Ignore:
Timestamp:
08/29/24 20:27:21 (4 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
99d0ecc
Parents:
a850333
Message:

fix issues

fix bugs with nested tables
fix delete nested fk items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/BlogController.cs

    ra850333 re90ba32  
    6060
    6161            // Список на блог постови
    62             var blogPosts = await db.BlogPostControllerObj.ToListAsync();
     62            var blogPosts = await db.BlogUsers.ToListAsync();
    6363
    6464            // Вземи тековниот корисник
     
    105105            blogClass.BlogPostAnswers = blogAnswers;
    106106            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     107            ViewBag.CurrentUserId = customerClass?.id;
    107108            return View(blogClass);
    108109        }
     
    301302        // POST: Customer/Delete/5
    302303
     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                */
    303315
    304316        [HttpPost, ActionName("Delete")]
     
    306318        public ActionResult DeleteConfirmed(int id)
    307319        {
     320            // Наоѓање на објектот по ID
    308321            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            // Отстранување на објектот ако е пронајден
    309345            db.BlogPostControllerObj.Remove(blogClass);
    310346            db.SaveChanges();
     347
     348            // Пренасочување на корисникот кон Index страницата
    311349            return RedirectToAction("Index");
    312350        }
    313        
     351
    314352        // GET: Customer/Delete/5
    315353        // GET: Customer/Delete/5
    316354        // GET: Customer/Delete/5
    317    
     355
    318356
    319357
Note: See TracChangeset for help on using the changeset viewer.