Ejemplo n.º 1
0
        public ActionResult EditAccount(AccountViewModel acct)
        {
            if (!ModelState.IsValid) {
                return View(acct);
            }

            var dbAcct = ModRepository.GetAccountById(acct.Id);

            if (dbAcct == null) {
                TempData["Message"] = "Conta não encontrada.";
                return RedirectToAction("Index", "Home");
            }

            dbAcct.Name = acct.Name;
            dbAcct.SubdomainName = acct.Subdomain;

            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;
            }

            ModRepository.Save();

            TempData["Message"] = "Dados salvos com sucesso!";
            return RedirectToAction("ListAccounts");
        }
Ejemplo n.º 2
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");
        }