Esempio n. 1
0
        public ActionResult CreateAccount(AccountViewModel acct, string userName, string email, string password, string confirmPassword)
        {
            if (!ModelState.IsValid)
            {
                return(View(acct));
            }

            var dbAcct = new Account {
                Name          = acct.Name,
                SubdomainName = acct.Subdomain,
                Plan          = ModRepository.GetPlanByName("Unlimited")
            };

            if (Request.Files.Count > 0 &&
                Request.Files[0].ContentLength > 0)
            {
                var user    = Membership.GetUser() as UACUser;
                var imgInfo = user.SaveImage(Request.Files[0]);
                dbAcct.Logo = imgInfo.FullRelativePath;
            }

            if (!CreateNewUser(userName, email, password, confirmPassword))
            {
                return(View(acct));
            }

            var createdUser = ModRepository.GetUserByName(userName);

            dbAcct.Users.Add(createdUser);

            ModRepository.AddAccount(dbAcct);
            ModRepository.Save();

            TempData["Message"] = "Conta criada com sucesso!";
            return(RedirectToAction("ListAccounts"));
        }