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