示例#1
0
        public async Task <IActionResult> UpdateAsync([FromBody] InWorkOrderDTO workOrderDTO)
        {
            var userId = HttpContext.User.GetUserId();

            var workOrder = await _repositoryManager.WorkOrderRepository
                            .GetAsync(workOrderDTO.Id);

            if (workOrder == null)
            {
                return(NotFound());
            }

            if (!HttpContext.User.IsAdministrator() &&
                !await _repositoryManager.CarRepository
                .IsActiveCarAssignmentAsync(workOrderDTO.CarId, userId.Value) ||
                workOrder.Locked)
            {
                return(Forbid());
            }

            workOrder.Update(workOrderDTO);

            _repositoryManager.WorkOrderRepository.Update(workOrder);

            await _repositoryManager.SaveAsync();

            return(Ok(WorkOrderMapper.Map(workOrder)));
        }
示例#2
0
 public static void Update(this WorkOrder workOrder, InWorkOrderDTO workOrderDTO)
 {
     workOrder.CarId     = workOrderDTO.CarId;
     workOrder.CreatedAt = DateTimeOffset
                           .FromUnixTimeSeconds(workOrderDTO.CreatedAt).UtcDateTime;
     workOrder.Comment = workOrderDTO.Comment;
 }
示例#3
0
 public static WorkOrder Map(int userId, InWorkOrderDTO workOrderDTO)
 {
     return(new WorkOrder
     {
         Id = workOrderDTO.Id,
         UserId = userId,
         CarId = workOrderDTO.CarId,
         CreatedAt = DateTimeOffset
                     .FromUnixTimeSeconds(workOrderDTO.CreatedAt).UtcDateTime,
         Comment = workOrderDTO.Comment
     });
 }
示例#4
0
        public async Task <IActionResult> CreateAsync([FromBody] InWorkOrderDTO workOrderDTO)
        {
            var userId = HttpContext.User.GetUserId();

            if (!HttpContext.User.IsAdministrator() &&
                !await _repositoryManager.CarRepository
                .IsActiveCarAssignmentAsync(workOrderDTO.CarId, userId.Value))
            {
                return(Forbid());
            }

            if (await _repositoryManager.WorkOrderRepository.ExistAsync(workOrderDTO.Id))
            {
                return(BadRequest());
            }

            var workOrder = WorkOrderMapper.Map(userId.Value, workOrderDTO);

            workOrder = _repositoryManager.WorkOrderRepository.Create(workOrder);

            await _repositoryManager.SaveAsync();

            return(Ok(WorkOrderMapper.Map(workOrder)));
        }