public async Task <ActionResult> UpdateAsync(int id, UpdateOrderRequestModel updateOrderRequestModel) { const string actionName = nameof(updateOrderRequestModel); Logger.LogDebug(LoggingMessage.ProcessingRequestWithModel, actionName, updateOrderRequestModel); var response = await _orderAppService.UpdateAsync(id, updateOrderRequestModel); Logger.LogInfomation(LoggingMessage.RequestResults, actionName); return(Ok(response)); }
public async Task <ResponseViewModel> UpdateOrder(long id, [FromBody] UpdateOrderRequestModel model) { var response = new ResponseViewModel { Result = false, }; var order = await _orderService.GetById(id); if (order == null) { response.Messages.Add("Không tìm thấy Đơn hàng"); } else { order.ContactName = model.ContactName; order.Phone = model.Phone; order.Email = model.Email; order.Address = model.Address; order.OrderStatusId = model.OrderStatusId; order.Note = model.Note; order.BranchId = model.BranchId; order.PaymentMethodId = model.PaymentMethodId; foreach (var orderDetailModel in model.OrderDetails) { var orderDetail = order.OrderDetails.Where(x => x.OrderDetailId == orderDetailModel.OrderDetailId).FirstOrDefault(); if (orderDetail != null) { orderDetail.ColorId = orderDetailModel.ColorId; orderDetail.Quantity = orderDetailModel.Quantity; // Ko update Price và ProductId => Đã chọn lucs mua rồi thì thôi // Còn color, Branch, Số lượng thì admin có thể edit dc... nên cho update } } response.Result = await _orderService.Update(order); response.Messages.Add(response.Result ? SuccessMessage : FailMessage); } return(response); }
public async Task <OrderReponseModel> UpdateAsync(int id, UpdateOrderRequestModel updateOrderRequestModel) { var actionName = nameof(UpdateAsync); updateOrderRequestModel = updateOrderRequestModel ?? throw new ArgumentNullException(nameof(updateOrderRequestModel)); if (id != updateOrderRequestModel.Id) { throw new InconsistentException(nameof(id)); } Logger.LogInfomation(LoggingMessage.ProcessingInService, actionName, seviceName, updateOrderRequestModel); var order = _Mapper.Map <Entities.Order>(updateOrderRequestModel); var response = await _orderRepository.UpdateAsync(order, true); Logger.LogInfomation(LoggingMessage.ActionSuccessfully, actionName, seviceName, updateOrderRequestModel); return(_Mapper.Map <OrderReponseModel>(response)); }