public ActionResult Create(School school) { try { using (var context = new Context()) { context.Schools.Add(school); context.SaveChanges(); var account = new Account() { LoginName = "school" + school.Id.ToString() + "admin", Password = "******", SchoolId = school.Id, Role = (int) Role.Admin, DisplayName = school.Name + " admin" }; context.Accounts.Add(account); context.SaveChanges(); TempData["message"] = "New admin account: " + account.LoginName + " " + account.Password; } return RedirectToAction("Index"); } catch { return View(); } }
/// <summary> /// Create a new organization or update an existing one. /// This method will never be called if the organization.Id is null (for example, if the attribute /// has not been requested from RM Unify). /// If your app stores information about an organization, it should use organization.Id as a key to create a /// new organization record or update an existing one. /// </summary> /// <param name="org">Organization profile</param> /// <param name="source">Source of update (sign on or provisioning)</param> public override void CreateOrUpdateOrganization(RmUnifyOrganization org, Source source) { using (var context = new Context()) { School school = (from s in context.Schools where s.RmUnifyId == org.Id select s).SingleOrDefault(); if (school == null) { school = new School() { RmUnifyId = org.Id }; context.Schools.Add(school); } school.Name = org.Name; school.DfeCode = org.Code; school.PostCode = "N/A"; school.IsRmUnifySchool = true; context.SaveChanges(); // Cache school for next method _school = school; } }
public ActionResult Delete(int id, School school) { if (id != 0) { using (var context = new Context()) { var accounts = (from a in context.Accounts where a.SchoolId == id select a); foreach (var account in accounts) { context.Accounts.Remove(account); } var posts = (from p in context.Posts where p.Account.SchoolId == id select p); foreach (var post in posts) { context.Posts.Remove(post); } var sch = (from s in context.Schools where s.Id == id select s).FirstOrDefault(); if (sch != null) { context.Schools.Remove(sch); } context.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult Edit(int id, School school) { using (var context = new Context()) { var sch = (from s in context.Schools where s.Id == id select s).FirstOrDefault(); if (sch == null) { return new HttpNotFoundResult(); } sch.Name = school.Name; sch.PostCode = school.PostCode; sch.DfeCode = school.DfeCode; sch.Licenced = school.Licenced; context.SaveChanges(); } return RedirectToAction("Index"); }