public void GetNextNotStartedRegisteredActionsToday_AllTodayAndNotStarted() { var employee = new Employee(); DataContext.Employees.Add(employee); var client1 = new Client(); var client2 = new Client(); DataContext.Clients.AddRange(new[] { client2, client1 }); var action1 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now.AddHours(1), ClientId = client1.Id, EmployeeId = employee.Id }; var action2 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now.AddHours(2), ClientId = client1.Id, EmployeeId = employee.Id }; var action3 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now, ClientId = client2.Id, EmployeeId = employee.Id }; DataContext.RegisteredClientActions.AddRange(new[] { action1, action2, action3 }); DataContext.SaveChanges(); var result = _testedService.GetNextNotStartedRegisteredActionsToday(employee.Id); Assert.IsNotNull(result.FirstOrDefault(r => r.Id == action1.Id)); Assert.IsNotNull(result.FirstOrDefault(r => r.Id == action3.Id)); Assert.IsNull(result.FirstOrDefault(r => r.Id == action2.Id)); }
public void GetNextNotStartedRegisteredActionsToday_WithOtherEmployees() { var employee1 = new Employee(); var employee2 = new Employee(); DataContext.Employees.AddRange(new[] { employee1, employee2 }); var client = new Client(); DataContext.Clients.AddRange(new[] { client }); var action1 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now, ClientId = client.Id, EmployeeId = employee1.Id }; var action2 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now, ClientId = client.Id, EmployeeId = employee2.Id }; var action3 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now, ClientId = client.Id, EmployeeId = employee2.Id }; DataContext.RegisteredClientActions.AddRange(new[] { action1, action2, action3 }); DataContext.SaveChanges(); var result = _testedService.GetNextNotStartedRegisteredActionsToday(employee1.Id); Assert.AreEqual(1, result.Count); Assert.IsNotNull(result.FirstOrDefault(r => r.Id == action1.Id)); }
public void GetAllNextRegisteredActions_SingleClient_RegisteredActionsExists_ValidPlan() { var employee = new Employee(); DataContext.Employees.Add(employee); var client = new Client(); DataContext.Clients.Add(client); CreateClientEmployeePlanActionStructure(employee.Id, client.Id, true); var action1 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now.AddHours(-1), ClientId = client.Id, EmployeeId = employee.Id }; var action2 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now.AddHours(1), ClientId = client.Id, EmployeeId = employee.Id }; var action3 = new RegisteredClientAction { PlannedStartDateTime = DateTime.Now.AddHours(2), ClientId = client.Id, EmployeeId = employee.Id }; DataContext.RegisteredClientActions.AddRange(new[] { action1, action2, action3 }); DataContext.SaveChanges(); var result = _testedService.GetAllNextRegisteredActions(employee.Id); Assert.IsNull(result.FirstOrDefault(r => r.Id == action1.Id)); Assert.IsNull(result.FirstOrDefault(r => r.Id == action3.Id)); Assert.IsNotNull(result.FirstOrDefault(r => r.Id == action2.Id)); }
public void CreateRegisteredAction(RegisteredClientAction action) { // to simplify logic adhoc actions always have 1 hour duration action.EstimatedDurationMinutes = 60; DataContext.RegisteredClientActions.Add(action); DataContext.SaveChanges(); }
private RegisteredActionBasicDTO MapRegisteredActionToBasicDto(RegisteredClientAction action) { var dto = new RegisteredActionBasicDTO(); dto.Id = action.Id; dto.Name = action.AgreedClientActionId.HasValue ? action.AgreedClientAction.Action.Name : action.Action.Name; dto.Date = action.PlannedStartDateTime; dto.Time = action.PlannedStartDateTime; return(dto); }
// create registered client actions from agreed client actions - all past and max 30 days into future private List <RegisteredClientAction> GenerateRegisteredClientActionsForAgreedClientAction( AgreedClientAction agreedClientAction) { var registeredClientActions = new List <RegisteredClientAction>(); var startDate = agreedClientAction.IndividualPlan.ValidFromDate; if (startDate > DateTime.Today.AddDays(10)) { return(registeredClientActions); } var endDate = agreedClientAction.IndividualPlan.ValidUntilDate > DateTime.Today.AddDays(30) ? DateTime.Today.AddDays(10) : agreedClientAction.IndividualPlan.ValidUntilDate; var random = new Random(); while (startDate < endDate) { if (startDate.DayOfWeek != agreedClientAction.Day) { startDate = startDate.AddDays(1); continue; } var clientAction = new RegisteredClientAction(); clientAction.EmployeeId = agreedClientAction.EmployeeId; clientAction.ClientId = agreedClientAction.IndividualPlan.ClientId; clientAction.AgreedClientAction = agreedClientAction; clientAction.PlannedStartDateTime = startDate.Add(agreedClientAction.PlannedStartTime); clientAction.IsCanceled = random.Next(1, 10) == 1; clientAction.IsCompleted = clientAction.IsCanceled == false && startDate < DateTime.Today; clientAction.ActionId = agreedClientAction.ActionId; if (clientAction.IsCanceled) { clientAction.Comment = "Reason for canceling action."; } if (clientAction.IsCompleted) { clientAction.ActionStartedDateTime = startDate.Add(agreedClientAction.PlannedStartTime); clientAction.ActionFinishedDateTime = clientAction.ActionStartedDateTime ?.AddMinutes(agreedClientAction.EstimatedDurationMinutes); } registeredClientActions.Add(clientAction); startDate = startDate.AddDays(1); } return(registeredClientActions); }
private RegisteredClientAction CreateRegisteredActionFromAgreedAction(AgreedClientAction agreedClientAction) { var registeredAction = new RegisteredClientAction(); registeredAction.IsCanceled = false; registeredAction.ClientId = agreedClientAction.IndividualPlan.ClientId; registeredAction.PlannedStartDateTime = GeneralHelper.GetNextDateFromDay(agreedClientAction.Day).Date .Add(agreedClientAction.PlannedStartTime); registeredAction.EmployeeId = agreedClientAction.EmployeeId; registeredAction.AgreedClientActionId = agreedClientAction.Id; return(registeredAction); }
private RegisteredClientAction CreateRegisteredActionFromAgreedAction(AgreedClientAction agreedClientAction, DateTime date) { var registeredAction = new RegisteredClientAction(); registeredAction.ActionId = agreedClientAction.ActionId; registeredAction.IsCanceled = false; registeredAction.ClientId = agreedClientAction.IndividualPlan.ClientId; registeredAction.PlannedStartDateTime = date.Add(agreedClientAction.PlannedStartTime); registeredAction.EmployeeId = agreedClientAction.EmployeeId; registeredAction.AgreedClientActionId = agreedClientAction.Id; registeredAction.IsCompleted = false; return(registeredAction); }
public RegisteredClientAction UpdateRegisteredActionPersistent(RegisteredClientAction action) { var queriedAction = DataContext.RegisteredClientActions.Find(action.Id); queriedAction.Comment = action.Comment; queriedAction.ActionStartedDateTime = action.ActionStartedDateTime; queriedAction.PlannedStartDateTime = action.PlannedStartDateTime; queriedAction.EmployeeId = action.EmployeeId; queriedAction.ActionId = action.ActionId; if (action.ActionFinishedDateTime.HasValue) { queriedAction.ActionFinishedDateTime = action.ActionFinishedDateTime; queriedAction.IsCompleted = true; } if (action.Photo != null) { if (queriedAction.Photo != null) { queriedAction.Photo.MimeType = action.Photo.MimeType; queriedAction.Photo.BinaryData = action.Photo.BinaryData; } else { queriedAction.Photo = action.Photo; DataContext.Pictures.Add(action.Photo); } } if (queriedAction.AgreedClientActionId.HasValue == false) { queriedAction.EstimatedDurationMinutes = action.EstimatedDurationMinutes; } queriedAction.IsCanceled = action.IsCanceled; DataContext.SaveChanges(); return(queriedAction); }