source: PostgreSqlDotnetCore/Controllers/JobsController.cs@ 118e414

main
Last change on this file since 118e414 was 6782104, checked in by ElenaMoskova <elena.moskova99@…>, 3 months ago

fix authorization

implement hiding menu items

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