Beispiel #1
0
        public async Task <CustomerTaskDto> ReopenTask(Guid taskId)
        {
            CustomerTaskPoco task = await Context.CustomerTasks
                                    .Where(o => o.Id == taskId)
                                    .FirstOrDefaultAsync();

            task.EndDate = null;
            await Context.SaveChangesAsync();

            return(task.MapTo <CustomerTaskDto>());
        }
Beispiel #2
0
        public async Task <CustomerTaskDto> RescheduleTask(Guid taskId, DateTime newDate)
        {
            if (newDate < DateTime.Now)
            {
                throw new Exception("Não é possível reprogramar a tarefa para uma data passada.");
            }

            CustomerTaskPoco task = await Context.CustomerTasks
                                    .Where(o => o.Id == taskId)
                                    .FirstOrDefaultAsync();

            task.EstimatedEndDate = newDate;
            await Context.SaveChangesAsync();

            return(task.MapTo <CustomerTaskDto>());
        }
Beispiel #3
0
        public async Task <CustomerProcessDto> StartCustomerProcess(ModelProcessDto modelProcessDto, Guid customerId, Guid consultantId, Guid customerUserId, DateTime startDate)
        {
            CustomerProcessPoco customerProcess = new CustomerProcessPoco();

            List <ModelStepPoco> lstModelSteps = Context.ModelSteps
                                                 .Include(o => o.ModelTasks)
                                                 .Where(o => o.ProcessId == modelProcessDto.Id)
                                                 .ToList();

            List <CustomerStepPoco> lstCustomerSteps = new List <CustomerStepPoco>();

            DateTime?processEstimatedEndDate = null;

            foreach (ModelStepPoco modelStep in lstModelSteps)
            {
                CustomerStepPoco customerStep = new CustomerStepPoco();

                customerStep.Id = Guid.NewGuid();

                DateTime?firstDate = null;
                DateTime?lastDate  = null;

                List <CustomerTaskPoco> lstTasks = new List <CustomerTaskPoco>();

                foreach (ModelTaskPoco modelTask in modelStep.ModelTasks)
                {
                    CustomerTaskPoco customerTask = new CustomerTaskPoco();

                    customerTask.Id             = Guid.NewGuid();
                    customerTask.CustomerStepId = customerStep.Id;
                    customerTask.ModelTaskId    = modelTask.Id;

                    customerTask.Description  = modelTask.Description;
                    customerTask.Instructions = modelTask.Instructions;
                    customerTask.Duration     = modelTask.Duration;
                    customerTask.CreationDate = DateTime.Now;

                    customerTask.StartDate = Utils.AddBusinessDays(startDate, modelTask.StartAfterDays);
                    firstDate = (firstDate == null || customerTask.StartDate < firstDate ? customerTask.StartDate : firstDate);
                    customerTask.EstimatedEndDate = Utils.AddBusinessDays(customerTask.StartDate, modelTask.DueDays);
                    lastDate = (lastDate == null || customerTask.EstimatedEndDate > lastDate ? customerTask.EstimatedEndDate : lastDate);
                    processEstimatedEndDate = (processEstimatedEndDate == null || lastDate > processEstimatedEndDate ? lastDate : processEstimatedEndDate);

                    customerTask.EndDate = null;

                    customerTask.CustomerId     = customerId;
                    customerTask.CustomerUserId = customerUserId;
                    customerTask.ConsultantId   = consultantId;

                    if (modelTask.TaskTypeId == Const.TaskTypes.Customer)
                    {
                        customerTask.TaskTypeId = Const.TaskTypes.Customer;
                        customerTask.OwnerId    = customerUserId;
                    }
                    else
                    {
                        customerTask.TaskTypeId = Const.TaskTypes.Consultant;
                        customerTask.OwnerId    = consultantId;
                    }

                    lstTasks.Add(customerTask);
                }

                customerStep.CustomerTasks    = lstTasks;
                customerStep.StartDate        = (firstDate.HasValue ? firstDate.Value : throw new Exception("Data inicial da etapa não definida."));
                customerStep.EstimatedEndDate = (lastDate.HasValue ? lastDate.Value : throw new Exception("Data final da etapa não definida"));
                customerStep.EndDate          = null;
                customerStep.Description      = modelStep.Description;
                customerStep.ModelStepId      = modelStep.Id;

                lstCustomerSteps.Add(customerStep);
            }

            customerProcess.Id               = new Guid();
            customerProcess.Description      = modelProcessDto.Description;
            customerProcess.ModelProcessId   = modelProcessDto.Id;
            customerProcess.CustomerId       = customerId;
            customerProcess.StartDate        = startDate;
            customerProcess.CustomerSteps    = lstCustomerSteps;
            customerProcess.EstimatedEndDate = (processEstimatedEndDate.HasValue ? processEstimatedEndDate.Value : throw new Exception("Data final do processo não definida"));
            customerProcess.EndDate          = null;

            Context.CustomerProcesses.Add(customerProcess);
            await Context.SaveChangesAsync();

            CustomerProcessDto customerProcessDto = customerProcess.MapTo <CustomerProcessDto>();

            foreach (CustomerStepDto step in customerProcessDto.CustomerSteps)
            {
                step.CustomerProcess = null;

                foreach (CustomerTaskDto task in step.CustomerTasks)
                {
                    task.CustomerStep = null;
                }
            }

            return(customerProcessDto);
        }