public ActionResult <RemoveOrAddedOrderItemDTO> PutOrderItem([FromBody] OrderItemDTO dto, long orderItemId) { try { OrderItem oi = _orderItems.GetById(orderItemId); oi.Amount = dto.Amount; _orderItems.SaveChanges(); return(new RemoveOrAddedOrderItemDTO(oi.Order, oi)); } catch (ArgumentNullException) { return(NotFound(new CustomErrorDTO("Order item niet gevonden"))); } }
public ActionResult <RemoveOrAddedOrderItemDTO> AddOrderItemToOrder([FromBody] OrderItemDTO dto, long orderId) { try { Order o = _orders.GetById(orderId); OrderItem oi = new OrderItem(dto); var oiNew = o.AddOrderItem(oi); _orders.SaveChanges(); var oiFullInclude = _orderItems.GetById(oiNew.OrderItemId); return(new RemoveOrAddedOrderItemDTO(o, oiFullInclude)); } catch (NotSupportedException ex) { return(BadRequest(new CustomErrorDTO(ex.Message))); } catch (ArgumentNullException) { return(NotFound(new CustomErrorDTO("Order niet gevonden"))); } }