public async Task <IActionResult> Create([Bind("Id,Name,Info,Logo")] Bank bank) { if (BankExist(bank)) { ModelState.AddModelError(string.Empty, "Такий банк вже існує"); } if (ModelState.IsValid) { _context.Add(bank); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bank)); }
public async Task <IActionResult> Create([Bind("Id,Name")] City city) { if (CityExist(city)) { ModelState.AddModelError(string.Empty, "Таке місто вже існує"); } if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create(int bankId, [Bind("Id,BankId,Number,CityId,Info,NumberOfEmployers,Photo")] Department department) { department.BankId = bankId; if (DepartmentExist(department)) { ModelState.AddModelError(string.Empty, "Таке відділення вже існує"); } if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Departments", new { id = bankId })); } ViewData["CityId"] = new SelectList(_context.City, "Id", "Name", department.CityId); ViewBag.BankId = bankId; ViewBag.BankName = _context.Bank.Where(bank => bank.Id == bankId).FirstOrDefault().Name; return(View(department)); }