public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,EnrollmentDate")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "Id,Name,Age")] Students students) { if (ModelState.IsValid) { db.Students.Add(students); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(students)); }
public ActionResult Create([Bind(Include = "CourseID,Title,Credits")] Course course) { if (ModelState.IsValid) { db.Courses.Add(course); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult Info() { try { Stream req = Request.Body; string json = new StreamReader(req).ReadToEnd(); w2uiJsonFormPostModel <Group> model = null; try { model = JsonConvert.DeserializeObject <w2uiJsonFormPostModel <Group> >(json); } catch (Exception ex) { return(Json(w2uiBaseModel.Error(ex))); } if (model.cmd == "save-record") { if (!TryValidateModel(model.record, nameof(Student))) { var errors = ModelState .Values .Select(el => el.Errors.Select(m => m.ErrorMessage).FirstOrDefault()) .ToList(); var msg = string.Join(", ", errors); return(Json(w2uiBaseModel.Error(msg))); } ; var record = model.record; var gr = _db.Groups.FirstOrDefault(el => el.Id == record.Id); if (gr == null) { throw new Exception("Не найдена группа"); } gr.Title = record.Title; _db.SaveChanges(); } return(Json(new w2uiBaseModel())); } catch (Exception ex) { return(Json(w2uiBaseModel.Error(ex))); } }
public ActionResult Create(Students student) { if (ModelState.IsValid) { SDB.Student.Add(student); SDB.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(Assignments assignment) { if (ModelState.IsValid) { ADB.Assignment.Add(assignment); ADB.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(Teachers teacher) { if (ModelState.IsValid) { TDB.Teacher.Add(teacher); TDB.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(SchoolApp.Models.Courses course) { if (ModelState.IsValid) { CDB.Course.Add(course); CDB.SaveChanges(); //People.DbPeople.Add(people); } return(RedirectToAction("Index")); }
public ActionResult InsertData() { Student s = new Student(); s.Rno = int.Parse(Request["rno"]); s.Sname = Request["name"]; s.Branch = Request["branch"]; s.Fees = int.Parse(Request["fees"]); db.Students.Add(s); db.SaveChanges(); ViewBag.data = "Data Inserted Successfully"; return(PartialView()); }
public ActionResult Info() { try { Stream req = Request.Body; string json = new StreamReader(req).ReadToEnd(); w2uiJsonFormPostModel <StudentAPI> model = null; try { model = JsonConvert.DeserializeObject <w2uiJsonFormPostModel <StudentAPI> >(json); } catch (Exception ex) { return(Json(w2uiBaseModel.Error(ex))); } if (model.cmd == "save-record") { var record = model.record; //чтобы не записывалась пустая строка if (string.IsNullOrEmpty(record.CallSign)) { record.CallSign = null; } if (!TryValidateModel(record, nameof(Student))) { var errors = ModelState .Values .Select(el => el.Errors.Select(m => m.ErrorMessage).FirstOrDefault()) .ToList(); var msg = string.Join(", ", errors); return(Json(w2uiBaseModel.Error(msg))); } ; var st = _db.Students.FirstOrDefault(el => el.Id == record.Id); if (st == null) { throw new Exception("Не найден student"); } var oldGroupList = _db .UserInGroups .Where(el => el.UserId == st.Id) .Select(el => el.GroupId) .ToList(); var newGroupList = record.Groups.Select(el => el.id).ToList(); //на добавление var forAddIds = newGroupList.Except(oldGroupList).ToList(); var forAdd = forAddIds.Select( el => new UserInGroup { GroupId = el, UserId = record.Id }) .ToList(); //на удаление var forDelIds = oldGroupList.Except(newGroupList).ToList(); var forDel = _db.UserInGroups.Where(el => forDelIds.Contains(el.GroupId)); st.FirstName = record.FirstName; st.GenderId = record.GenderId; st.LastName = record.LastName; st.SecondName = record.SecondName; st.CallSign = record.CallSign; _db.SaveChanges(); _db.UserInGroups.AddRange(forAdd); _db.UserInGroups.RemoveRange(forDel); _db.SaveChanges(); } return(Json(new w2uiBaseModel())); } catch (Exception ex) { return(Json(w2uiBaseModel.Error(ex))); } }