示例#1
0
 public ActionResult Create(Vegetable vegetable)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ctx.Vegetables.Add(vegetable);
             ctx.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         return(View(vegetable));
     }
     catch
     {
         return(View(vegetable));
     }
 }
示例#2
0
 public ActionResult Create(Sale sale)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ctx.Sales.Add(sale);
             ctx.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         ViewBag.VegetableId = new SelectList(ctx.Vegetables, "Id", "Name");
         return(View(sale));
     }
     catch
     {
         return(View(sale));
     }
 }
示例#3
0
        public ActionResult Edit(int id, Sale sale)
        {
            ViewBag.VegetableId = new SelectList(ctx.Vegetables, "Id", "Name");
            Sale sales = ctx.Sales.SingleOrDefault(x => x.SaleId == id);

            try
            {
                if (sales != null)
                {
                    sales.SaleDate      = sale.SaleDate;
                    sales.SaleWeight    = sale.SaleWeight;
                    sales.SaleUnitPrice = sale.SaleUnitPrice;
                    sales.SaleActive    = sale.SaleActive;
                    ctx.SaveChanges();
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }