Esempio n. 1
0
        public ActionResult Create(ViewModels model)
        {
            Generate();
            if (!ModelState.IsValid) return View(model);
            // Attempt to register the user
            try
            {
                if (_manager.ConfirmEmail(model.Email) != 0 || WebSecurity.UserExists(model.UserName))
                {
                    TempData["status"] = "Error";
                    return View(model);
                }

                WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                model.UserId = WebSecurity.GetUserId(model.UserName);
                model.AdminId = WebSecurity.GetUserId(User.Identity.Name);
                _manager.CreateClient(model, "create");
                Roles.AddUserToRole(model.UserName, "Clients");
                Helper.Helper.SendMail(model, "ClientCreated");
                TempData["status"] = "Success";
                return View(model);
            }
            catch (MembershipCreateUserException e)
            {
                //ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 2
0
        public int CreateClient(ViewModels user, string type)
        {
            var x = _db.UserProfiles.Find(user.UserId);
            x.FirstName = user.FirstName;
            x.LastName = user.LastName;
            x.Email = user.Email;
            x.Phone = user.Phone;
            x.DateCreated = type == "create" ? DateTime.Now : x.DateCreated;
            x.DateModified = type == "edit" ? DateTime.Now : x.DateModified;
            x.ClientId = user.ClientId;
            x.DseId = user.DseId;
            x.CompanyId = user.CompanyId;
            x.AdminId = user.AdminId;

            _db.SaveChanges();
            return 0;
        }