// this class will be frequently referenced // it should be stateless, don't put any fields here // All method in this class is self contained. // Add as many as methods as you wish here. // Don't delete any method here! // // public Boolean addAdminAccount(string email, string password) { using (Youth_Center_DB_Conn db = new Youth_Center_DB_Conn()) { try { var duplicatedAccount = from user in db.ProjectLaucherSets where user.emailAddr == email select user; if (!duplicatedAccount.Any()) { ProjectLaucherSet_AdminSet admin = new ProjectLaucherSet_AdminSet(); admin.ProjectLaucherSet.emailAddr = email; admin.ProjectLaucherSet.role = "Admin"; admin.password = password; db.ProjectLaucherSet_AdminSet.Add(admin); db.SaveChanges(); return true; } else return false; } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); return false; } } }
// // public ActionResult CreateAdmin() { try { string email = Request.Params["email"].Trim(); string password = Request.Params["password"].Trim(); var dupicatedEmail = from ad in db.ProjectLaucherSets where ad.emailAddr == email select ad; if (!dupicatedEmail.Any()) { ProjectLaucherSet laucher = new ProjectLaucherSet(); laucher.emailAddr = email; laucher.role = "Admin"; ProjectLaucherSet_AdminSet admin = new ProjectLaucherSet_AdminSet(); admin.password = password; admin.ProjectLaucherSet = laucher; laucher.ProjectLaucherSet_AdminSet = admin; db.ProjectLaucherSet_AdminSet.Add(admin); db.SaveChanges(); return RedirectToAction("AdminAccountManagement", new { message = "an admin account has been added" }); } } catch (Exception ex) { } return RedirectToAction("AdminAccountManagement"); }