[2aea0fd] | 1 | using Microsoft.AspNetCore.Identity;
|
---|
| 2 | using Microsoft.AspNetCore.Mvc;
|
---|
| 3 | using Microsoft.EntityFrameworkCore;
|
---|
| 4 | using PostgreSqlDotnetCore.Controllers;
|
---|
| 5 | using PostgreSqlDotnetCore.Models;
|
---|
| 6 | using System.Net;
|
---|
| 7 |
|
---|
| 8 | namespace PostgreSqlDotnetCore.Controllers
|
---|
| 9 | {
|
---|
| 10 | public class CityController : BaseController
|
---|
| 11 | {
|
---|
| 12 | public CityController(UserManager<IdentityUser> userManager) : base(userManager)
|
---|
| 13 | {
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | // GET: Customer
|
---|
| 17 | public async Task<ActionResult> IndexAsync()
|
---|
| 18 | {
|
---|
| 19 | // check for permission
|
---|
| 20 | UsersClass customerClass = await checkAuthorizationAsync();
|
---|
| 21 | if (customerClass == null)
|
---|
| 22 | {
|
---|
| 23 | return RedirectToAction("AccessDenied", "Error");
|
---|
| 24 | }
|
---|
| 25 | //return View(Enumerable.Empty<UsersClass>());
|
---|
| 26 | return View(db.CitiesObj.ToList());
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | // GET: Customer/Details/5
|
---|
| 30 | public ActionResult Details(int? id)
|
---|
| 31 | {
|
---|
| 32 | if (id == null)
|
---|
| 33 | {
|
---|
| 34 | return RedirectToAction("NotExist", "Error");
|
---|
| 35 | }
|
---|
| 36 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 37 | if (cityClass == null)
|
---|
| 38 | {
|
---|
| 39 | return RedirectToAction("NotExist", "Error");
|
---|
| 40 | }
|
---|
| 41 | return View(cityClass);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | // GET: Customer/Create
|
---|
| 45 | //public ActionResult Create()
|
---|
| 46 | //{
|
---|
| 47 | // return View();
|
---|
| 48 | //}
|
---|
| 49 |
|
---|
| 50 | public ActionResult Create()
|
---|
| 51 | {
|
---|
| 52 |
|
---|
| 53 | return View();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // POST: Customer/Create
|
---|
| 57 | // To protect from overposting attacks, enable the specific properties you want to bind to, for
|
---|
| 58 | // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
---|
| 59 | [HttpPost]
|
---|
| 60 | [ValidateAntiForgeryToken]
|
---|
| 61 | public ActionResult Create([Bind(include: "id,name")] CitiesClass cityClass)
|
---|
| 62 | {
|
---|
| 63 | if (ModelState.IsValid)
|
---|
| 64 | {
|
---|
| 65 | db.CitiesObj.Add(cityClass);
|
---|
| 66 | db.SaveChanges();
|
---|
| 67 | return RedirectToAction("Index");
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | return View(cityClass);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | // GET: Customer/Edit/5
|
---|
| 74 | public ActionResult Edit(int? id)
|
---|
| 75 | {
|
---|
| 76 | if (id == null)
|
---|
| 77 | {
|
---|
| 78 | return RedirectToAction("NotExist", "Error");
|
---|
| 79 | }
|
---|
| 80 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 81 | if (cityClass == null)
|
---|
| 82 | {
|
---|
| 83 | return RedirectToAction("NotExist", "Error");
|
---|
| 84 | }
|
---|
| 85 | return View(cityClass);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | // POST: Customer/Edit/5
|
---|
| 89 | // To protect from overposting attacks, enable the specific properties you want to bind to, for
|
---|
| 90 | // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
---|
| 91 | [HttpPost]
|
---|
| 92 | [ValidateAntiForgeryToken]
|
---|
| 93 | public ActionResult Edit([Bind(include: "id,name")] CitiesClass cityClass)
|
---|
| 94 | {
|
---|
| 95 | if (ModelState.IsValid)
|
---|
| 96 | {
|
---|
| 97 | db.Entry(cityClass).State = EntityState.Modified;
|
---|
| 98 | db.SaveChanges();
|
---|
| 99 | return RedirectToAction("Index");
|
---|
| 100 | }
|
---|
| 101 | return View(cityClass);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | // GET: Customer/Delete/5
|
---|
| 105 | public ActionResult Delete(int? id)
|
---|
| 106 | {
|
---|
| 107 | if (id == null)
|
---|
| 108 | {
|
---|
| 109 | return RedirectToAction("NotExist", "Error");
|
---|
| 110 | }
|
---|
| 111 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 112 | if (cityClass == null)
|
---|
| 113 | {
|
---|
| 114 | return RedirectToAction("NotExist", "Error");
|
---|
| 115 | }
|
---|
| 116 | return View(cityClass);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // POST: Customer/Delete/5
|
---|
| 120 | [HttpPost, ActionName("Delete")]
|
---|
| 121 | [ValidateAntiForgeryToken]
|
---|
| 122 | public ActionResult DeleteConfirmed(int id)
|
---|
| 123 | {
|
---|
| 124 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 125 | db.CitiesObj.Remove(cityClass);
|
---|
| 126 | db.SaveChanges();
|
---|
| 127 | return RedirectToAction("Index");
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | protected override void Dispose(bool disposing)
|
---|
| 131 | {
|
---|
| 132 | if (disposing)
|
---|
| 133 | {
|
---|
| 134 | db.Dispose();
|
---|
| 135 | }
|
---|
| 136 | base.Dispose(disposing);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|