public void CreateStudySubject(NewStudySubjectViewModel model) { using (var db = new ErasmusDbContext()) { db.StudySubjects.Add(new StudySubjects() { Credits = model.Credits, Evaluation = model.Evaluation, Language = model.Language, Name = model.Name, Semester = model.Semester }); db.SaveChanges(); } }
public ActionResult NewStudySubject(NewStudySubjectViewModel model) { try { if (ModelState.IsValid) { _adminBusinessLogic.CreateStudySubject(model); ViewData.Add("LastActionResult", "Study subject created"); return(RedirectToActionPermanent("StudySubjects")); } return(View(model)); } catch (Exception e) { return(Json(new { result = "ERROR", message = e.Message }, JsonRequestBehavior.AllowGet)); } }
internal object GetNewStudySubjectViewModel(int?uniId, int id) { var model = new NewStudySubjectViewModel(); using (var db = new ErasmusDbContext()) { var sub = db.StudySubjects.SingleOrDefault(x => x.Id == id && x.UniversityId == uniId); if (sub == null) { throw new FormValidationException("Invalid subject"); } model.Id = sub.Id; model.Credits = sub.Credits; model.Evaluation = sub.Evaluation; model.Language = sub.Language; model.Name = sub.Name; model.Semester = sub.Semester; } return(model); }
internal void CreateStudySubject(NewStudySubjectViewModel model, int?uniId) { using (var db = new ErasmusDbContext()) { if (model.Id != null) { //Edit var sub = db.StudySubjects.SingleOrDefault(x => x.Id == model.Id && x.UniversityId == uniId); if (sub == null) { throw new FormValidationException("Invalid subject"); } sub.Credits = model.Credits; sub.Evaluation = model.Evaluation; sub.Language = model.Language; sub.Name = model.Name; sub.Semester = model.Semester; db.SaveChanges(); } else { //New db.StudySubjects.Add(new StudySubjects() { Credits = model.Credits, Evaluation = model.Evaluation, Language = model.Language, Name = model.Name, Semester = model.Semester, UniversityId = uniId }); db.SaveChanges(); } } }
internal object GetNewStudySubjectViewModel(int?uniId) { var model = new NewStudySubjectViewModel(); return(model); }
public NewStudySubjectViewModel GetNewStudySubjectViewModel() { var model = new NewStudySubjectViewModel(); return(model); }