Beispiel #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    // List<Users> users = userService.GetAll().ToList();
                    string password = Base.GenearateKey(8);
                    var status = MembershipCreateStatus.UserRejected;
                    Membership.CreateUser(model.UserName, password, model.UserName + "@gmail.com", "what is", "yes",
                        true, null, out status);
                    MembershipUser user = Membership.GetUser(model.UserName, false);
                    user.Email = "*****@*****.**";
                    Membership.UpdateUser(user);

                    // Profiles profile = profileProvider.CreateProfile(model.UserName, true);

                    UserProfileBase profile = UserProfileBase.GetUserProfile(model.UserName);

                    if (profile != null)
                    {
                        profile.FirstName = "jeffrey";
                        profile.LastName = "Valeroso";
                        //  profile.Address = "Taytay, Rizal";
                        profile.Gender = "M";
                        profile.Language = "English";
                        profile.Position = "Senior Software Developer";
                        profile.Subscription = "None";
                        profile.Save();
                    }

                    bool check = Roles.RoleExists("MVP");

                    string[] usernames = { model.UserName };
                    string[] roles = { "MVP" };

                    Roles.AddUsersToRoles(usernames, roles);
                    //add user to role
                    //System.Web.Security.Roles.AddUserToRole(model.UserName, model.RoleName);

                    var store = new Store();
                    store.Address = "Makati City";
                    store.Active = true;
                    store.Code = "MC2012";
                    store.Name = "Greenbelt";
                    store.DateCreated = DateTime.Now;
                    store.PermitNo = "1223423";

                    Users employee = userService.GetUserByUsernameApplicationName(user.UserName, "Exchange");
                    store.AddUser(employee);

                    //  storeService.SaveOrUpdate(store);

                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #2
0
        public ActionResult Register()
        {
            //var userRoles = System.Web.Security.Roles.GetAllRoles();
            //var stores = _storeService.GetAll();
            var model = new RegisterModel();
            //{
            //    UserRoles = userRoles.Select(x => new SelectListItem
            //    {
            //        Value = x,
            //        Text = x
            //    }),

            //    StoreList = stores.Select(y => new SelectListItem
            //    {
            //        Value = y.Code,
            //        Text = y.Name
            //    })
            //};
            return View(model);
        }