public Address BuildAddress(SchoolCreate model) { var address = new Address(); address.StreetAddress = model.StreetAddress; address.City = model.City; address.State = model.State; address.ZipCode = model.ZipCode; return(address); }
public School BuildSchoolEntity(SchoolCreate model) { var entity = new School(); entity.SchoolName = model.SchoolName; entity.Address = _addressHelper.BuildAddress(model); entity.LowestGrade = model.LowestGradeLevel; entity.HighestGrade = model.HighestGradeLevel; entity.TeacherId = model.TeacherId; return(entity); }
// CREATE public bool CreateSchool(SchoolCreate model) { var entity = new School() { SchoolName = model.SchoolName, City = model.City, State = model.State }; using (var ctx = new ApplicationDbContext()) { ctx.Schools.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(SchoolCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateSchoolService(); if (service.CreateSchool(model)) { TempData["SaveResult"] = "This school was added successfully, good luck on your journey"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "There was an issue with this school"); return(View(model)); }
//____________________________________________CREATE public bool AddSchoolToTeacher(SchoolCreate model) { using (var ctx = new ApplicationDbContext()) { var teacher = ctx.Teachers.Find(_currentUser); if (teacher != null) { model.TeacherId = _currentUser; var entity = _schoolHelper.BuildSchoolEntity(model); teacher.Schools.Add(entity); return(ctx.SaveChanges() == 2); } else { return(false); } } }
public ActionResult AddSchool(SchoolCreate model) { if (this.ModelState.IsValid) { var service = CreateSchoolService(); if (service.AddSchoolToTeacher(model)) { TempData["SaveResult"] = "School was successfully removed."; return(RedirectToAction("Detail", "EditProfile", new { id = this.User.Identity.GetUserId() })); } else { TempData["ErrorMessage"] = "School could not be added. Try again."; return(RedirectToAction("Detail", new { id = model.TeacherId })); } } else { TempData["ErrorMessage"] = "School could not be added. Try again."; return(RedirectToAction("Detail", new { id = model.TeacherId })); } }