Пример #1
0
        public ActionResult Manage(string id)
        {
            var model = new RegisterModel();
            Profiles profile = _profileService.GetProfileByUserId(new Guid(id));
            Users user = _userService.GetUserById(new Guid(id));
            //get roles
            string[] roles = Access.GetUserRoles(user.Username);
            Core.Entities.Roles role = _roleService.GetDataByName(roles[0]);
            //get store
            Guid storeId = user.Stores.Any() ? user.Stores.First().Id : new Guid();

            if (profile != null)
            {
                model.Address = profile.Address;
                model.BirthDate = profile.BirthDate.ToString(CultureInfo.InvariantCulture);
                model.BirthDay = profile.BirthDate.Day.ToString(CultureInfo.InvariantCulture);
                model.BirthMonth = profile.BirthDate.Month.ToString(CultureInfo.InvariantCulture);
                model.BirthYear = profile.BirthDate.Year.ToString(CultureInfo.InvariantCulture);
                model.Email = user.Email;
                model.FirstName = profile.FirstName;
                model.Gender = profile.Gender;
                model.LastName = profile.LastName;
                model.MiddleName = profile.MiddleName;
                model.Position = profile.Position;
                model.StoreList = _service.GetStoreList(storeId);
                model.RoleList = _service.GetRoleList(role.Id);
                model.UserName = user.Username;
            }

            return View(model);
        }
Пример #2
0
 private static void CreateProfile(RegisterModel model)
 {
     UserProfileBase profile = UserProfileBase.GetUserProfile(model.UserName);
     if (profile == null) return;
     profile.FirstName = model.FirstName;
     profile.LastName = model.LastName;
     profile.MiddleName = model.MiddleName;
     profile.Address = model.Address;
     profile.Gender = model.Gender;
     profile.Language = model.Language;
     profile.Position = model.Position;
     profile.BirthDate = Convert.ToDateTime(model.BirthDate);
     profile.Subscription = !string.IsNullOrEmpty(model.Subscription) ? model.Subscription : string.Empty;
     profile.Language = !string.IsNullOrEmpty(model.Language) ? model.Language : string.Empty;
     profile.Save();
 }
Пример #3
0
        public JsonResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var fullName = Base.GenerateFullName(model.FirstName, model.MiddleName, model.LastName);
                try
                {
                    string password = Base.GenearateKey(8);

                    MembershipCreateStatus status;
                    model.UserName = Base.GenerateUsername(model.FirstName, model.MiddleName, model.LastName);
                    Membership.CreateUser(model.UserName, password, model.Email, "na", "na", true, null, out status);

                    var user = Membership.GetUser(model.UserName, false);
                    //create Profile
                    CreateProfile(model);
                    //Add user to Role
                    if (!Roles.IsUserInRole(model.UserName, model.RoleName))
                    {
                        Roles.AddUserToRole(model.UserName, model.RoleName);
                    }

                    Users employee = _userService.GetUserByUsernameApplicationName(user.UserName,
                        ConfigManager.Exchange.ApplicationName);
                    Store store = _storeService.GetDataById(new Guid(model.StoreId));

                    AddUserIsInStore(employee, store);

                    return
                        Json(new { result = "", message = MessageCode.saved, code = StatusCode.saved, content = fullName });
                }
                catch (Exception ex)
                {
                    return
                        Json(
                            new
                            {
                                result = StatusCode.failed,
                                message = ex.Message,
                                code = StatusCode.invalid,
                                content = fullName
                            });
                }
            }
            return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
        }
Пример #4
0
 public ActionResult Register()
 {
     var model = new RegisterModel
     {
         StoreList = _service.GetStoreList(new Guid()),
         RoleList = _service.GetRoleList(new Guid())
     };
     return View(model);
 }
Пример #5
0
        public JsonResult Manage(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Users employee = _userService.GetUserByUsernameApplicationName(model.UserName,
                        ConfigManager.Exchange.ApplicationName);
                    MembershipUser user = Membership.GetUser(model.UserName, false);
                    Store store = _storeService.GetDataById(new Guid(model.StoreId));

                    employee.Roles.Clear();
                    employee.Stores.Clear();
                    _userService.SaveOrUpdate(employee);
                    //add roles and store
                    Roles.AddUserToRole(model.UserName, model.RoleName);
                    AddUserIsInStore(employee, store);

                    return Json(new { result = "", message = MessageCode.saved, code = StatusCode.saved, content = "" });
                }
                catch (Exception ex)
                {
                    return Json(new { result = StatusCode.failed, message = ex.Message, code = StatusCode.invalid });
                }
            }
            return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
        }
Пример #6
0
        public void ActivateInitialUser()
        {
            if (!Settings.EnableInitialization) return;
            MembershipCreateStatus status;
            var userName = Base.GenerateUsername("Jeffrey", "Fuensalida", "Valeroso");
            Membership.CreateUser(userName, "admin@2014", "*****@*****.**", "na", "na", true, null,
                out status);

            var user = Membership.GetUser(userName, false);
            var profile = new RegisterModel
            {
                FirstName = "Jeffrey",
                LastName = "Valeroso",
                MiddleName = "Fuensalida",
                Address = "Manila, Philippines",
                Gender = "M",
                Language = "EN",
                Position = "Software Developer",
                BirthDate = "10/29/1986",
                UserName = userName
            };

            CreateProfile(profile);
            //create Admin Role
            if (!Roles.RoleExists("Admin"))
            {
                Roles.CreateRole("Admin");
            }
            if (!Roles.RoleExists("Super Admin"))
            {
                Roles.CreateRole("Super Admin");
            }

            //Add user to Role
            if (!Roles.IsUserInRole(userName, "Super Admin"))
            {
                Roles.AddUserToRole(userName, "Super Admin");
            }

            //Create new strore
            var store = new Store
            {
                Name = "Main",
                Address = "Manila, Philippines",
                Active = true,
                Code = "000",
                CreatedBy = "Admin",
                DateCreated = DateTime.Now,
                PermitNo = "NA",
                TINNo = "NA"
            };
            _storeService.Create(store);

            var employee = _userService.GetUserByUsernameApplicationName(userName,
                ConfigManager.Exchange.ApplicationName);
            var myStore = _storeService.GetDataById(store.Id);

            if (!CheckIfUserIsInStore(employee, myStore))
            {
                store.AddUser(employee);
                _storeService.SaveOrUpdate(myStore);
            }
        }