コード例 #1
0
ファイル: TableController.cs プロジェクト: mojila/kafe-web
        public async Task <IActionResult> Create([Bind("Id,Name,UseStatus")] Table table)
        {
            if (ModelState.IsValid)
            {
                _context.Add(table);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(table));
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: mojila/kafe-web
        public async Task <IActionResult> Create([Bind("Id,Name,Username,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Picture")] MenuItem menuItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(menuItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuItem));
        }
コード例 #4
0
        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"));
        }