示例#1
0
        public ActionResult deleteUser(string id)
        {
            DBEnt db = new DBEnt();

            var user = db.AspNetUsers.Where(x => x.Id == id).FirstOrDefault();
            List <AspNetRole> roles = user.AspNetRoles.ToList();

            try
            {
                if (roles.FirstOrDefault().Name == "Admin")
                {
                    return(Content("Admin cannot be deleted!"));
                }
                if (roles.FirstOrDefault().Name != "Admin")
                {
                    db.Entry(user).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    Alerts.deleteUser = true;
                    return(RedirectToAction("allUsers", "Admin"));
                }
            }
            catch
            {
                db.Entry(user).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
                Alerts.deleteUser = true;
                return(RedirectToAction("allUsers", "Admin"));
            }

            return(Content("Error........"));
        }
示例#2
0
        public ActionResult deleteChapter(int?id)
        {
            DBEnt      db  = new DBEnt();
            List <Mcq> mcq = db.Mcqs.Where(x => x.ChapterId == id).ToList <Mcq>();

            foreach (Mcq i in mcq)
            {
                db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
            }
            db.SaveChanges();
            Chapter chapter = db.Chapters.Where(x => x.Id == id).First();

            db.Entry(chapter).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            Alerts.deleteChapter = true;
            return(RedirectToAction("addChapter", "Admin"));
        }
示例#3
0
        public ActionResult deleteMessage(int?id)
        {
            DBEnt db      = new DBEnt();
            var   message = db.Messages.Where(x => x.Id == id).First();

            db.Entry(message).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            Alerts.deleteMessage = true;
            return(RedirectToAction("viewMessagaes", "Admin"));
        }
示例#4
0
        public ActionResult deleteMcq(int id)
        {
            DBEnt db = new DBEnt();

            List <Submission> submissions = db.Submissions.Where(x => x.McqId == id).ToList <Submission>();

            foreach (Submission i in submissions)
            {
                db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
            }
            db.SaveChanges();

            Mcq mcq = db.Mcqs.Where(x => x.Id == id).First();

            db.Entry(mcq).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            Alerts.deleteMcq = true;
            return(RedirectToAction("allMcq", "Admin"));
        }
示例#5
0
        public ActionResult deleteExam(int?id)
        {
            DBEnt db   = new DBEnt();
            var   mcqs = db.Mcqs.Where(x => x.ExamId == id).ToList <Mcq>();

            foreach (var i in mcqs)
            {
                db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
                var sub = db.Submissions.Where(x => x.McqId == i.Id).FirstOrDefault();
                db.Entry(sub).State = System.Data.Entity.EntityState.Deleted;
            }
            db.SaveChanges();
            var exam = db.Exams.Where(x => x.Id == id).First();

            db.Entry(exam).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            Alerts.deleteExam = true;
            return(RedirectToAction("AddExam", "Admin"));
        }
示例#6
0
        public ActionResult deleteSubject(int?id)
        {
            DBEnt   db      = new DBEnt();
            Subject subject = db.Subjects.Where(x => x.Id == id).First();

            List <Mcq> mcq = db.Mcqs.Where(x => x.SubjectId == subject.Id).ToList <Mcq>();

            foreach (Mcq i in mcq)
            {
                db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
            }

            List <Chapter> chapters = db.Chapters.Where(x => x.SubjectId == subject.Id).ToList <Chapter>();

            foreach (Chapter i in chapters)
            {
                db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
            }
            db.Entry(subject).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            Alerts.deleteSubject = true;
            return(RedirectToAction("addSubject", "Admin"));
        }