Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdPurchaseOfcheese,RawMaterials,Quantity,Summ,Date,Employees")] PurchaseOfCheese purchaseOfCheese)
        {
            if (id != purchaseOfCheese.IdPurchaseOfcheese)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await Task.Run(() => purchaserepo.Update(purchaseOfCheese));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PurchaseOfCheeseExists(purchaseOfCheese.IdPurchaseOfcheese))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Employees"]    = new SelectList(employeesrepo.GetList(), "IdEmployees", "FullName", purchaseOfCheese.Employees);
            ViewData["RawMaterials"] = new SelectList(rawMaterialsrepo.GetList(), "IdRawMaterials", "Names", purchaseOfCheese.RawMaterials);
            return(View(purchaseOfCheese));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("IdPurchaseOfcheese,RawMaterials,Quantity,Summ,Date,Employees")] PurchaseOfCheese purchaseOfCheese)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await Task.Run(() => purchaserepo.Create(purchaseOfCheese));

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    ViewBag.message          = "Недостаточно суммы в бюджете для покупки сырья";
                    ViewData["Employees"]    = new SelectList(employeesrepo.GetList(), "IdEmployees", "FullName", purchaseOfCheese.Employees);
                    ViewData["RawMaterials"] = new SelectList(rawMaterialsrepo.GetList(), "IdRawMaterials", "Names", purchaseOfCheese.RawMaterials);
                    return(View(purchaseOfCheese));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }