public async Task <ActionResult> OrderUpdate(int orderId, OrderPutDTO orderPutDTO) { if (orderId != orderPutDTO.OrderId) { ModelState.AddModelError("OrderId", "The Parameter OrderId and the OrderId from the body do not match."); return(ValidationProblem(ModelState)); } // Get a copy of the Order entity from the respository var updateOrder = await _orderRespository.GetById(orderId); if (updateOrder is null) { return(NotFound()); } // Map orderPutDTO to the repositories Order entity updateOrder = _mapper.Map(orderPutDTO, updateOrder); // Apply audit changes to Order entity updateOrder = Audit <Order> .PerformAudit(updateOrder); // Update Order in the respository var isUpdated = await _orderRespository.Update(updateOrder); if (!isUpdated) { return(NotFound()); } return(Ok()); }
public void Update(Order order) { _orderRespository.Update(order); }
/// <summary> /// Attempts to edit an order within the current IOrderRepository data /// </summary> /// <param name="inputtedDate"></param> /// <param name="orderNumber"></param> /// <param name="newCustomerName"></param> /// <param name="newState"></param> /// <param name="newProductType"></param> /// <param name="newArea"></param> /// <returns></returns> public EditOrderResponse EditOrder(string inputtedDate, int orderNumber, string newCustomerName, string newState, string newProductType, decimal newArea) { EditOrderResponse response = new EditOrderResponse(); DateTime date = ParseDate(response, inputtedDate); if (response.ResponseType.Equals(ResponseType.Invalid)) { return(response); } Order order = OrderRepository.GetByValue(orderNumber); if (order == null) { response.ResponseType = ResponseType.Fail; response.Message = "Couldn't find order with that number."; return(response); } if (!ValidNameInput(newCustomerName)) { response.ResponseType = ResponseType.Fail; response.Message = "Invalid customer name. Check special characters."; return(response); } TaxData tax = TaxRepository.GetByValue(newState); Product product = ProductRepository.GetByValue(newProductType); if (tax == null) { response.ResponseType = ResponseType.Fail; response.Message = "Invalid state."; return(response); } if (product == null) { response.ResponseType = ResponseType.Fail; response.Message = "Invalid product type."; return(response); } if (newArea < 0) { response.ResponseType = ResponseType.Fail; response.Message = "Area must be a positive decimal."; return(response); } if (newArea < 100) { response.ResponseType = ResponseType.Fail; response.Message = "Area must be at least 100 sq ft."; return(response); } Order updated = Order.CreateOrder(newCustomerName, newArea, tax, product, orderNumber); OrderRepository.Update(updated); response.NewOrder = updated; response.Date = date; response.ResponseType = ResponseType.Success; return(response); }