public IActionResult GetItems(long order_id) { Cloud.Result <OrderItem> result = new Cloud.Result <OrderItem>(); try { var items = _cafeContext.OrderItems.Where( orderItem => orderItem.Order.Id == order_id); if (items == null) { result.SetFail("Items not found"); } else { result.SetSuccess("order_items", items.ToList()); } } catch (System.Exception e) { result.SetFail(e, "GetItems"); } return(Ok(result)); }
public IActionResult GetItems(long stock_id, [FromQuery] string date) { Cloud.Result <StockItem> result = new Cloud.Result <StockItem>(); try { DateTime checkTime = DateTime.Parse(date); var items = _cafeContext.StockItems.Where( stockItem => stockItem.Stock.Id == stock_id && stockItem.TimeRequired.Date == checkTime.Date); if (items == null) { result.SetFail("Items not found"); } else { result.SetSuccess("stock_items", items.ToList()); } } catch (System.Exception e) { result.SetFail(e, "GetItems"); } return(Ok(result)); }
public async Task <IActionResult> CreateOrderItemAsync( long user_id, long order_id, [FromBody] OrderItem orderItem) { Cloud.Result <OrderItem> result = new Cloud.Result <OrderItem>(); try { if (!ModelState.IsValid) { result.SetFail("Invalid model state"); } else { _logger.LogInformation(string.Format( "Order Item Create request from user id {0} received by Nest-{1}.{2} at {3}. {4}", user_id, _runtime.NestTag, _runtime.CushionIndex, DateTime.Now.ToString("t"), JsonConvert.SerializeObject(orderItem))); Wppod.Models.Order order = _cafeContext.Orders.FirstOrDefault( searchOrder => searchOrder.Id == order_id); if (order == null) { result.SetFail("Order not found"); } else { _cafeContext.OrderItems.Add(orderItem); await _cafeContext.SaveChangesAsync(); _runtime.SendToNest( JsonConvert.SerializeObject(orderItem), "stockallocator"); result.SetSuccess("order_item", orderItem); } } } catch (System.Exception e) { result.SetFail(e, "CreateOrderAsync"); } return(Ok(result)); }
public async Task <IActionResult> CreateAsync(int menu_id, [FromBody] MenuItem item) { try { if (!ModelState.IsValid) { return(StatusCode(422, ModelState)); } Cloud.Result <MenuItem> result = new Cloud.Result <MenuItem>(); Menu menu = _cafeContext.Menus.FirstOrDefault( searchMenu => searchMenu.Id == menu_id); if (menu == null) { result.SetFail("Menu not found"); } else { item.Menu = menu; string status; status = string.Format("Menu Item Create request, received by Nest {0}.{1} at {2}", _runtime.NestTag, _runtime.CushionIndex, DateTime.Now.ToString("t")); _logger.LogInformation(status); status = string.Format("Create under Menu id {0}, the Menu Item {1}", menu_id, JsonConvert.SerializeObject(item)); _logger.LogInformation(status); _cafeContext.MenuItems.Add(item); await _cafeContext.SaveChangesAsync(); _runtime.SendToNest( JsonConvert.SerializeObject(item), "stockallocator"); result.SetSuccess("menu_item", item); } return(Ok(result)); } catch (System.Exception e) { return(StatusCode(500, e)); } }