Changeset 57fc402 for PostgreSqlDotnetCore/Controllers
- Timestamp:
- 08/22/24 01:46:17 (3 months ago)
- Branches:
- main
- Children:
- 72b1da2
- Parents:
- d6040ef
- Location:
- PostgreSqlDotnetCore/Controllers
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
rd6040ef r57fc402 79 79 //} 80 80 81 public ActionResult Create() 82 { 83 var model = new BlogPostConsultation(); 84 return View(model); 81 /* public ActionResult Create() 82 { 83 var model = new BlogPostConsultation(); 84 return View(model); 85 }*/ 86 87 public async Task<ActionResult> CreateAsync() 88 { 89 90 // check for permission 91 UsersClass customerClass = await getCrrentUser(); 92 // set if is authenticated 93 ViewBag.isAuthenticated = customerClass; 94 return View(); 85 95 } 86 96 … … 90 100 [HttpPost] 91 101 [ValidateAntiForgeryToken] 92 public async Task<ActionResult> CreateAsync([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 93 { 94 if (ModelState.IsValid) 95 { 96 bool isAuthenticated = User.Identity.IsAuthenticated; 97 if (isAuthenticated) 98 { 99 var user = await _userManager.GetUserAsync(User); 100 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 101 blogClass.users_id = customerClass.id; 102 db.BlogPostControllerObj.Add(blogClass); 103 db.SaveChanges(); 104 return RedirectToAction("Index"); 105 } 106 else 107 { 108 return RedirectToAction("AccessDenied", "Error"); 109 } 110 } 111 112 return View(blogClass); 113 } 102 public async Task<ActionResult> CreateAsync([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 103 { 104 if (ModelState.IsValid) 105 { 106 bool isAuthenticated = User.Identity.IsAuthenticated; 107 if (isAuthenticated) 108 { 109 var user = await _userManager.GetUserAsync(User); 110 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 111 if (customerClass != null) 112 { 113 // Поставете users_id на идентификаторот на корисникот 114 blogClass.users_id = customerClass.id; 115 //blogClass.date_askes = DateOnly.FromDateTime(DateTime.UtcNow); 116 blogClass.date_askes = DateOnly.FromDateTime(DateTime.Now); // Ова ќе стави локално време 117 118 db.BlogPostControllerObj.Add(blogClass); 119 await db.SaveChangesAsync(); 120 return RedirectToAction("Index"); 121 } 122 } 123 else 124 { 125 return RedirectToAction("AccessDenied", "Error"); 126 } 127 } 128 129 return View(blogClass); 130 } 131 132 133 134 135 114 136 115 137 // GET: Customer/Edit/5 -
PostgreSqlDotnetCore/Controllers/CityController.cs
rd6040ef r57fc402 17 17 public async Task<ActionResult> IndexAsync() 18 18 { 19 // check for permission 20 UsersClass customerClass = await checkAuthorizationAsync(); 21 22 23 if (customerClass == null) 24 { 25 return RedirectToAction("AccessDenied", "Error"); 26 } 27 28 var citiess = await db.CitiesObj.ToListAsync(); 29 30 return View(citiess); 31 } 32 33 34 35 36 /* public async Task<ActionResult> IndexAsync() 37 { 19 38 // check for permission 20 39 UsersClass customerClass = await checkAuthorizationAsync(); … … 26 45 return View(db.CitiesObj.ToList()); 27 46 } 28 47 */ 48 29 49 30 50 … … 138 158 base.Dispose(disposing); 139 159 } 160 161 162 163 140 164 } 141 165 } -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
rd6040ef r57fc402 78 78 79 79 // GET: Customer/Details/5 80 public ActionResultDetails(int? id)80 public async Task<ActionResult> Details(int? id) 81 81 { 82 82 if (id == null) … … 84 84 return RedirectToAction("NotExist", "Error"); 85 85 } 86 UsersClass customerClass = await getCrrentUser(); 87 ViewBag.isAuthenticated = customerClass; 86 88 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 87 89 if (peClass == null) … … 178 180 var vetCenters = await db.VetCentersObj.ToListAsync(); 179 181 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name", peClass.vetcentersid); 180 182 // dodadeno na 22.08 183 ViewBag.isAuthenticated = await getCrrentUser(); 181 184 return View(peClass); 182 185 } … … 196 199 return RedirectToAction("AccessDenied", "Error"); 197 200 } 201 ViewBag.isAuthenticated = await getCrrentUser(); 198 202 199 203 if (ModelState.IsValid) … … 214 218 215 219 // GET: Customer/Delete/5 216 public ActionResultDelete(int? id)220 public async Task<ActionResult> Delete(int? id) 217 221 { 218 222 if (id == null) … … 220 224 return RedirectToAction("NotExist", "Error"); 221 225 } 226 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 227 ViewBag.isAuthenticated = customerClass; 222 228 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 223 229 if (peClass == null) -
PostgreSqlDotnetCore/Controllers/PetsController.cs
rd6040ef r57fc402 45 45 46 46 // GET: Customer/Details/5 47 public ActionResult Details(int? id) 47 /* public ActionResult Details(int? id) 48 { 49 if (id == null) 50 { 51 return RedirectToAction("NotExist", "Error"); 52 } 53 PetsClass peClass = db.PetsObj.Find(id); 54 if (peClass == null) 55 { 56 return RedirectToAction("NotExist", "Error"); 57 } 58 return View(peClass); 59 }*/ 60 61 public async Task<ActionResult> Details(int? id) 48 62 { 49 63 if (id == null) … … 51 65 return RedirectToAction("NotExist", "Error"); 52 66 } 53 PetsClass peClass = db.PetsObj.Find(id); 67 68 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 69 ViewBag.isAuthenticated = customerClass; 70 71 PetsClass peClass = await db.PetsObj.FindAsync(id); 54 72 if (peClass == null) 55 73 { 56 74 return RedirectToAction("NotExist", "Error"); 57 75 } 76 58 77 return View(peClass); 59 78 } … … 110 129 111 130 // GET: Customer/Edit/5 112 public ActionResult Edit(int? id) 131 // public ActionResult Edit(int? id) 132 public async Task<ActionResult> Edit(int? id) 113 133 { 114 134 if (id == null) … … 121 141 return RedirectToAction("NotExist", "Error"); 122 142 } 143 // додадено на 21.08 144 ViewBag.isAuthenticated = await getCrrentUser(); 123 145 return View(peClass); 124 146 } … … 132 154 { 133 155 bool isAuthenticated = User.Identity.IsAuthenticated; 156 ViewBag.isAuthenticated = await getCrrentUser(); 157 134 158 if (!isAuthenticated) 135 159 { … … 140 164 141 165 // set if is authenticated 142 ViewBag.isAuthenticated = new UsersClass(); 166 // додадено и избришено 167 ViewBag.isAuthenticated = await getCrrentUser(); 168 //ViewBag.isAuthenticated = new UsersClass(); 143 169 144 170 … … 158 184 159 185 // GET: Customer/Delete/5 160 public ActionResult Delete(int? id) 186 /* public ActionResult Delete(int? id) 187 { 188 if (id == null) 189 { 190 return RedirectToAction("NotExist", "Error"); 191 } 192 PetsClass peClass = db.PetsObj.Find(id); 193 if (peClass == null) 194 { 195 return RedirectToAction("NotExist", "Error"); 196 } 197 return View(peClass); 198 }*/ 199 200 public async Task<ActionResult> Delete(int? id) 161 201 { 162 202 if (id == null) … … 164 204 return RedirectToAction("NotExist", "Error"); 165 205 } 166 PetsClass peClass = db.PetsObj.Find(id); 206 207 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 208 ViewBag.isAuthenticated = customerClass; 209 210 PetsClass peClass = await db.PetsObj.FindAsync(id); 167 211 if (peClass == null) 168 212 { 169 213 return RedirectToAction("NotExist", "Error"); 170 214 } 215 171 216 return View(peClass); 172 217 } -
PostgreSqlDotnetCore/Controllers/ProductsController.cs
rd6040ef r57fc402 46 46 47 47 // GET: Customer/Details/5 48 public ActionResultDetails(int? id)48 public async Task<ActionResult> Details(int? id) 49 49 { 50 50 if (id == null) … … 52 52 return RedirectToAction("NotExist", "Error"); 53 53 } 54 UsersClass customerClass = await getCrrentUser(); 55 ViewBag.isAuthenticated = customerClass; 54 56 ProductsClass prodClass = db.ProductObj.Find(id); 55 57 if (prodClass == null) -
PostgreSqlDotnetCore/Controllers/VetCenterController.cs
rd6040ef r57fc402 4 4 using PostgreSqlDotnetCore.Models; 5 5 using Microsoft.AspNetCore.Mvc.Rendering; 6 using System.Data; 7 using System.Net; 6 using System.Threading.Tasks; 8 7 9 8 namespace PostgreSqlDotnetCore.Controllers … … 15 14 } 16 15 17 public async Task<ActionResult> Create() 18 { 19 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 20 if (customerClass == null) 21 { 22 return RedirectToAction("AccessDenied", "Error"); 23 } 24 var citiess = await db.CitiesObj.ToListAsync(); 16 public async Task<ActionResult> Create() 17 { 18 // Set if user is authenticated 19 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 20 ViewBag.isAuthenticated = await getCrrentUser(); 21 if (customerClass == null) 22 { 23 return RedirectToAction("AccessDenied", "Error"); 24 } 25 25 26 ViewBag.Citiess = new SelectList(citiess, "id", "name"); 26 // Fetch cities for dropdown 27 var citiess = await db.CitiesObj.ToListAsync(); 28 ViewBag.Citiess = new SelectList(citiess, "id", "name"); 27 29 28 29 30 return View(); 31 } 30 32 31 // GET: Customer 32 /* public ActionResult Index() 33 { 34 return View(db.VetCentersObj.ToList()); 35 }*/ 33 public async Task<ActionResult> Index() 34 { 35 var vetCenters = await db.VetCentersObj.ToListAsync(); 36 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 36 37 37 public ActionResult Index() 38 { 39 var vetCenters = db.VetCentersObj.ToList(); 40 41 // Составување на списокот на ветеринарни центри и проверка на автентикацијата 42 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 38 // Check if the user is an admin 39 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 40 ViewBag.hasAccess = customerClass != null; 43 41 44 42 return View(vetCenters); 45 43 } 46 44 47 48 // GET: Customer/Details/5 49 public ActionResult Details(int? id) 45 public async Task<ActionResult> Details(int? id) 50 46 { 51 47 if (id == null) … … 53 49 return RedirectToAction("NotExist", "Error"); 54 50 } 55 VetCenter vetClass = db.VetCentersObj.Find(id); 51 52 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 56 53 if (vetClass == null) 57 54 { 58 55 return RedirectToAction("NotExist", "Error"); 59 }60 return View(vetClass);61 }62 63 // GET: Customer/Create64 /* public async Task<ActionResult> CreateAsync()65 {66 // check for permission67 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);68 if (customerClass == null)69 {70 return RedirectToAction("AccessDenied", "Error");71 }72 return View();73 }*/74 75 // POST: Customer/Create76 // To protect from overposting attacks, enable the specific properties you want to bind to, for77 // more details see https://go.microsoft.com/fwlink/?LinkId=317598.78 [HttpPost]79 [ValidateAntiForgeryToken]80 81 82 public ActionResult Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)83 {84 if (ModelState.IsValid)85 {86 db.VetCentersObj.Add(vetClass);87 db.SaveChanges();88 return RedirectToAction("Index");89 56 } 90 57 … … 92 59 } 93 60 94 // GET: Customer/Edit/5 95 public async Task<ActionResult> EditAsync(int? id) 61 [HttpPost] 62 [ValidateAntiForgeryToken] 63 public async Task<ActionResult> Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass) 64 { 65 if (ModelState.IsValid) 66 { 67 db.VetCentersObj.Add(vetClass); 68 await db.SaveChangesAsync(); 69 return RedirectToAction("Index"); 70 } 71 72 // If model is invalid, repopulate the cities for dropdown 73 var citiess = await db.CitiesObj.ToListAsync(); 74 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); 75 76 return View(vetClass); 77 } 78 79 public async Task<ActionResult> Edit(int? id) 96 80 { 97 81 if (id == null) … … 99 83 return RedirectToAction("NotExist", "Error"); 100 84 } 101 VetCenter vetClass = db.VetCentersObj.Find(id); 85 86 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 102 87 if (vetClass == null) 103 88 { 104 89 return RedirectToAction("NotExist", "Error"); 105 90 } 106 // check for permission 91 92 // Check for permission 107 93 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 94 //UsersClass customerClass = await checkAuthorizationAsync(); 95 ViewBag.isAuthenticated = await getCrrentUser(); 108 96 if (customerClass == null) 109 97 { 110 98 return RedirectToAction("AccessDenied", "Error"); 111 99 } 100 101 // Fetch cities for dropdown 112 102 var citiess = await db.CitiesObj.ToListAsync(); 113 103 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); 104 114 105 return View(vetClass); 115 106 } 116 107 117 // POST: Customer/Edit/5118 // To protect from overposting attacks, enable the specific properties you want to bind to, for119 // more details see https://go.microsoft.com/fwlink/?LinkId=317598.120 108 [HttpPost] 121 109 [ValidateAntiForgeryToken] 122 /*123 public ActionResult Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)124 {125 if (ModelState.IsValid)126 {127 db.Entry(vetClass).State = EntityState.Modified;128 db.SaveChanges();129 return RedirectToAction("Index");130 }131 return View(vetClass);132 }*/133 134 // POST: VetCenter/Edit/5135 136 110 public async Task<ActionResult> Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass) 137 111 { … … 143 117 } 144 118 119 // If model is invalid, repopulate the cities for dropdown 145 120 var citiess = await db.CitiesObj.ToListAsync(); 146 121 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); … … 149 124 } 150 125 151 152 153 // GET: Customer/Delete/5 154 public ActionResult Delete(int? id) 126 public async Task<ActionResult> Delete(int? id) 155 127 { 156 128 if (id == null) … … 158 130 return RedirectToAction("NotExist", "Error"); 159 131 } 160 VetCenter vetClass = db.VetCentersObj.Find(id); 132 133 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 161 134 if (vetClass == null) 162 135 { 163 136 return RedirectToAction("NotExist", "Error"); 164 137 } 138 165 139 return View(vetClass); 166 140 } 167 141 168 // POST: Customer/Delete/5169 142 [HttpPost, ActionName("Delete")] 170 143 [ValidateAntiForgeryToken] 171 public ActionResultDeleteConfirmed(int id)144 public async Task<ActionResult> DeleteConfirmed(int id) 172 145 { 173 VetCenter vetClass = db.VetCentersObj.Find(id);146 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 174 147 db.VetCentersObj.Remove(vetClass); 175 db.SaveChanges();148 await db.SaveChangesAsync(); 176 149 return RedirectToAction("Index"); 177 150 } … … 186 159 } 187 160 188 189 // GET: VetCenter/Search 190 public ActionResult IndexWithSearch(string searchTerm) 161 public async Task<ActionResult> IndexWithSearch(string searchTerm) 191 162 { 192 163 if (string.IsNullOrEmpty(searchTerm)) 193 164 { 194 var vetCenters = db.VetCentersObj.ToList();165 var vetCenters = await db.VetCentersObj.ToListAsync(); 195 166 return View(vetCenters); 196 167 } 197 168 else 198 169 { 199 var searchResults = db.VetCentersObj.Where(vc => vc.name.Contains(searchTerm)).ToList();170 var searchResults = await db.VetCentersObj.Where(vc => vc.name.Contains(searchTerm)).ToListAsync(); 200 171 return View(searchResults); 201 172 } 202 173 } 203 204 205 206 174 } 207 175 }
Note:
See TracChangeset
for help on using the changeset viewer.