Esempio n. 1
0
        public IActionResult Edit(int id)
        {
            var testBase = context.Tests.AsNoTracking().First(a => a.Id == id & !a.IsDel);
            var obg      = new TestUpdatedViewModel
            {
                Test      = testBase,
                Questions = context.Questions.AsNoTracking().Where(a => a.TestId == id & !a.IsDel).ToList(),
                ImgDel    = "/img/Delete.jpg",
                ImgEdit   = "/img/Edit.jpg"
            };

            return(View(obg));
        }
Esempio n. 2
0
        public IActionResult Edit(int id, TestUpdatedViewModel testModel)
        {
            if (testModel.Test.Id == 0)
            {
                context.Tests.Add(testModel.Test);
                context.SaveChanges();
                return(RedirectToAction("Admin", "Admin"));
            }

            context.Update(testModel.Test);
            context.SaveChanges();


            testModel.Test      = context.Tests.AsNoTracking().FirstOrDefault(a => a.Id == testModel.Test.Id & !a.IsDel);
            testModel.Questions = context.Questions.AsNoTracking()
                                  .Where(a => a.TestId == testModel.Test.Id & !a.IsDel).ToList();
            testModel.ImgDel  = "/img/Delete.jpg";
            testModel.ImgEdit = "/img/Edit.jpg";
            return(View(testModel));
        }