Changeset e90ba32 for PostgreSqlDotnetCore/Controllers/BlogController.cs
- Timestamp:
- 08/29/24 20:27:21 (3 months ago)
- Branches:
- main
- Children:
- 99d0ecc
- Parents:
- a850333
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
ra850333 re90ba32 60 60 61 61 // Список на блог постови 62 var blogPosts = await db.Blog PostControllerObj.ToListAsync();62 var blogPosts = await db.BlogUsers.ToListAsync(); 63 63 64 64 // Вземи тековниот корисник … … 105 105 blogClass.BlogPostAnswers = blogAnswers; 106 106 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 107 ViewBag.CurrentUserId = customerClass?.id; 107 108 return View(blogClass); 108 109 } … … 301 302 // POST: Customer/Delete/5 302 303 304 /* 305 [HttpPost, ActionName("Delete")] 306 [ValidateAntiForgeryToken] 307 public ActionResult DeleteConfirmed(int id) 308 { 309 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 310 db.BlogPostControllerObj.Remove(blogClass); 311 db.SaveChanges(); 312 return RedirectToAction("Index"); 313 } 314 */ 303 315 304 316 [HttpPost, ActionName("Delete")] … … 306 318 public ActionResult DeleteConfirmed(int id) 307 319 { 320 // Наоѓање на објектот по ID 308 321 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 322 323 // Проверка дали објектот е пронајден 324 if (blogClass == null) 325 { 326 // Ако објектот не е пронајден, враќаме 404 Not Found или друга соодветна акција 327 return View(null); 328 } 329 // prvo izbrisi gi site odgovori po sot BlogId e primaren kluc vo drugata tabela 330 331 // query 332 var query = from st in db.BlogPostAnswersObj 333 where st.BlogPostConsultationid == blogClass.id 334 select st; 335 //elenaaa 336 var blogAnswers = query.ToList(); 337 foreach (BlogPostAnswers answerClass in blogAnswers) 338 { 339 db.BlogPostAnswersObj.Remove(answerClass); 340 db.SaveChanges(); 341 342 } 343 344 // Отстранување на објектот ако е пронајден 309 345 db.BlogPostControllerObj.Remove(blogClass); 310 346 db.SaveChanges(); 347 348 // Пренасочување на корисникот кон Index страницата 311 349 return RedirectToAction("Index"); 312 350 } 313 351 314 352 // GET: Customer/Delete/5 315 353 // GET: Customer/Delete/5 316 354 // GET: Customer/Delete/5 317 355 318 356 319 357
Note:
See TracChangeset
for help on using the changeset viewer.