public async Task <IActionResult> Create(Countryside countryside) { if (ModelState.IsValid) { try { _context.Add(countryside); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(countryside)); }
static void Main(string[] args) { Countryside c = new Countryside(); c.run(); c.Travel(); //new Test().forTest(); // Anonymous Object Reference Console.ReadLine(); }
// GET: Countrysides/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } Countryside countryside = await _context.countrysides .Include(D => D.Districts) .ThenInclude(C => C.Churches) .FirstOrDefaultAsync(m => m.Id == id); if (countryside == null) { return(NotFound()); } return(View(countryside)); }
public async Task <IActionResult> EditDistrict(int?id) { if (id == null) { return(NotFound()); } District district = await _context.districts.FindAsync(id); if (district == null) { return(NotFound()); } Countryside countryside = await _context.countrysides.FirstOrDefaultAsync(c => c.Districts.FirstOrDefault(d => d.Id == district.Id) != null); district.IdCountryside = countryside.Id; return(View(district)); }
public async Task <IActionResult> AddDistrict(int?id) { if (id == null) { return(NotFound()); } Countryside countryside = await _context.countrysides.FindAsync(id); if (countryside == null) { return(NotFound()); } District model = new District { IdCountryside = countryside.Id }; return(View(model)); }
public async Task <IActionResult> AddDistrict(District district) { if (ModelState.IsValid) { Countryside countryside = await _context.countrysides .Include(c => c.Districts) .FirstOrDefaultAsync(c => c.Id == district.Id); if (countryside == null) { return(NotFound()); } try { district.Id = 0; countryside.Districts.Add(district); _context.Update(countryside); await _context.SaveChangesAsync(); return(RedirectToAction($"{nameof(Details)}/{countryside.Id}")); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(district)); }
public async Task <IActionResult> DetailsDistrict(int?id) { if (id == null) { return(NotFound()); } District district = await _context.districts .Include(c => c.Churches) .FirstOrDefaultAsync(m => m.Id == id); if (district == null) { return(NotFound()); } Countryside countryside = await _context.countrysides.FirstOrDefaultAsync(d => d.Districts.FirstOrDefault(c => c.Id == district.Id) != null); district.IdCountryside = countryside.Id; return(View(district)); }
public async Task <IActionResult> DeleteDistrict(int?id) { if (id == null) { return(NotFound()); } District district = await _context.districts .Include(d => d.Churches) .FirstOrDefaultAsync(m => m.Id == id); if (district == null) { return(NotFound()); } Countryside countryside = await _context.countrysides.FirstOrDefaultAsync(c => c.Districts.FirstOrDefault(d => d.Id == district.Id) != null); _context.districts.Remove(district); await _context.SaveChangesAsync(); return(RedirectToAction($"{nameof(Details)}/{countryside.Id}")); }
// GET: Countrysides/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } Countryside countryside = await _context.countrysides .Include(d => d.Districts) .ThenInclude(c => c.Churches) .FirstOrDefaultAsync(m => m.Id == id); if (countryside == null) { return(NotFound()); } _context.countrysides.Remove(countryside); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
static void Main(string[] args) { Countryside Ontario = new Countryside(); Ontario.run(); }