// GET: Agencies/Create public IActionResult Create() { var model = new NewAgency(); ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name"); return(View(model)); }
public async Task <IActionResult> Create(NewAgency newAgency) { UserAgency userAgency = newAgency.UserAgency; if (newAgency.Agency.AgencyId == 0) { ViewBag.Message = string.Format("Please select an Agency !"); ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name"); return(View(newAgency)); } var user = await GetCurrentUserAsync(); userAgency.AgencyId = newAgency.Agency.AgencyId; userAgency.UserId = user.Id; userAgency.OpeningDate = DateTime.Now; ModelState.Remove("UserAgency.UserId"); ModelState.Remove("Agency.Name"); if (ModelState.IsValid) { _context.Add(userAgency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name"); return(View(newAgency)); }
public async Task <IActionResult> Create(NewAgency newAgency) { //if (ModelState.IsValid) { // add data to userAgency table UserAgency userAgency = new UserAgency(); var user = await GetCurrentUserAsync(); userAgency.AgencyId = newAgency.Agency.AgencyId; userAgency.UserId = user.Id; userAgency.AccountNo = newAgency.UserAgency.AccountNo; userAgency.OpeningDate = DateTime.Now; _context.Add(userAgency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name", newAgency.Agency.CountryId); return(View(newAgency)); }