示例#1
0
        public async Task <T> Add(T entity)
        {
            _appDbContext.Set <T>().Add(entity);
            await _appDbContext.SaveChangesAsync();

            return(entity);
        }
示例#2
0
        public async Task <IActionResult> Payment(int id, bool checkPayment)
        {
            var order = await _context.Orders
                        .FirstOrDefaultAsync(m => m.Id == id);

            if (order == null)
            {
                return(View("NotFound"));
            }

            if (checkPayment)
            {
                order.IsPaid      = true;
                order.PaymentDate = DateTime.Now;
            }
            else
            {
                order.IsPaid      = false;
                order.PaymentDate = null;
            }

            order.UpdateDate = DateTime.Now;
            _context.Orders.Update(order);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Order"));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,Name,SummaryDescription,FullDescription,Price,ImageUrl,ImageThumbnailUrl,IsFavoriteSnack,InStock,CategoryId")] Snack snack)
        {
            if (snack.CategoryId == 0)
            {
                ModelState.AddModelError("CategoryId", "Selecione uma categoria");
            }

            if (ModelState.IsValid)
            {
                var category = await _context.Categories
                               .FindAsync(snack.CategoryId);

                if (category == null)
                {
                    ModelState.AddModelError("CategoryId", "Selecione uma categoria válida");
                }
                else
                {
                    _context.Add(snack);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }

            ViewData["CategoryItems"] = GetCategoryItems();
            return(View(snack));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }