public ActionResult Add(Account acc, string[] secRoles, string newPassword) { if (secRoles != null) { foreach (string s in secRoles) { Role r = new Role() { SecurityRole = (SecurityRole)Enum.Parse(typeof(SecurityRole), s) }; acc.Roles.Add(r); } } if (ModelState.IsValid) { if (!string.IsNullOrEmpty(newPassword)) { if (WebIT.Lib.Utils.Validate.PasswordFormat(newPassword)) { acc.Password = Security.Password.GenerateHash(acc.Email, newPassword); } else { ModelState.AddModelError("acc.Password", "Password format is not valid. Expecting 6+ characters(1 upper & 1 lower alpha, 1 numeric)"); } if (ModelState.IsValid) { DBDataContext db = Utils.DB.GetContext(); if (db.Accounts.Count(x => x.Email.Equals(acc.Email)) > 0) { ModelState.AddModelError("acc.Email", "Email address is already in use. Please choose another one."); } else { db.Accounts.InsertOnSubmit(acc); try { acc.Registered = DateTime.Now; acc.StatusID = db.Status.Single(x => x.Value.Equals("Active")).ID; db.SubmitChanges(); return RedirectToAction("Index", "Account"); } catch(Exception ex) { ModelState.AddModelError("", "An unknown error occurred. Please try again in few minutes."); ErrorHandler.Report.Exception(ex, "Account/Add"); } } } } else { ModelState.AddModelError("Password", "Password is required"); } } ViewData["Title"] = "Add Account"; ViewData["Action"] = "Add"; return View("Manage", acc); }
private void detach_Accounts(Account entity) { this.SendPropertyChanging(); entity.Status = null; }
private void attach_Accounts(Account entity) { this.SendPropertyChanging(); entity.Status = this; }
partial void DeleteAccount(Account instance);
partial void UpdateAccount(Account instance);
partial void InsertAccount(Account instance);