public ActionResult EditGet(int id) { var studentParent = Data.Objects.GetStudentParentWStudent(id); var check = Data.Security.CheckForStudent(studentParent.StudentId, SessionItems.CurrentUser.UserId); if (!check.Exists) return View("NotFound"); if (!check.HasAccess) return View("NoAccess"); var model = new EditStudentParentModel { Email = studentParent.Email, FirstName = studentParent.FirstName, LastName = studentParent.LastName, Phone = studentParent.Phone, PreferredContactMethod = studentParent.PreferredContactMethod, Relationship = studentParent.Relationship, StudentFirstName = studentParent.Student.FirstName, StudentId = studentParent.StudentId, StudentLastName = studentParent.Student.LastName, StudentParentId = studentParent.StudentParentId }; return PartialView("_Edit", model); }
public ActionResult CreateGet(int id) { var check = Data.Security.CheckForStudent(id, SessionItems.CurrentUser.UserId); if (!check.Exists) return View("NotFound"); if (!check.HasAccess) return View("NoAccess"); var student = Data.Objects.GetStudent(id); Debug.Assert(student.StudentId != null, "student.StudentId != null"); var model = new EditStudentParentModel {StudentId = student.StudentId.Value, StudentFirstName = student.FirstName, StudentLastName = student.LastName, ShowCancelButton = true }; return PartialView("_Create", model); }
public ActionResult Edit(EditStudentParentModel model) { var check = Data.Security.CheckForStudent(model.StudentId, SessionItems.CurrentUser.UserId); if (!check.Exists) return Json(new Helpers.JsonAjaxResult.result { notFound = true, noAccess = false, errorList = new[] { "" }, success = false }); if (!check.HasAccess) return Json(new Helpers.JsonAjaxResult.result { notFound = false, noAccess = true, errorList = new[] { "" }, success = false }); model.DoValidation(); if (!model.IsValid()) { return Json(new Helpers.JsonAjaxResult.result { errorList = model.ValidationErrors.ToArray(), success = false }); } Data.CRUD.UpdateStudentParent(model, SessionItems.CurrentUser.UserId); return Json(new Helpers.JsonAjaxResult.result { errorList = null, success = true }); }
public static void UpdateStudentParent(EditStudentParentModel model, int userId) { using (var context = DataContext.GetContext()) { var existingItem = context.StudentParents.Single(a => a.StudentParentId == model.StudentParentId); existingItem.LastModifiedOn = DateTime.Now; existingItem.LastModifiedBy = userId; existingItem.Email = model.Email; existingItem.Phone = model.Phone.RemoveNonNumericCharacters(); existingItem.FirstName = model.FirstName; existingItem.LastName = model.LastName; existingItem.StudentId = model.StudentId; existingItem.Relationship = model.Relationship; existingItem.PreferredContactMethod = model.PreferredContactMethod; context.SaveChanges(); } }
public static Entities.StudentParent CreateStudentParent(EditStudentParentModel model, int userId) { using (var context = DataContext.GetContext()) { var result = new Entities.StudentParent { CreatedOn = DateTime.Now, CreatedBy = userId, LastModifiedOn = DateTime.Now, LastModifiedBy = userId, Email = model.Email, Phone = model.Phone.RemoveNonNumericCharacters(), FirstName = model.FirstName, LastName = model.LastName, StudentId = model.StudentId, Relationship = model.Relationship, PreferredContactMethod = model.PreferredContactMethod }; context.StudentParents.AddObject(result); context.SaveChanges(); return result; } }