Skip to content

Commit

Permalink
Add datetime provider to logs service
Browse files Browse the repository at this point in the history
  • Loading branch information
cwetanow committed Mar 2, 2017
1 parent cba4eb5 commit a7cf723
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Logs.Services/LogsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Logs.Data.Contracts;
using Logs.Factories;
using Logs.Models;
using Logs.Providers.Contracts;
using Logs.Services.Contracts;

namespace Logs.Services
Expand All @@ -14,11 +15,13 @@ public class LogsService : ILogService
private readonly IUserService userService;
private readonly IUnitOfWork unitOfWork;
private readonly ITrainingLogFactory logFactory;
private readonly IDateTimeProvider provider;

public LogsService(IRepository<TrainingLog> logRepository,
IUnitOfWork unitOfWork,
ITrainingLogFactory logFactory,
IUserService userService)
IUserService userService,
IDateTimeProvider provider)
{
if (logRepository == null)
{
Expand All @@ -40,6 +43,12 @@ public class LogsService : ILogService
throw new ArgumentNullException("userService");
}

if (provider == null)
{
throw new ArgumentNullException("provider");
}

this.provider = provider;
this.logRepository = logRepository;
this.userService = userService;
this.logFactory = logFactory;
Expand All @@ -54,7 +63,9 @@ public TrainingLog GetTrainingLogById(int id)
public TrainingLog CreateTrainingLog(string name, string description, string userId)
{
var user = this.userService.GetUserById(userId);
var log = this.logFactory.CreateTrainingLog(name, description, DateTime.Now, user);

var currentTime = this.provider.GetCurrenTime();
var log = this.logFactory.CreateTrainingLog(name, description, currentTime, user);

this.logRepository.Add(log);
this.unitOfWork.Commit();
Expand Down

0 comments on commit a7cf723

Please sign in to comment.