Beispiel #1
0
        private Guid CreateClientEmployeePlanActionStructure(Guid employeeId, Guid clientId, bool isPlanValid)
        {
            var from = isPlanValid ? DateTime.Today.AddDays(-10) : DateTime.Today.AddDays(5);

            var plan = new IndividualPlan();

            plan.ClientId       = clientId;
            plan.ValidFromDate  = from;
            plan.ValidUntilDate = DateTime.Today.AddDays(10);
            DataContext.IndividualPlans.Add(plan);

            var agreedActionTomorrow = new AgreedClientAction();

            agreedActionTomorrow.IndividualPlanId = plan.Id;
            agreedActionTomorrow.EmployeeId       = employeeId;
            agreedActionTomorrow.Day = DateTime.Today.DayOfWeek;
            agreedActionTomorrow.PlannedStartTime = DateTime.Now.AddHours(1).TimeOfDay;

            var agreedActionYesterday = new AgreedClientAction();

            agreedActionYesterday.IndividualPlanId = plan.Id;
            agreedActionYesterday.EmployeeId       = employeeId;
            agreedActionYesterday.Day = DateTime.Today.AddDays(-1).DayOfWeek;
            agreedActionYesterday.PlannedStartTime = DateTime.Now.AddHours(1).TimeOfDay;

            DataContext.AgreedClientActions.AddRange(new[] { agreedActionTomorrow, agreedActionYesterday });

            return(agreedActionTomorrow.Id);
        }
        private AgreedClientAction MapDtoToAction(AgreedActionDTO dto)
        {
            var action = new AgreedClientAction();

            if (dto.Id.HasValue)
            {
                action.Id = dto.Id.Value;
            }

            action.ActionId         = dto.Action.Id.Value;
            action.PlannedStartTime = dto.PlannedStartTime.TimeOfDay;

            if (dto.EstimatedDurationMinutes.HasValue)
            {
                action.EstimatedDurationMinutes = dto.EstimatedDurationMinutes.Value;
            }
            else
            {
                var duration = (int)(dto.PlannedEndTime - dto.PlannedStartTime).TotalMinutes;
                action.EstimatedDurationMinutes = duration;
            }

            action.ClientActionSpecificDescription = dto.ClientActionSpecificDescription;
            action.Day              = dto.Day;
            action.EmployeeId       = dto.EmployeeId;
            action.IndividualPlanId = dto.IndividualPlanId;

            return(action);
        }
Beispiel #3
0
        // 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);
        }
        public void UpdateAgreedClientAction(AgreedClientAction action)
        {
            var queriedAction = DataContext.AgreedClientActions.Find(action.Id);

            queriedAction.PlannedStartTime         = action.PlannedStartTime;
            queriedAction.EstimatedDurationMinutes = action.EstimatedDurationMinutes;
            queriedAction.ActionId   = action.ActionId;
            queriedAction.EmployeeId = action.EmployeeId;
            queriedAction.ClientActionSpecificDescription = action.ClientActionSpecificDescription;
            queriedAction.Day = action.Day;

            DataContext.SaveChanges();
        }
Beispiel #5
0
        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);
        }
        // mappers
        private AgreedActionDTO MapActionToDto(AgreedClientAction action)
        {
            var dto = new AgreedActionDTO();

            dto.Id = action.Id;
            dto.ClientActionSpecificDescription = action.ClientActionSpecificDescription;
            dto.EstimatedDurationMinutes        = action.EstimatedDurationMinutes;
            dto.PlannedStartTime = DateTime.Today.Add(action.PlannedStartTime);
            dto.PlannedEndTime   = DateTime.Today.Add(action.PlannedStartTime).AddMinutes(action.EstimatedDurationMinutes);
            dto.Action           = MapActionToDto(action.Action);
            dto.IndividualPlanId = action.IndividualPlanId;
            dto.EmployeeId       = action.EmployeeId;
            dto.Day = action.Day;

            return(dto);
        }
Beispiel #8
0
        private void CreateIndividualPlansWithAgreedClientActions()
        {
            var individualPlans       = new List <IndividualPlan>();
            var agreedClientActions   = new List <AgreedClientAction>();
            var firstDayOfCurrentYear = new DateTime(DateTime.Today.Year, 1, 1);
            var lastDayOfCurrentYear  = new DateTime(DateTime.Today.Year, 12, 31);

            var individualPlanClient = new IndividualPlan();

            individualPlanClient.ClientId       = _clientIds[0];
            individualPlanClient.ValidFromDate  = firstDayOfCurrentYear;
            individualPlanClient.ValidUntilDate = lastDayOfCurrentYear;
            individualPlans.Add(individualPlanClient);

            var client0Bathing = new AgreedClientAction();

            client0Bathing.ActionId = _actionIds[0];
            client0Bathing.EstimatedDurationMinutes = 60;
            client0Bathing.IndividualPlanId         = individualPlanClient.Id;
            client0Bathing.Day = DayOfWeek.Monday;
            client0Bathing.PlannedStartTime = TimeSpan.FromHours(8);
            agreedClientActions.Add(client0Bathing);

            var client0Bathing1 = new AgreedClientAction();

            client0Bathing1.ActionId = _actionIds[1];
            client0Bathing1.EstimatedDurationMinutes = 60;
            client0Bathing1.IndividualPlanId         = individualPlanClient.Id;
            client0Bathing1.Day = DayOfWeek.Thursday;
            client0Bathing1.PlannedStartTime = TimeSpan.FromHours(8);
            agreedClientActions.Add(client0Bathing1);

            var client0Cleaning = new AgreedClientAction();

            client0Cleaning.ActionId = _actionIds[1];
            client0Cleaning.EstimatedDurationMinutes = 30;
            client0Cleaning.IndividualPlanId         = individualPlanClient.Id;
            client0Cleaning.Day = DayOfWeek.Monday;
            client0Cleaning.PlannedStartTime = TimeSpan.FromHours(9);
            agreedClientActions.Add(client0Cleaning);

            var client0Cleaning1 = new AgreedClientAction();

            client0Cleaning1.ActionId = _actionIds[1];
            client0Cleaning1.EstimatedDurationMinutes = 30;
            client0Cleaning1.IndividualPlanId         = individualPlanClient.Id;
            client0Cleaning1.Day = DayOfWeek.Thursday;
            client0Cleaning1.PlannedStartTime = TimeSpan.FromHours(9);
            agreedClientActions.Add(client0Cleaning1);

            var client0GroceryShopping = new AgreedClientAction();

            client0GroceryShopping.ActionId = _actionIds[2];
            client0GroceryShopping.EstimatedDurationMinutes = 60;
            client0GroceryShopping.IndividualPlanId         = individualPlanClient.Id;
            client0GroceryShopping.Day = DayOfWeek.Wednesday;
            client0GroceryShopping.PlannedStartTime = TimeSpan.FromHours(8);
            agreedClientActions.Add(client0GroceryShopping);

            var individualPlanClient1 = new IndividualPlan();

            individualPlanClient1.ClientId       = _clientIds[1];
            individualPlanClient1.ValidFromDate  = firstDayOfCurrentYear;
            individualPlanClient1.ValidUntilDate = lastDayOfCurrentYear;
            individualPlans.Add(individualPlanClient1);

            var client1GroceryShopping = new AgreedClientAction();

            client1GroceryShopping.ActionId = _actionIds[2];
            client1GroceryShopping.EstimatedDurationMinutes = 60;
            client1GroceryShopping.IndividualPlanId         = individualPlanClient1.Id;
            client1GroceryShopping.Day = DayOfWeek.Tuesday;
            client1GroceryShopping.PlannedStartTime = TimeSpan.FromHours(8);
            agreedClientActions.Add(client1GroceryShopping);

            var client1Transportation = new AgreedClientAction();

            client1Transportation.ActionId = _actionIds[4];
            client1Transportation.EstimatedDurationMinutes = 120;
            client1Transportation.IndividualPlanId         = individualPlanClient1.Id;
            client1Transportation.Day = DayOfWeek.Tuesday;
            client1Transportation.PlannedStartTime = TimeSpan.FromHours(9);
            agreedClientActions.Add(client1Transportation);

            var client1Errands = new AgreedClientAction();

            client1Errands.ActionId = _actionIds[5];
            client1Errands.EstimatedDurationMinutes = 60;
            client1Errands.IndividualPlanId         = individualPlanClient1.Id;
            client1Errands.Day = DayOfWeek.Tuesday;
            client1Errands.PlannedStartTime = TimeSpan.FromHours(1);
            agreedClientActions.Add(client1Errands);

            var individualPlanClient2 = new IndividualPlan();

            individualPlanClient2.ClientId       = _clientIds[2];
            individualPlanClient2.ValidFromDate  = firstDayOfCurrentYear;
            individualPlanClient2.ValidUntilDate = lastDayOfCurrentYear;
            individualPlans.Add(individualPlanClient2);

            var client2Cleaning = new AgreedClientAction();

            client2Cleaning.ActionId = _actionIds[1];
            client2Cleaning.EstimatedDurationMinutes = 30;
            client2Cleaning.IndividualPlanId         = individualPlanClient2.Id;
            client2Cleaning.Day = DayOfWeek.Monday;
            client2Cleaning.PlannedStartTime = TimeSpan.FromHours(10);
            agreedClientActions.Add(client2Cleaning);

            var client2Cleaning2 = new AgreedClientAction();

            client2Cleaning2.ActionId = _actionIds[1];
            client2Cleaning2.EstimatedDurationMinutes = 30;
            client2Cleaning2.IndividualPlanId         = individualPlanClient2.Id;
            client2Cleaning2.Day = DayOfWeek.Wednesday;
            client2Cleaning2.PlannedStartTime = TimeSpan.FromHours(9).Add(TimeSpan.FromMinutes(30));
            agreedClientActions.Add(client2Cleaning2);

            var individualPlanClient3 = new IndividualPlan();

            individualPlanClient3.ClientId       = _clientIds[3];
            individualPlanClient3.ValidFromDate  = firstDayOfCurrentYear;
            individualPlanClient3.ValidUntilDate = lastDayOfCurrentYear;
            individualPlans.Add(individualPlanClient3);

            var client3Errands = new AgreedClientAction();

            client3Errands.ActionId = _actionIds[3];
            client3Errands.EstimatedDurationMinutes = 120;
            client3Errands.IndividualPlanId         = individualPlanClient3.Id;
            client3Errands.Day = DayOfWeek.Friday;
            client3Errands.PlannedStartTime = TimeSpan.FromHours(8);
            agreedClientActions.Add(client2Cleaning);

            var client3DrugShopping = new AgreedClientAction();

            client3DrugShopping.ActionId = _actionIds[3];
            client3DrugShopping.EstimatedDurationMinutes = 60;
            client3DrugShopping.IndividualPlanId         = individualPlanClient3.Id;
            client3DrugShopping.Day = DayOfWeek.Friday;
            client3DrugShopping.PlannedStartTime = TimeSpan.FromHours(10);
            agreedClientActions.Add(client3DrugShopping);

            var individualPlanClient5 = new IndividualPlan();

            individualPlanClient5.ClientId       = _clientIds[5];
            individualPlanClient5.ValidFromDate  = firstDayOfCurrentYear;
            individualPlanClient5.ValidUntilDate = lastDayOfCurrentYear;
            individualPlans.Add(individualPlanClient5);

            var client5Bathing = new AgreedClientAction();

            client5Bathing.ActionId = _actionIds[0];
            client5Bathing.EstimatedDurationMinutes = 60;
            client5Bathing.IndividualPlanId         = individualPlanClient5.Id;
            client5Bathing.Day = DayOfWeek.Monday;
            client5Bathing.PlannedStartTime = TimeSpan.FromHours(11);
            agreedClientActions.Add(client5Bathing);

            foreach (var agreedClientAction in agreedClientActions)
            {
                agreedClientAction.EmployeeId = _dcEmployeeId;
            }

            _dataContext.IndividualPlans.AddRange(individualPlans);
            _dataContext.AgreedClientActions.AddRange(agreedClientActions);
            _dataContext.SaveChanges();
        }
 public void CreateAgreedClientAction(AgreedClientAction action)
 {
     DataContext.AgreedClientActions.Add(action);
     DataContext.SaveChanges();
 }