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))); }
public static void Update(this WorkOrder workOrder, InWorkOrderDTO workOrderDTO) { workOrder.CarId = workOrderDTO.CarId; workOrder.CreatedAt = DateTimeOffset .FromUnixTimeSeconds(workOrderDTO.CreatedAt).UtcDateTime; workOrder.Comment = workOrderDTO.Comment; }
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 }); }
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))); }