[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()
|
---|
[d6040ef] | 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 |
|
---|
[2aea0fd] | 30 |
|
---|
| 31 | // GET: Customer/Details/5
|
---|
| 32 | public ActionResult Details(int? id)
|
---|
| 33 | {
|
---|
| 34 | if (id == null)
|
---|
| 35 | {
|
---|
| 36 | return RedirectToAction("NotExist", "Error");
|
---|
| 37 | }
|
---|
| 38 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 39 | if (cityClass == null)
|
---|
| 40 | {
|
---|
| 41 | return RedirectToAction("NotExist", "Error");
|
---|
| 42 | }
|
---|
| 43 | return View(cityClass);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | // GET: Customer/Create
|
---|
| 47 | //public ActionResult Create()
|
---|
| 48 | //{
|
---|
| 49 | // return View();
|
---|
| 50 | //}
|
---|
| 51 |
|
---|
| 52 | public ActionResult Create()
|
---|
| 53 | {
|
---|
| 54 |
|
---|
| 55 | return View();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | // POST: Customer/Create
|
---|
| 59 | // To protect from overposting attacks, enable the specific properties you want to bind to, for
|
---|
| 60 | // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
---|
| 61 | [HttpPost]
|
---|
| 62 | [ValidateAntiForgeryToken]
|
---|
| 63 | public ActionResult Create([Bind(include: "id,name")] CitiesClass cityClass)
|
---|
| 64 | {
|
---|
| 65 | if (ModelState.IsValid)
|
---|
| 66 | {
|
---|
| 67 | db.CitiesObj.Add(cityClass);
|
---|
| 68 | db.SaveChanges();
|
---|
| 69 | return RedirectToAction("Index");
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | return View(cityClass);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | // GET: Customer/Edit/5
|
---|
| 76 | public ActionResult Edit(int? id)
|
---|
| 77 | {
|
---|
| 78 | if (id == null)
|
---|
| 79 | {
|
---|
| 80 | return RedirectToAction("NotExist", "Error");
|
---|
| 81 | }
|
---|
| 82 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 83 | if (cityClass == null)
|
---|
| 84 | {
|
---|
| 85 | return RedirectToAction("NotExist", "Error");
|
---|
| 86 | }
|
---|
| 87 | return View(cityClass);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | // POST: Customer/Edit/5
|
---|
| 91 | // To protect from overposting attacks, enable the specific properties you want to bind to, for
|
---|
| 92 | // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
---|
| 93 | [HttpPost]
|
---|
| 94 | [ValidateAntiForgeryToken]
|
---|
| 95 | public ActionResult Edit([Bind(include: "id,name")] CitiesClass cityClass)
|
---|
| 96 | {
|
---|
| 97 | if (ModelState.IsValid)
|
---|
| 98 | {
|
---|
| 99 | db.Entry(cityClass).State = EntityState.Modified;
|
---|
| 100 | db.SaveChanges();
|
---|
| 101 | return RedirectToAction("Index");
|
---|
| 102 | }
|
---|
| 103 | return View(cityClass);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // GET: Customer/Delete/5
|
---|
| 107 | public ActionResult Delete(int? id)
|
---|
| 108 | {
|
---|
| 109 | if (id == null)
|
---|
| 110 | {
|
---|
| 111 | return RedirectToAction("NotExist", "Error");
|
---|
| 112 | }
|
---|
| 113 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 114 | if (cityClass == null)
|
---|
| 115 | {
|
---|
| 116 | return RedirectToAction("NotExist", "Error");
|
---|
| 117 | }
|
---|
| 118 | return View(cityClass);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | // POST: Customer/Delete/5
|
---|
| 122 | [HttpPost, ActionName("Delete")]
|
---|
| 123 | [ValidateAntiForgeryToken]
|
---|
| 124 | public ActionResult DeleteConfirmed(int id)
|
---|
| 125 | {
|
---|
| 126 | CitiesClass cityClass = db.CitiesObj.Find(id);
|
---|
| 127 | db.CitiesObj.Remove(cityClass);
|
---|
| 128 | db.SaveChanges();
|
---|
| 129 | return RedirectToAction("Index");
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | protected override void Dispose(bool disposing)
|
---|
| 133 | {
|
---|
| 134 | if (disposing)
|
---|
| 135 | {
|
---|
| 136 | db.Dispose();
|
---|
| 137 | }
|
---|
| 138 | base.Dispose(disposing);
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|