Ejemplo n.º 1
0
        public ActionResult Create(CreateAccountModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //If there are no UserRoles in the Roles table shit breaks, Add them if not present
                    UserRoleService URS = new UserRoleService();
                    if (URS.GetCount() == 0)
                    {
                        UserRole UR = new UserRole();
                        UR.Name = "Administrator";
                        URS.Save(UR);
                        UR      = new UserRole();
                        UR.Name = "User";
                        URS.Save(UR);
                    }


                    //Armor.Data.User user = Mapper.Map<CreateAccountModel, Armor.Data.User>(model);
                    User Newuser = new User();

                    Newuser.Address            = model.Address;
                    Newuser.City               = model.City;
                    Newuser.CreatedDate        = DateTime.UtcNow;
                    Newuser.EmailAddress       = model.EmailAddress;
                    Newuser.FaxNumber          = model.Fax;
                    Newuser.FirstName          = model.FirstName;
                    Newuser.ForgotPasswordHash = new Guid();
                    Newuser.GSTInformation     = model.GSTInformation;
                    Newuser.IsActive           = true;
                    Newuser.LastName           = model.LastName;
                    Newuser.Password           = PasswordHelpers.EncryptPassword(model.Password);
                    Newuser.PhoneNumber        = model.Phone;
                    Newuser.PostalCode         = model.PostalCode;
                    Newuser.Province           = model.Province;
                    Newuser.RoleID             = URS.GetByRoleName("User").ID;

                    service.Save(Newuser);


                    // build a message to send to the user.
                    //string validateUrl = string.Format("{0}account/validate/{1}", App.BaseUrl, Helpers.base64Encode(user.EmailAddress));

                    //TemplateParser parser = new TemplateParser();
                    //Dictionary<string, string> replacements = new Dictionary<string, string>();
                    //replacements.Add("[BASE_URL]", App.BaseUrl);
                    //replacements.Add("[FIRST_NAME]", user.EmailAddress);
                    //replacements.Add("[VALIDATE_ACCOUNT_URL]", validateUrl);

                    //string message = parser.Replace(AccountEmails.ValidateAccount, replacements);

                    //EmailSender sender = new EmailSender();
                    //sender.Send(App.MailConfiguration, model.EmailAddress, "", "Thank you for registering on epilogger.com", message);

                    //this.StoreSuccess("Your account was created successfully<br /><br/>Please check your inbox for our validation message, your account will be inaccessable until you validate it.");

                    return(RedirectToAction("login", "account"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ViewRes.SharedString.CreateAccountProblem + " - " + ex.Message.ToString());
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(CreateAccountModel model)
        {
            if (ModelState.IsValid)
            {

                try
                {
                    //If there are no UserRoles in the Roles table shit breaks, Add them if not present
                    UserRoleService URS = new UserRoleService();
                    if (URS.GetCount() == 0)
                    {
                        UserRole UR = new UserRole();
                        UR.Name = "Administrator";
                        URS.Save(UR);
                        UR = new UserRole();
                        UR.Name = "User";
                        URS.Save(UR);
                    }

                    //Armor.Data.User user = Mapper.Map<CreateAccountModel, Armor.Data.User>(model);
                    User Newuser = new User();

                    Newuser.Address = model.Address;
                    Newuser.City = model.City;
                    Newuser.CreatedDate = DateTime.UtcNow;
                    Newuser.EmailAddress = model.EmailAddress;
                    Newuser.FaxNumber = model.Fax;
                    Newuser.FirstName = model.FirstName;
                    Newuser.ForgotPasswordHash = new Guid();
                    Newuser.GSTInformation = model.GSTInformation;
                    Newuser.IsActive = true;
                    Newuser.LastName = model.LastName;
                    Newuser.Password = PasswordHelpers.EncryptPassword(model.Password);
                    Newuser.PhoneNumber = model.Phone;
                    Newuser.PostalCode = model.PostalCode;
                    Newuser.Province = model.Province;
                    Newuser.RoleID = URS.GetByRoleName("User").ID ;

                    service.Save(Newuser);

                    // build a message to send to the user.
                    //string validateUrl = string.Format("{0}account/validate/{1}", App.BaseUrl, Helpers.base64Encode(user.EmailAddress));

                    //TemplateParser parser = new TemplateParser();
                    //Dictionary<string, string> replacements = new Dictionary<string, string>();
                    //replacements.Add("[BASE_URL]", App.BaseUrl);
                    //replacements.Add("[FIRST_NAME]", user.EmailAddress);
                    //replacements.Add("[VALIDATE_ACCOUNT_URL]", validateUrl);

                    //string message = parser.Replace(AccountEmails.ValidateAccount, replacements);

                    //EmailSender sender = new EmailSender();
                    //sender.Send(App.MailConfiguration, model.EmailAddress, "", "Thank you for registering on epilogger.com", message);

                    //this.StoreSuccess("Your account was created successfully<br /><br/>Please check your inbox for our validation message, your account will be inaccessable until you validate it.");

                    return RedirectToAction("login", "account");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ViewRes.SharedString.CreateAccountProblem + " - " + ex.Message.ToString());
                    return View(model);
                }
            }
            else
                return View(model);
        }