public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, [Table("orderhistory")] ICollector <TableOrderItem> items, ILogger log) { try { log.LogInformation("OrderFunction is called"); var order = await req.Content.ReadAsAsync <Order>(); foreach (var item in order.Items) { var orderId = Guid.NewGuid().ToString(); TableOrderItem toi = new TableOrderItem(item); toi.PartitionKey = "history"; toi.RowKey = $"{orderId} - {item.Id}"; items.Add(toi); } return(new OkResult()); } catch (Exception exp) { log.LogError("Error happened, while calling OrderFunction", exp.Message); return(new BadRequestObjectResult(exp.Message)); } }
public IActionResult ConfirmOrder() { List <string> orders = HttpContext.Request.Query["orders"].ToString().Split(",").ToList <string>(); int user = int.Parse(HttpContext.Request.Query["user"]); int table = int.Parse(HttpContext.Request.Query["table"]); Table selectedTable = context.Tables.Where(e => e.Id == table).FirstOrDefault <Table>(); selectedTable.UseStatus = true; context.Tables.Update(selectedTable); TableOrder tableOrder = new TableOrder(); tableOrder.DoneStatus = false; tableOrder.Date = DateTime.Now; tableOrder.User = context.Users.Where(e => e.Id == user).FirstOrDefault <User>(); tableOrder.IdUser = user; tableOrder.Table = selectedTable; tableOrder.IdTable = selectedTable.Id; context.TableOrders.Add(tableOrder); var saveTableOrder = context.SaveChangesAsync(); if (saveTableOrder.IsCompletedSuccessfully) { orders.ForEach(d => { KafeWeb.Models.Order order = context.Orders.Where(x => x.Id == int.Parse(d)).FirstOrDefault <KafeWeb.Models.Order>(); order.DoneStatus = true; context.Orders.Update(order); var saveOrder = context.SaveChangesAsync(); if (saveOrder.IsCompletedSuccessfully) { List <TableOrder> lastTableOrder = context.TableOrders.ToList <TableOrder>(); TableOrderItem tableOrderItem = new TableOrderItem(); tableOrderItem.Order = order; tableOrderItem.TableOrder = lastTableOrder.Last <TableOrder>(); tableOrderItem.IdTableOrder = lastTableOrder.Last <TableOrder>().Id; tableOrderItem.IdOrder = order.Id; context.TableOrderItems.Add(tableOrderItem); context.SaveChanges(); } }); } return(Redirect("/Order")); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, [Table("orderhistory")] ICollector <TableOrderItem> items, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string orderId = System.Guid.NewGuid().ToString(); Order order = await req.Content.ReadAsAsync <Order>(); foreach (var item in order.Items) { TableOrderItem tableOrderItem = new TableOrderItem(item); tableOrderItem.PartitionKey = "history"; tableOrderItem.RowKey = $"{orderId} - {item.Id}"; items.Add(tableOrderItem); } return(new OkResult()); }