public async Task <IActionResult> ChangeOrderStatus([FromBody] ChangeOrderStatusDto orderStatusDto) { // Validates if the order id passed by the user exists is the db. var orderIdValid = await this.ordersService.ValidateOrderIdAsync(orderStatusDto.OrderId); if (!orderIdValid) { return(this.NotFound(ExceptionsHelper.OrderNotExist)); } // Validates if the currently logged user is the user who made the order. var userId = this.GetUserId(); var userAbleToModifyOrder = await this.ordersService.ValidateUserAsync(userId, orderStatusDto.OrderId); if (!userAbleToModifyOrder) { return(this.BadRequest(ExceptionsHelper.NotAbleToModify)); } // Validates if the new order status is valid. var orderStatusValid = this.ordersService.ValidateOrderStatus(orderStatusDto.Status); if (!orderStatusValid) { return(this.BadRequest(ExceptionsHelper.OrderStatusNotValid)); } // Changes order status. await this.ordersService.ChangeOrderStatusAsync(orderStatusDto.OrderId, orderStatusDto.Status); return(this.Ok()); }
public IActionResult Put(int id, [FromBody] ChangeOrderStatusDto dto, [FromServices] IChangeOrderStatus command) { dto.OrderId = id; executor.ExecuteCommand(command, dto); return(NoContent()); }