public async Task ModifyOrderSessionStatus(int id, StatusModModel model) { if (!Enum.IsDefined(typeof(OrderSessionStatus), model.Status)) { throw new RestaurantNotFoundException("Nem létező státusz!"); } var orderSession = await DbContext.OrderSessions.Include(os => os.Orders).Where(os => os.Id == id).SingleOrDefaultAsync(); if (orderSession == null) { throw new RestaurantNotFoundException("Nem létező rendelési folyamat!"); } await StatusService.CheckRightsForStatus(orderSession.Status); orderSession.Status = StatusService.StringToStatus <OrderSessionStatus>(model.Status); if (orderSession.Status == OrderSessionStatus.Cancelled || orderSession.Status == OrderSessionStatus.Paid) { orderSession.ClosedAt = DateTime.Now; if (orderSession.Status == OrderSessionStatus.Cancelled) { orderSession.Orders.ForEach(order => { order.Status = OrderStatus.Cancelled; order.ClosedAt = DateTime.Now; }); } } await DbContext.SaveChangesAsync(); }
public async Task ModifyOrder(int id, StatusModModel model) { if (!Enum.IsDefined(typeof(OrderStatus), model.Status)) { throw new RestaurantNotFoundException("Nem létező státusz!"); } var order = await DbContext.Orders.Include(o => o.OrderSession).Where(o => o.Id == id).SingleOrDefaultAsync(); if (order == null) { throw new RestaurantNotFoundException("Nem létező rendelés!"); } var newStatus = StatusService.StringToStatus <OrderStatus>(model.Status); await StatusService.CheckRightsForStatusModification(order.OrderSession.Status, order.Status, newStatus); order.Status = newStatus; if (order.Status == OrderStatus.Cancelled || order.Status == OrderStatus.Served) { order.ClosedAt = DateTime.Now; } await DbContext.SaveChangesAsync(); }
public async Task ModifyOrder(int id, StatusModModel status) => await OrderService.ModifyOrder(id, status);