public async Task <AdminCityEditDeleteServiceModel> GetUpdateAsync(int?id) { var city = await this.context.Cities .FindAsync(id); if (city == null) { return(null); } var country = await this.context.Countries.FindAsync(city.CountryId); var model = new AdminCityEditDeleteServiceModel { Country = country.Name, City = city, CityList = await this.context.Cities .Where(x => x.CountryId == city.CountryId) .OrderBy(x => x.Name) .Select(x => x.Name) .Distinct() .ToListAsync(), }; return(model); }
public async Task <IActionResult> EditPostAsync(int?id, AdminCityEditDeleteServiceModel model) { if (this.ModelState.IsValid) { bool isEdited = await this.adminCityService.UpdateAsync(id, model.City.Name); if (!isEdited) { this.StatusMessage = CouldNotUpdateRecord; var modelVM = await this.adminCityService.GetUpdateAsync(id); modelVM.StatusMessage = this.StatusMessage; return(this.View(modelVM)); } return(this.RedirectToAction(nameof(this.Index)) .WithSuccess(string.Empty, RecordUpdatedSuccessfully)); } return(this.RedirectToAction(nameof(this.Index)) .WithWarning(string.Empty, RecordIdIsInvalid)); }