Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ExamPortionID,ExamID,ChapterID,TopicID")] ExamPortion examportion)
        {
            errordata data = new errordata();

            data.type      = "error";
            Session["err"] = "Error, Please Check Input Fields";
            Session["msg"] = "";
            if (ModelState.IsValid)
            {
                ExamPortion exist = db.ExamPortions.Where(s => s.TopicID == examportion.TopicID).FirstOrDefault();
                if (exist != null)
                {
                    Session["err"] = "Topic already exists";
                    data.message   = Session["err"].ToString();
                    return(Json(data, JsonRequestBehavior.AllowGet));
                }
                db.ExamPortions.Add(examportion);
                db.SaveChanges();

                ModelState.Clear();

                Session["err"] = "";
                Session["msg"] = "Created Successfully";
            }
            data.message = Session["msg"].ToString();
            data.type    = "success";
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirm(int id)
        {
            Session["err"] = "Error, Can't Delete, Please check Dependency Data";
            Session["msg"] = "";
            try
            {
                ExamPortion examPortion = db.ExamPortions.Find(id);
                db.ExamPortions.Remove(examPortion);
                db.SaveChanges();

                Session["err"] = "";
                Session["msg"] = "Deleted Successfully";
            }
            catch { }
            return(RedirectToAction("Index", "Exam"));
        }
Ejemplo n.º 3
0
        // GET: /ExamPortion/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExamPortion examPortion = db.ExamPortions.Find(id);
            Exam        exam        = db.Exams.Find(examPortion.ExamID);

            if (examPortion == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Existing  = examPortion.TopicID;
            ViewBag.ChapterID = new SelectList(db.Chapters.Include(e => e.CurrentSubject).Where(e => e.CurrentSubject.SubjectID == exam.SubjectID), "ChapterID", "Name", examPortion.ChapterID);
            ViewBag.TopicID   = new SelectList(db.Topics, "TopicID", "Name", examPortion.TopicID);
            return(View(examPortion));
        }
Ejemplo n.º 4
0
        public ActionResult Create(int id)
        {
            Exam        exam        = db.Exams.Find(id);
            ExamPortion examPortion = new ExamPortion();

            examPortion.ExamID = id;
            IEnumerable <SelectListItem> subjectlist = (from p in db.Chapters.Include(s => s.CurrentSubject).Include(s => s.CurrentSubject.CurrentClass).Where(e => e.CurrentSubject.SubjectID == exam.SubjectID).OrderBy(s => s.CurrentSubject.Name).OrderBy(s => s.CurrentSubject.CurrentClass.Name) select p).AsEnumerable().Select(p => new SelectListItem()
            {
                Text = p.Name + " : " + p.CurrentSubject.Name + " : " + p.CurrentSubject.CurrentClass.Name, Value = p.ChapterID.ToString()
            });

            ViewBag.ChapterID = new SelectList(subjectlist, "Value", "Text");
            ViewBag.TopicID   = new SelectList(db.Topics, "TopicID", "Name");

            ViewBag.Message = Session["msg"];
            ViewBag.Error   = Session["err"];
            Session["err"]  = "";
            Session["msg"]  = "";
            return(View(examPortion));
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "ExamPortionID,ExamID,ChapterID,TopicID")] ExamPortion examPortion, string existing)
        {
            Session["err"] = "Error, Please Check Input Fields";
            Session["msg"] = "";
            if (ModelState.IsValid)
            {
                if (Convert.ToString(examPortion.TopicID) != existing)
                {
                    ExamPortion examPortionexisting = db.ExamPortions.Where(s => s.TopicID == examPortion.TopicID).FirstOrDefault();
                    if (examPortionexisting != null)
                    {
                        Session["err"] = "Topic already exists";

                        ViewBag.Existing = existing;
                        Exam exam = db.Exams.Find(examPortion.ExamID);
                        ViewBag.ChapterID = new SelectList(db.Chapters.Include(e => e.CurrentSubject).Where(e => e.CurrentSubject.SubjectID == exam.SubjectID), "ChapterID", "Name", examPortion.ChapterID);
                        ViewBag.TopicID   = new SelectList(db.Topics, "TopicID", "Name", examPortion.TopicID);

                        ViewBag.Message = Session["msg"];
                        ViewBag.Error   = Session["err"];
                        Session["err"]  = "";
                        Session["msg"]  = "";
                        return(View(examPortion));
                    }
                }

                db.Entry(examPortion).State = EntityState.Modified;
                db.SaveChanges();

                Session["err"] = "";
                Session["msg"] = "Modified Successfully";

                return(RedirectToAction("Index", "Exam"));
            }
            ViewBag.Existing = existing;
            ViewBag.Message  = Session["msg"];
            ViewBag.Error    = Session["err"];
            Session["err"]   = "";
            Session["msg"]   = "";
            return(View(examPortion));
        }