Exemple #1
0
        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));
        }
Exemple #2
0
 static void Main(string[] args)
 {
     Countryside c = new Countryside();
     c.run();
     c.Travel();
     //new Test().forTest(); // Anonymous Object Reference
     Console.ReadLine();
 }
Exemple #3
0
        // 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));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        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}"));
        }
Exemple #9
0
        // 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)));
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Countryside Ontario = new Countryside();

            Ontario.run();
        }