Changeset e90ba32 for PostgreSqlDotnetCore/Controllers
- Timestamp:
- 08/29/24 20:27:21 (3 months ago)
- Branches:
- main
- Children:
- 99d0ecc
- Parents:
- a850333
- Location:
- PostgreSqlDotnetCore/Controllers
- Files:
-
- 3 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 -
PostgreSqlDotnetCore/Controllers/BlogPostAnswersController.cs
ra850333 re90ba32 155 155 public ActionResult Edit([Bind(include: "id,parent_id,reply,root_post,usersID")] BlogPostAnswers answerClass) 156 156 { 157 if (ModelState.IsValid) 158 { 159 db.Entry(answerClass).State = EntityState.Modified; 157 158 BlogPostAnswers answerClassDB = db.BlogPostAnswersObj.Find(answerClass.id); 159 if (answerClassDB != null && !answerClassDB.reply.Equals(answerClass.reply)) 160 { 161 answerClassDB.reply = answerClass.reply; 162 answerClassDB.parent_id = answerClass.parent_id; 163 db.Entry(answerClassDB).State = EntityState.Modified; 160 164 db.SaveChanges(); 161 return RedirectToAction("Index"); 162 } 163 return View(answerClass); 165 //return RedirectToAction("Index"); 166 int id = answerClassDB.BlogPostConsultationid; 167 return RedirectToAction("Details", "Blog", new { id }); 168 } 169 return View(answerClassDB); 164 170 } 165 171 -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
ra850333 re90ba32 57 57 { 58 58 // check for permission 59 bool isAuthenticated = User.Identity.IsAuthenticated; 59 60 UsersClass customerClass = await getCrrentUser(); 60 61 // set if is authenticated … … 75 76 76 77 var userPetCares = 77 await query. ToListAsync<Pet_CaresClass>();78 await query.Include(n => n.PetsClass).ToListAsync<Pet_CaresClass>(); 78 79 79 80 return View(userPetCares); … … 81 82 else 82 83 { 83 return View(db.PetCaresObj. ToList());84 return View(db.PetCaresObj.Include(n => n.PetsClass).ToList()); 84 85 } 85 86 … … 280 281 281 282 // POST: Customer/Delete/5 283 /* [HttpPost, ActionName("Delete")] 284 [ValidateAntiForgeryToken] 285 public ActionResult DeleteConfirmed(int id) 286 { 287 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 288 db.PetCaresObj.Remove(peClass); 289 db.SaveChanges(); 290 return RedirectToAction("Index"); 291 } 292 */ 293 282 294 [HttpPost, ActionName("Delete")] 283 295 [ValidateAntiForgeryToken] 284 public ActionResult DeleteConfirmed(int id) 285 { 286 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 296 public async Task<ActionResult> DeleteConfirmed(int id) 297 { 298 Pet_CaresClass peClass = await db.PetCaresObj.FindAsync(id); 299 if (peClass == null) 300 { 301 return RedirectToAction("NotExist", "Error"); 302 } 287 303 db.PetCaresObj.Remove(peClass); 288 db.SaveChanges();304 await db.SaveChangesAsync(); 289 305 return RedirectToAction("Index"); 290 306 }
Note:
See TracChangeset
for help on using the changeset viewer.