public static Account GetByEmail(string email) { using (DocCommanderEntities db = new DocCommanderEntities()) { return db.Accounts.SingleOrDefault(c => c.Email == email); } }
public static Account Get(string userName) { using (DocCommanderEntities db = new DocCommanderEntities()) { return db.Accounts.SingleOrDefault(c => c.UserName == userName); } }
public ActionResult GetEvent(int eventId) { using (DocCommanderEntities db = new DocCommanderEntities()) { AppEvent ae = db.AppEvents.Find(eventId); return View(ae); } }
public static string GetConfirmationToken(string userName) { using (DocCommanderEntities db = new DocCommanderEntities()) { Account acc = db.Accounts.SingleOrDefault(c => c.UserName == userName); return db.webpages_Membership.SingleOrDefault(x => x.UserId == acc.AccountId).ConfirmationToken; } }
public static List<SelectListItem> GetSelectList(this HtmlHelper html, string listName) { using (DocCommanderEntities db = new DocCommanderEntities()) { var list = db.SysLists.SingleOrDefault(x => x.Name == listName); var res = db.SysListItems.Where(x => x.SysListId == list.SysListId).Select(x => new SelectListItem() { Text = x.Value, Value = x.Value }).ToList(); return res; } }
public static void Disable(string username) { using (DocCommanderEntities db = new DocCommanderEntities()) { Account acc = AccountRepos.Get(username); acc.IsEnabled = false; db.Entry(acc).State = EntityState.Modified; db.SaveChanges(); } }
public static void AddBadLogin(string username) { using (DocCommanderEntities db = new DocCommanderEntities()) { Account acc = AccountRepos.Get(username); acc.NumBadLogins++; db.Entry(acc).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult GetEventsForRecord(int recordId, string tableName) { using (DocCommanderEntities db = new DocCommanderEntities()) { List<AppEvent> result = db.AppEvents.Where(x => x.TableName == tableName && x.RecordId == recordId) .OrderByDescending(x => x.NewRecordVersion) .OrderBy(x => x.EventDate) .ToList(); return View(result); } }
public static string GetDisplayName(int Id) { using (DocCommanderEntities db = new DocCommanderEntities()) { Account acc = db.Accounts.SingleOrDefault(x=>x.AccountId==Id); if (acc != null) { return acc.FirstName + " " + acc.LastName; } return ""; } }
public ActionResult Login(LoginModel model) { using (DocCommanderEntities db = new DocCommanderEntities()) { //Get configured values and get the users this template is for an intranet application. //Note AdminLoginOnlyallowed is commented out as //bool AdminLoginOnlyAllowed = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["AdminLoginOnlyAllowed"]); int maxBadLogins = int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxBadLogins"]); Account acc = AccountRepos.Get(model.UserName); //Trap errors if(acc == null) ModelState.AddModelError("", "Your username or password is not correct."); if (!(bool)acc.IsEnabled) ModelState.AddModelError("", "Your account is not enabled. Please contact your site administrator."); //if(AdminLoginOnlyAllowed && !User.IsInRole("Admin")) //ModelState.AddModelError("", "This website is being maintained. Normal service will resume shortly."); //check details submitted if (ModelState.IsValid) { if (WebSecurity.IsConfirmed(model.UserName)) { if (WebSecurity.Login(acc.UserName, model.Password, persistCookie: model.RememberMe)) { //use the Enable function to reset the numBad Logins to 0; AccountRepos.Enable(acc.UserName); return RedirectToAction("Dashboard", "Account"); } else { ModelState.AddModelError("", "Your username or password is not correct"); AccountRepos.AddBadLogin(model.UserName); RedirectToAction("SendNotifyFailedLoginEmail", "Email", new { username = model.UserName }); if (maxBadLogins > 0 && AccountRepos.GetNumBadLogins(acc.AccountId) > maxBadLogins) { AccountRepos.Disable(acc.UserName); } } } else { ModelState.AddModelError("", "Your account is not activated. Please Check Your email and activate your account."); } } } return View(model); }
public static int GetNumBadLogins(int Id) { using (DocCommanderEntities db = new DocCommanderEntities()) { return db.Accounts.Find(Id).NumBadLogins; } }
public static bool GetIsLDAPAccount(string userName) { using (DocCommanderEntities db = new DocCommanderEntities()) { Account acc = db.Accounts.SingleOrDefault(c => c.UserName == userName); if (acc != null) return acc.IsLDAPAccount; return false; } }
public static List<Account> Search(string term) { using (DocCommanderEntities db = new DocCommanderEntities()) { return db.Accounts .Where(x => x.FirstName.Contains(term) || x.LastName.Contains(term) || x.UserName.Contains(term)) .ToList(); } }