Changeset 118e414 for PostgreSqlDotnetCore/Controllers/BlogController.cs
- Timestamp:
- 08/23/24 15:40:14 (2 months ago)
- Branches:
- main
- Children:
- e9bb9d1
- Parents:
- 72b1da2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
r72b1da2 r118e414 13 13 14 14 { 15 15 16 16 } 17 17 … … 49 49 }*/ 50 50 51 public async Task<ActionResult> Index() 52 { 53 // Проверка за автентикација 54 bool isAuthenticated = User.Identity.IsAuthenticated; 55 56 if (!isAuthenticated) 57 { 58 return RedirectToAction("AccessDenied", "Error"); 59 } 60 61 // Список на блог постови 62 var blogPosts = await db.BlogPostControllerObj.ToListAsync(); 63 64 // Вземи тековниот корисник 65 var currentUser = await _userManager.GetUserAsync(User); 66 var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email); 67 68 // Предавање на ViewBag за проверка на автентикација и корисничкиот ID 69 ViewBag.isAuthenticated = isAuthenticated; 70 ViewBag.CurrentUserId = customerClass?.id; 71 72 return View(blogPosts); 73 } 74 75 76 51 public async Task<ActionResult> Index() 52 { 53 // Проверка за автентикација 54 bool isAuthenticated = User.Identity.IsAuthenticated; 55 56 if (!isAuthenticated) 57 { 58 return RedirectToAction("AccessDenied", "Error"); 59 } 60 61 // Список на блог постови 62 var blogPosts = await db.BlogPostControllerObj.ToListAsync(); 63 64 // Вземи тековниот корисник 65 var currentUser = await _userManager.GetUserAsync(User); 66 var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email); 67 68 // Предавање на ViewBag за проверка на автентикација и корисничкиот ID 69 ViewBag.isAuthenticated = isAuthenticated; 70 // no access for standard user 71 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 72 73 ViewBag.CurrentUserId = customerClass?.id; 74 75 return View(blogPosts); 76 } 77 78 79 77 80 78 81 … … 121 124 // set if is authenticated 122 125 ViewBag.isAuthenticated = customerClass; 126 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 127 123 128 return View(); 124 129 } … … 197 202 } 198 203 } 204 // no access for standard user 205 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 206 199 207 200 208 return View(blogClass); … … 217 225 }*/ 218 226 219 227 220 228 public async Task<ActionResult> EditAsync(int id, [Bind(include: "id,date_askes,title,description")] BlogPostConsultation blogClass) 221 229 { … … 239 247 240 248 // GET: Customer/Delete/5 241 public async Task<ActionResult> DeleteAsync(int? id) { 242 // UsersClass customerClass = await checkAuthorizationAsync(); 243 244 ViewBag.isAuthenticated = await getCrrentUser(); 245 249 public async Task<ActionResult> DeleteAsync(int? id) 250 { 251 // UsersClass customerClass = await checkAuthorizationAsync(); 252 253 ViewBag.isAuthenticated = await getCrrentUser(); 254 246 255 if (id == null) 247 {248 return View(null);249 //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);250 } 251 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id);256 { 257 return View(null); 258 //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 259 } 260 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 252 261 if (blogClass == null) 253 262 { 254 263 return View(null); 255 //return HttpNotFound();264 //return HttpNotFound(); 256 265 } 257 266 // check for permission … … 271 280 } 272 281 } 282 // no access for standard user 283 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 284 273 285 return View(blogClass); 274 286 } 275 287 276 288 // POST: Customer/Delete/5 277 289 278 290 279 291 [HttpPost, ActionName("Delete")]
Note:
See TracChangeset
for help on using the changeset viewer.