Exemple #1
0
        public async Task <CreateTaskResponse> Handle(CreateTaskRequest request, CancellationToken cancellationToken)
        {
            var currentUser = await _userService.GetCurrentUser();

            var planStart = request.PlanStartUtc.UnixTimeStampToDateTime();
            var planEnd   = request.Type == TaskType.Unexpected
                ? planStart.AddHours(1)
                : request.PlanEndUtc.UnixTimeStampToDateTime();
            var task = new TaskEntity()
            {
                Created    = DateTime.Now,
                LoaderId   = request.LoaderId,
                Status     = TaskWorkStatus.New,
                Comment    = request.Comment,
                Type       = request.Type,
                PlanStart  = planStart,
                PlanEnd    = planEnd,
                Direction  = request.Direction,
                CreateUser = currentUser
            };

            // Баки и логисты создаются сразу в статусе InProcess
            if (request.Direction == TaskDirection.Baki || request.Direction == TaskDirection.Logistic)
            {
                var taskInWork = await _loaderService.TaskInWork(request.LoaderId.Value);

                if (taskInWork != null)
                {
                    return(new CreateTaskResponse()
                    {
                        Result = TasksRequestHandleResult.LoaderIsBusy,
                        Message = $"У погрузчика есть незавершенное задание: {taskInWork.FactStart.Value.ToString("dd.mm.yyyy HH:mm")}"
                    });
                }

                task.Status    = TaskWorkStatus.InProcess;
                task.FactStart = DateTime.Now;
                task.PlanStart = 0L.UnixTimeStampToDateTime();
                task.PlanEnd   = 0L.UnixTimeStampToDateTime();
            }

            await _taskService.InsertTaskIntoPlanTimeline(task, false);

            _taskRepository.Add(task);
            await _taskRepository.SaveChangesAsync(cancellationToken);

            await _taskHubContextWrapper.TasksChanged(task.GetDateTimeForUpdateSignal());

            return(new CreateTaskResponse());
        }
Exemple #2
0
        public async Task <CompleteTaskInProcessResponse> Handle(CompleteTaskInProcessRequest request, CancellationToken cancellationToken)
        {
            var taskInProcess = await _loaderService.TaskInWork(request.LoaderId);

            if (taskInProcess != null)
            {
                taskInProcess.Status  = TaskWorkStatus.Completed;
                taskInProcess.FactEnd = DateTime.Now;
                await _loaderRepository.SaveChangesAsync(cancellationToken);

                await _taskHubContextWrapper.TasksChanged(taskInProcess.GetDateTimeForUpdateSignal());
            }

            return(new CompleteTaskInProcessResponse());
        }