public void UpdateSchoolEntity(SchoolEdit model, School entity) { entity.SchoolName = model.SchoolName; entity.Address.StreetAddress = model.StreetAddress; entity.Address.City = model.City; entity.Address.State = model.State; entity.Address.ZipCode = model.ZipCode; entity.HighestGrade = model.HighestGradeLevel; entity.LowestGrade = model.LowestGradeLevel; }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } SchoolEdit = await SchoolEdit.SaveAsync(true); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } SchoolEdit = await DataPortal.FetchAsync <SchoolEdit>(id); if (SchoolEdit == null) { return(NotFound()); } return(Page()); }
public ActionResult Edit(int id) { var service = CreateSchoolService(); var detail = service.GetSchoolById(id); var model = new SchoolEdit { SchoolId = detail.SchoolId, SchoolName = detail.SchoolName, City = detail.City, State = detail.State, }; return(View(model)); }
//____________________________________________UPDATE public bool UpdateSchool(SchoolEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Schools.Find(model.SchoolId); if (entity != null) { _schoolHelper.UpdateSchoolEntity(model, entity); return(ctx.SaveChanges() == 1); } else { return(false); } } }
public bool UpdateSchool(SchoolEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Schools .Single(e => e.SchoolId == model.SchoolId); entity.SchoolId = model.SchoolId; entity.SchoolName = model.SchoolName; entity.City = model.City; entity.State = model.State; entity.Region = model.Region; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, SchoolEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SchoolId != id) { ModelState.AddModelError("", "this id does not match a school please enter the correct one"); return(View(model)); } var service = CreateSchoolService(); if (service.UpdateSchool(model)) { TempData["save result"] = "your school was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "school can not be updated"); return(View(model)); }
public ActionResult EditSchool(SchoolEdit model) { if (this.ModelState.IsValid) { var service = CreateSchoolService(); if (service.UpdateSchool(model)) { return(RedirectToAction("Detail", "EditProfile", new { id = this.User.Identity.GetUserId() })); } else { TempData["ErrorMessage"] = "School could not be updated. Try again."; return(RedirectToAction("Detail", new { id = model.TeacherId })); } } else { TempData["ErrorMessage"] = "School could not be updated. Try again."; return(RedirectToAction("Detail", new { id = model.TeacherId })); } }
public ActionResult Edit(int id, SchoolEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SchoolID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateSchoolService(); if (service.UpdateSchool(model)) { TempData["SaveResult"] = "The school was successfully updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The school could not be updated."); return(View(model)); }
public bool EditSchool(AdminSchoolViewModel vm_school) { if (vm_school == null) { return(false); } try { using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); //Validate input if (mapper == null) { return(false); } School school = (School)mapper.Map((AdminSchoolViewModel)vm_school, typeof(School)); //Validate input if (school == null) { return(false); } //Create the project edit and populate necessary attributes SchoolEdit edit = new SchoolEdit(); edit.SchoolID = school.SchoolID; edit.Username = school.Username; edit.SchoolName = school.SchoolName; edit.Phone = (int)school.Phone; edit.Email = school.Email; edit.ContactEmail = school.ContactEmail; edit.ContactName = school.ContactName; edit.ContactPhone = school.ContactPhone; edit.Department = school.Department; edit.Class = school.Class; edit.StreetNumber = school.StreetNumber; edit.StreetName = school.StreetName; edit.ZipCode = school.ZipCode; edit.City = school.City; edit.State = school.State; edit.EditDate = DateTime.Now; context.SchoolEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } } catch { //There was an error during school edit return(false); } }