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);
        }
Exemple #2
0
		private void detach_Accounts(Account entity)
		{
			this.SendPropertyChanging();
			entity.Status = null;
		}
Exemple #3
0
		private void attach_Accounts(Account entity)
		{
			this.SendPropertyChanging();
			entity.Status = this;
		}
Exemple #4
0
 partial void DeleteAccount(Account instance);
Exemple #5
0
 partial void UpdateAccount(Account instance);
Exemple #6
0
 partial void InsertAccount(Account instance);