Пример #1
0
        public ActionResult AddOrEdit([Bind(Include = "GradeId,Grade1,TeacherId,StudentId")] Grade grd)
        {
            using (AjaxCRUD_DBEntities db = new AjaxCRUD_DBEntities())
            {
                if (grd.GradeId == 0 && ModelState.IsValid)
                {
                    db.Grades.Add(grd);
                    db.SaveChanges();
                }
                else if (grd.GradeId != 0 && ModelState.IsValid)
                {
                    db.Entry(grd).State = EntityState.Modified;
                    db.SaveChanges();
                }
                ViewBag.StudentId = new SelectList(db.Students, "StudentId", "Name", "LastName");
                ViewBag.TeacherId = new SelectList(db.Teachers, "TeacherId", "FirstName", "LastName");
            }

            return(Json(new
            {
                success = true,
                html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllGrades()),
                message = "Submitted Successfully."
            }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult AddOrEdit([Bind(Include = "StudentId,FirstName,LastName,Age,UniversityId")] Student std)
        {
            using (AjaxCRUD_DBEntities db = new AjaxCRUD_DBEntities())
            {
                if (std.StudentId == 0 && ModelState.IsValid)
                {
                    db.Students.Add(std);
                    db.SaveChanges();
                }
                else if (std.StudentId != 0 && ModelState.IsValid)
                {
                    db.Entry(std).State = EntityState.Modified;
                    db.SaveChanges();
                }
                ViewBag.StudentId = new SelectList(db.Universities, "UniversityId", "Name");
            }

            return(Json(new
            {
                success = true,
                html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllStudents()),
                message = "Submitted Successfully."
            }, JsonRequestBehavior.AllowGet));
        }