Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] City city)
        {
            if (CityExist(city))
            {
                ModelState.AddModelError(string.Empty, "Таке місто вже існує");
            }
            if (id != city.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
Пример #2
0
 public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Info,Logo")] Bank bank)
 {
     if (BankExist(bank))
     {
         ModelState.AddModelError(string.Empty, "Такий банк вже існує");
     }
     if (id != bank.Id)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(bank);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!BankExists(bank.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(bank));
 }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,BankId,Number,CityId,Info,NumberOfEmployers,Photo")] Department department)
        {
            ViewBag.BankId   = department.BankId;
            ViewBag.BankName = _context.Bank.Where(bank => bank.Id == department.BankId).FirstOrDefault().Name;
            if (DepartmentExist(department))
            {
                ModelState.AddModelError(string.Empty, "Таке відділення вже існує");
            }


            if (id != department.Id)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction("Index", "Departments", new { id = department.BankId }));
            }
            ViewData["BankId"] = new SelectList(_context.Bank, "Id", "Name", department.BankId);
            ViewData["CityId"] = new SelectList(_context.City, "Id", "Name", department.CityId);
            return(View(department));
        }