public ActionResult Create(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                BOMembershipUser membershipUser = new BOMembershipUser();
                Mapper.Map<UserViewModel, BOMembershipUser>(model, membershipUser);
                SaveResult result = _userService.Save(membershipUser, Common.User);

                if (result == SaveResult.Success)
                {
                    _cacheService.Remove<MenuStructure>(CacheKeys.MenuStructure);
                    return RedirectToAction("Index");
                }

                else
                {
                    switch (result)
                    {
                        case SaveResult.DuplicateEmailExists:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.DuplicateEmailExists));
                            break;
                        case SaveResult.CannotReusePassword:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.CannotReusePassword));
                            break;
                        case SaveResult.DuplicateUserNameExists:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.DuplicateUserNameExists));
                            break;
                        case SaveResult.FailedToChangeUserName:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.InvalidUserName));
                            break;
                        case SaveResult.InvalidPassword:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.InvalidPassword));
                            break;
                        default:
                            ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.Unknown));
                            break;
                    }
                }

            }
            var companies = _companyService.GetAllCompanies();
            var roles = _roleService.GetAllRoles();

            model.CompanyList = new SelectList(companies, SelectLists.DataValueField, SelectLists.DataTextField, model.Company);
            model.UserRoleList = new SelectList(roles, SelectLists.DataValueField, SelectLists.DataTextField);
            model.PasswordValidationMessage = BOUser.PasswordValidationMessage;

            return View(model);
        }
        public ActionResult Create()
        {
            var companies = _companyService.GetAllCompanies();
            var roles = _roleService.GetAllRoles();

            var model = new UserViewModel()
            {
                CompanyList = new SelectList(companies, SelectLists.DataValueField, SelectLists.DataTextField, SelectLists.UnitializedSelectValue),
                UserRoleList = new SelectList(roles, SelectLists.DataValueField, SelectLists.DataTextField),
                PasswordValidationMessage = BOUser.PasswordValidationMessage,
                HasRoleCreatePermission = _rightService.UserHasRight(Common.LoggedInUser.UserName, Rights.Role, RightOperation.Create)
            };

            return View(model);
        }
Beispiel #3
0
        public ActionResult Create(UserViewModel user)
        {
            if (ModelState.IsValid)
            {
                AutoMapper.Mapper.CreateMap<UserViewModel, DAL.Models.User>();
                var userModel = AutoMapper.Mapper.Map<User>(user);
                int id =userContracts.Add(userModel);
                if (id <= 0)
                {
                    TempData["fail"] = "Failed to create the user";
                    return RedirectToAction("Create");
                }
                else
                {
                    TempData["success"] = "User Created";
                    AccountController account = new AccountController();
                    return RedirectToAction("Create");

                }

            }
            TempData["fail"] = "Failed to create the user";
            return View();
        }