Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="courierId"></param>
        /// <returns></returns>
        private async Task CreateCurrentOrNextAsync(int courierId)
        {
            var schedule = await _courierWorkShiftsScheduleService.GetCurrentOrNextActiveScheduleAsync(courierId);

            var item = new CourierShiftHistory
            {
                CourierShiftId   = schedule.Id,
                IsStarted        = false,
                StartTime        = null,
                IsEnded          = false,
                EndTime          = null,
                IsPaused         = false,
                PauseReasonId    = null,
                PauseTime        = null,
                PauseDescription = null,
                CreatedAt        = DateTime.Now,
                UpdatedAt        = DateTime.Now
            };

            _dbContext.CourierShiftHistories.Add(item);

            await _dbContext.SaveChangesAsync();
        }
Example #2
0
        private async Task <CourierShiftHistoryDto> MapCourierShiftHistoryToDTO(int courierId, CourierShiftHistory courierShiftHistory)
        {
            var orderCountDto = new OrderCountDto
            {
                Active = _dbContext.Orders
                         .Count(x =>
                                x.OrderStatusCode.IsFinal == false &&
                                x.CourierShiftHistoryId == courierShiftHistory.Id),

                Delivered = _dbContext.Orders
                            .Count(x =>
                                   x.OrderStatusCodeId == (int)OrderStatusCode.Completed &&
                                   x.CourierShiftHistoryId == courierShiftHistory.Id),

                Rejected = _dbContext.IncomingOrderHistories
                           .Count(x =>
                                  x.StatusId == (int)IncomingOrderStatuses.Rejected &&
                                  x.CourierShiftHistoryId == courierShiftHistory.Id),
                Total = 0
            };

            orderCountDto.Total = orderCountDto.Rejected + orderCountDto.Active + orderCountDto.Delivered;

            // Текущая смена курьера.

            // Получает время начала.
            var shiftStartTime = courierShiftHistory.CourierShift.Shift.StartTime;

            // Получает время завершения.
            var shiftEndTime = courierShiftHistory.CourierShift.Shift.EndTime;

            // Создаст дату и время начала.
            var startDateTime = CalcStartDateTime(shiftStartTime, shiftEndTime);

            // Создаст дату и время завершения.
            var endDateTime = CalcEndDateTime(shiftStartTime, shiftEndTime, startDateTime);

            // Создаст и заполнит запись для возвращения.
            var item = new CourierShiftHistoryDto
            {
                IsStarted  = courierShiftHistory.IsStarted,
                StartedAt  = courierShiftHistory.StartTime?.Format(),
                StartAt    = startDateTime.Format(),
                CloseAt    = endDateTime.Format(),
                PausedAt   = courierShiftHistory.PauseTime?.Format(),
                OrderCount = orderCountDto,
                Orders     = await GetShiftActiveOrderList(courierId, courierShiftHistory.Id)
            };

            return(item);
        }