public async Task <IActionResult> Create([Bind("CountryName,FormalName,IsoAlpha3Code,IsoNumericCode,CountryType,LatestRecordedPopulation,Continent,Region,Subregion")] Countries country) { if (ModelState.IsValid) { string previousRegion = HttpContext.Request.Form["previousRegion"]; if (previousRegion != country.Region) { SelectList regionSelectList = new SelectList(await _context.Countries.Select(c => c.Region).Distinct().OrderBy(r => 1).ToListAsync(), "", "", country.Region); ViewBag.RegionSelectList = regionSelectList; ViewBag.PreviousRegion = country.Region; ViewBag.SubregionSelectList = new SelectList(await _context.Countries.Where(r => r.Region == country.Region).Select(c => c.Subregion).Distinct().OrderBy(r => 1).ToListAsync()); } else { country.LastEditedBy = 1; _context.Add(country); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } } } return(View(country)); }
public async Task <IActionResult> Create([Bind("PersonId,FullName,PreferredName,IsPermittedToLogon,LogonName,IsExternalLogonProvider,HashedPassword,IsSystemUser,IsEmployee,IsSalesperson,UserPreferences,PhoneNumber,FaxNumber,EMailAddress,Photo,CustomFields,LastEditedBy,ValidFrom,ValidTo")] People people) { if (ModelState.IsValid) { _context.Add(people); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(people)); }
public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,BillToCustomerId,CustomerCategoryId,BuyingGroupId,PrimaryContactPersonId,AlternateContactPersonId,DeliveryMethodId,DeliveryCityId,PostalCityId,CreditLimit,AccountOpenedDate,StandardDiscountPercentage,IsStatementSent,IsOnCreditHold,PaymentDays,PhoneNumber,FaxNumber,DeliveryRun,RunPosition,WebsiteURL,DeliveryAddressLine1,DeliveryAddressLine2,DeliveryPostalCode,DeliveryLocation,PostalAddressLine1,PostalAddressLine2,PostalPostalCode,LastEditedBy,ValidFrom,ValidTo")] Customers customers) { if (ModelState.IsValid) { _context.Add(customers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AlternateContactPersonId"] = new SelectList(_context.People, "PersonId", "FullName", customers.AlternateContactPersonId); ViewData["CustomerCategoryId"] = new SelectList(_context.CustomerCategories, "CustomerCategoryId", "CustomerCategoryName", customers.CustomerCategoryId); ViewData["DeliveryCityId"] = new SelectList(_context.Cities, "CityId", "CityName", customers.DeliveryCityId); ViewData["PostalCityId"] = new SelectList(_context.Cities, "CityId", "CityName", customers.PostalCityId); ViewData["PrimaryContactPersonId"] = new SelectList(_context.People, "PersonId", "FullName", customers.PrimaryContactPersonId); return(View(customers)); }
public async Task <IActionResult> Create([Bind("StateProvinceCode,StateProvinceName,CountryId,SalesTerritory,LatestRecordedPopulation")] StateProvinces stateProvince) { if (ModelState.IsValid) { _context.Add(stateProvince); try { await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Countries", new { id = stateProvince.CountryId.ToString() })); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } } ViewBag.CountryId = stateProvince.CountryId.ToString(); return(View(stateProvince)); }