public async Task <IActionResult> EditPost(int?id) { if (id == null) { return(NotFound()); } StateProvinces stateProvince = await _context.StateProvinces.Include("Country").SingleOrDefaultAsync(s => s.StateProvinceId == id); stateProvince.LastEditedBy = 1; if (await TryUpdateModelAsync <StateProvinces>( stateProvince, "", s => s.StateProvinceCode, s => s.StateProvinceName, s => s.CountryId, s => s.SalesTerritory, s => s.LatestRecordedPopulation, s => s.LastEditedBy)) { 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."); } } ViewData["CountryId"] = new SelectList(_context.Countries.Where(s => s.Subregion == stateProvince.Country.Subregion), "CountryId", "CountryName", stateProvince.CountryId); return(View(stateProvince)); }
/// <summary> /// Dependent type names of this entity /// </summary> public void DeleteChildren(DatabaseEntities dbContext) { foreach (var x in StateProvinces.ToList()) { x.DeleteFull(dbContext); } }
public object Get(StateProvinces request) { return new StateProvincesResponse { StateProvinces = Db.Select<StateProvince>() }; }
/// <summary> /// Active Dependent type names of this object /// </summary> public List <string> DependentObjectNames() { var dependentObjects = new List <string>(); if (StateProvinces.Any()) { dependentObjects.Add(typeof(StateProvince).Name); } return(dependentObjects.Distinct().ToList()); }
public void GetCanadianProvinces() { IEnumerable <StateProvince> stateProvinces = StateProvinces.GetAll(); List <string> canadianProvinces = stateProvinces .Where(x => x.Country == "CA") .Select(x => x.Name) .ToList(); Assert.AreEqual(13, canadianProvinces.Count()); Assert.Contains("Saskatchewan", canadianProvinces); }
public void JoinToGetBritishEmployees() { var employees = Employees.GetAll(); var stateProvinces = StateProvinces.GetAll(); var britishStateProvinces = stateProvinces.Where(x => x.Country == "GB"); var joinedData = employees.Join(britishStateProvinces, e => e.StateProvinceID, sp => sp.StateProvinceID, (employee, stateProvince) => employee); IEnumerable <string> brits = joinedData .Select(x => x.FirstName + " " + x.LastName); }
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)); }
/// <summary> /// Does this object have any dependent objects? (If it does have dependent objects, these would need to be deleted before this object could be deleted.) /// </summary> /// <returns></returns> public bool HasDependentObjects() { return(StateProvinces.Any()); }