public async Task <ActionResult> Create(SchoolVm model) { if (ModelState.IsValid) { var school = new School { SchoolId = model.SchoolId, Name = model.Name, Alias = model.Alias, Address = model.Address, LocalGovtArea = model.LocalGovtArea.ToString(), Color = model.Color.ToString(), OwernshipType = model.OwernshipType.ToString(), DateOfEstablishment = model.DateOfEstablishment, Logo = model.Logo, SchoolBanner = model.SchoolBanner }; Db.Schools.Add(school); await Db.SaveChangesAsync(); //return RedirectToAction("Index"); return(new JsonResult { Data = new { status = true, message = "School Created Successfully" } }); } return(new JsonResult { Data = new { status = false, message = "Check your inputs and try again" } }); }
// GET: Schools/Edit/5 public async Task <ActionResult> Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var model = await Db.Schools.FindAsync(id); if (model == null) { return(HttpNotFound()); } var school = new SchoolVm() { SchoolId = model.SchoolId, Name = model.Name, Alias = model.Alias, Address = model.Address, DateOfEstablishment = model.DateOfEstablishment, //Color = model.Color.ToString(), Logo = model.Logo, SchoolBanner = model.SchoolBanner }; return(View(school)); }
public async Task <ActionResult> Edit(SchoolVm model) { if (ModelState.IsValid) { var school = new School { SchoolId = model.SchoolId, Name = model.Name, Alias = model.Alias, Address = model.Address, LocalGovtArea = model.LocalGovtArea.ToString(), Color = model.Color.ToString(), OwernshipType = model.OwernshipType.ToString(), DateOfEstablishment = model.DateOfEstablishment, Logo = model.Logo, SchoolBanner = model.SchoolBanner }; Db.Entry(school).State = EntityState.Modified; await Db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }