public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryNum,CategoryName,Description,Status")] SnackCategory snackCategory)
        {
            if (id != snackCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(snackCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SnackCategoryExists(snackCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CardCode,SecretKey,UserAccount,CardStatus,Price")] prepaidCard prepaidCard)
        {
            if (id != prepaidCard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(prepaidCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!prepaidCardExists(prepaidCard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(prepaidCard));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserAccount,Password,Money,Phone,Address")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public bool FinishOrder(string orderid)
        {
            var order = _context.Orders.FirstOrDefault(o => o.OrderId == orderid);

            order.Status = 1;
            _context.Update(order);
            _context.SaveChanges();
            //PrintTicket(order.OrderId);
            return(true);
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(int id, AdminViewModel adminEditView)
        {
            if (!IsSafe())
            {
                return(RedirectToAction("Login", "Admins"));
            }
            if (id != adminEditView.WorkMan.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string not_encrypted = adminEditView.WorkMan.PassWord;
                    //adminEditView.WorkMan.PassWord = PassWordHelper.Md532Salt(not_encrypted, adminEditView.WorkMan.LoginAccount);
                    adminEditView.WorkMan.CreateTime = DateTime.Now;
                    _context.Update(adminEditView.WorkMan);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdminExists(adminEditView.WorkMan.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }


                return(RedirectToAction("Index", "Admins", adminEditView));

                // return RedirectToAction(nameof(Index));
            }
            return(View(adminEditView));
        }
        public async Task <IActionResult> Edit(int id, SnackEditViewModel snackEditView)
        {
            if (id != snackEditView.SnackInfo.Id)
            {
                return(NotFound());
            }

            //if (ModelState.IsValid)
            //{
            if (snackEditView.PushFile != null)
            {
                string file_name = $"{snackEditView.SnackInfo.SnackNum}_{DateTime.Now.ToString("yyyymmddHHmmss")}.jpg";
                using (var fileStream = new FileStream(Path.Combine(_dir, file_name), FileMode.Create, FileAccess.Write))
                {
                    snackEditView.PushFile.CopyTo(fileStream);
                }
                snackEditView.SnackInfo.ImgUrl = relative_path + file_name;
            }



            try
            {
                long category_id = _context.SnackCategory.FirstOrDefault(c => c.CategoryName == snackEditView.CategoryName).CategoryNum;
                snackEditView.SnackInfo.CategoryId = category_id;
                if (snackEditView.SnackInfo.ImgUrl == null)
                {
                    snackEditView.SnackInfo.ImgUrl = _context.SnackInfo.AsNoTracking().FirstOrDefault(s => s.Id == snackEditView.SnackInfo.Id).ImgUrl;
                }
                _context.Update(snackEditView.SnackInfo);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SnackInfoExists(snackEditView.SnackInfo.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
            //}
        }