public async Task <IActionResult> DeleteOrder([FromBody] OrderIdModel model) { Order order = await _context.Orders.Include(x => x.ItemOrders).ThenInclude(x => x.Item).FirstOrDefaultAsync(x => x.OrderId == Guid.Parse(model.OrderId)); if (order != null) { List <Item> items = order.ItemOrders.Select(x => x.Item).ToList(); foreach (var x in items) { x.isBought = true; _context.Items.Update(x); } _context.Orders.Remove(order); await _context.SaveChangesAsync(); } return(Ok()); }
public IActionResult GetByOrderById([FromBody] OrderIdModel orderIdModel) { try { var orderClass = new OrderClass(); var orderModel = orderClass.GetOrderById(orderIdModel.OrderId); var json = JsonSerializer.Serialize(orderModel, new JsonSerializerOptions() { IgnoreNullValues = true }); return(Ok(json)); } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }