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