public ActionResult AddUser(AddUserViewModel addUser) { if(ModelState.IsValid) { using (new UnitOfWork(_currentContext)) { var user = new Account() { Username = addUser.Username, Password = addUser.Password.Sha256(Const.HashSalt), RegisteredAt = DateTime.Now, RoleId = (int) AccountRole.Administrator }; accountRepository.Add(user); TempData[Const.ActionResultInfo] = "Пользователь успешно добавлен"; return RedirectToAction("Users"); } } TempData[Const.ActionErrorInfo] = "Невозможно создать пользователя. Проверьте правильность заполнения данных"; return View(); }
public IActionResult Register() { AddUserViewModel model = new AddUserViewModel { }; return(View(model)); }
public ActionResult AddUser() { ViewBag.Title = Constant.ADD_USER; AddUserViewModel auvm = AddUserCommon(); return(PartialView(auvm)); }
public async Task <IActionResult> AddUser(AddUserViewModel model) { if (ModelState.IsValid) { await userService.AddUser(model.Email, model.Password, model.Country); } return(RedirectToAction("Index", "Home")); }
public IActionResult Create() { var view = new AddUserViewModel { RoleId = 2 }; return(View()); }
private string getRoleId(AddUserViewModel model) { var context = new ApplicationDbContext(); var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); return(roleManager.Roles.FirstOrDefault(r => r.Name == model.Role).Id); }
public void CanCreateUser_InvalidForm_ReturnsFalse() { var vm = new AddUserViewModel(); vm.FirstName = "test"; Assert.False(vm.CanCreateUser); }
// GET: Users/Create public IActionResult Create() { AddUserViewModel model = new AddUserViewModel(); model.Roles = ToSelectList(_RoleManager.Roles); return(View(model)); }
public void LoadModifyUserPage(UserDTO user) { IWindowManager manager = new WindowManager(); AddUserViewModel modify = new AddUserViewModel(user); manager.ShowDialog(modify, null, null); Reload(); }
public void LoadAddUserPage() { IWindowManager manager = new WindowManager(); AddUserViewModel add = new AddUserViewModel(); manager.ShowDialog(add, null, null); Reload(); }
public async Task <IActionResult> Create(AddUserViewModel model) { if (ModelState.IsValid) { var user = new User { Address = model.Address, Document = model.Document, Email = model.UserName, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, UserName = model.UserName }; var response = await _userHelper.AddUserAsync(user, model.Password); if (response.Succeeded) { var userInDB = await _userHelper.GetUserByEmailAsync(model.UserName); await _userHelper.AddUserToRoleAsync(userInDB, "Customer"); var owner = new Owner { Agendas = new List <Agenda>(), Pets = new List <Pet>(), User = userInDB }; _dataContext.Owners.Add(owner); try { await _dataContext.SaveChangesAsync(); var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); _mailHelper.SendMail(model.UserName, "Email confirmation", $"<h1>Email Confirmation</h1>" + $"To allow the user, " + $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.ToString()); return(View(model)); } } ModelState.AddModelError(string.Empty, response.Errors.FirstOrDefault().Description); } return(View(model)); }
public async Task <IActionResult> Register(AddUserViewModel model) { if (ModelState.IsValid) { var role = "Owner"; if (model.RoleId == 1) { role = "Lessee"; } var user = await _userHelper.AddUser(model, role); if (user == null) { ModelState.AddModelError(string.Empty, "This email is already used."); return(View(model)); } if (model.RoleId == 1) { var lessee = new Lessee { Contracts = new List <Contract>(), User = user }; _dataContext.Lessees.Add(lessee); } else { var owner = new Owner { Contracts = new List <Contract>(), Properties = new List <Property>(), User = user }; _dataContext.Owners.Add(owner); } await _dataContext.SaveChangesAsync(); var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); _mailHelper.SendMail(model.Username, "MyLeasing - Email confirmation", $"<h1>MyLeasing - Email Confirmation</h1>" + $"To allow the user, " + $"please click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); ViewBag.Message = "The instructions to allow your user has been sent to email."; return(View(model)); } model.Roles = _combosHelper.GetComboRoles(); return(View(model)); }
public ActionResult Add(AddUserViewModel userViewModel) { if (userManager.HasUserName(userViewModel.UserName)) { ModelState.AddModelError("UserName", "用户名已存在"); } if (userManager.HasEmail(userViewModel.Email)) { ModelState.AddModelError("Email", "Email已存在"); } if (ModelState.IsValid) { User _user = new Core.User() { RoleID = userViewModel.RoleID, UserName = userViewModel.UserName, Name = userViewModel.Name, Sex = userViewModel.Sex, Password = Core.General.Security.Sha256(userViewModel.Password), Email = userViewModel.Email, RegTime = DateTime.Now }; var _response = userManager.Add(_user); if (_response.Code == 1) { return(View("Prompt", new Prompt() { Title = "添加用户成功", Message = "您已成功添加了用户【" + _response.Data.UserName + "(" + _response.Data.Name + ")】", Buttons = new List <string> { "<a href=\"" + Url.Action("Index", "User") + "\" class=\"btn btn-default\">用户管理</a>", "<a href=\"" + Url.Action("Details", "User", new { id = _response.Data.UserID }) + "\" class=\"btn btn-default\">查看用户</a>", "<a href=\"" + Url.Action("Add", "User") + "\" class=\"btn btn-default\">继续添加</a>" } })); } else { ModelState.AddModelError("", _response.Message); } } //角色列表 var _roles = new RoleManager().FindList(); List <SelectListItem> _listItems = new List <SelectListItem>(_roles.Count()); foreach (var _role in _roles) { _listItems.Add(new SelectListItem() { Text = _role.Name, Value = _role.RoleID.ToString() }); } ViewBag.Roles = _listItems; //角色列表结束 return(View(userViewModel)); }
public ActionResult AddUser(string id) { AddUserViewModel model = new AddUserViewModel() { AspUserId = id }; return(View("AddUser", model)); }
public void Lastname_NewLastname_AssignNewLastname() { var vm = new AddUserViewModel(); var expected = "Lastname"; vm.LastName = expected; Assert.Equal(expected, vm.LastName); }
public ActionResult AddUser() { var viewModel = new AddUserViewModel() { RoleOptions = db.Roles.ToList() }; return(View(viewModel)); }
// GET: AppUsers/Create public IActionResult Create() { var model = new AddUserViewModel { UserTypes = _combosHelper.GetComboUserTypes(), }; return(View(model)); }
public AddUserView() { InitializeComponent(); DataContext = ViewModel = new AddUserViewModel(); Owner = Application.Current.MainWindow; Loaded += OnAddUserViewLoaded; }
public IActionResult Add(AddUserViewModel addUserViewModel) { if (ModelState.IsValid) { return(Redirect("/User/Index?username=" + addUserViewModel.Username)); } return(View(addUserViewModel)); }
public async Task <IActionResult> AddUser() { var model = new AddUserViewModel() { AllRoles = await _roleService.GetAllRoleNames() }; return(View(model)); }
public async Task <IActionResult> Create(AddUserViewModel model) { if (ModelState.IsValid) { Userstbl user = new Userstbl { Pro_Lote = model.PRO_LOTE, Pro_Nombres = model.PRO_NOMBRES, Pro_Apellidos = model.PRO_APELLIDOS, TipViv = await _context.TiposViviendatbls.FindAsync(model.TVId), TipPer = await _context.TipoPersonastbls.FindAsync(model.TPId), Pro_Observaciones = model.PRO_OBSERVACIONES, Pro_Telefono = model.PRO_TELEFONO, TipIde = await _context.TipoIdentificaciontbls.FindAsync(model.TIId), Pro_Identificacion = model.PRO_IDENTIFICACION, Email = model.Username, UserName = model.Username }; Microsoft.AspNetCore.Identity.IdentityResult response = await _userHelper.AddUserAsync(user, model.Password); if (response.Succeeded) { Userstbl userInDB = await _userHelper.GetUserByEmailAsync(model.Username); await _userHelper.AddUserToRoleAsync(userInDB, "Customer"); var propietario = new Propietariostbl { Vehiculos = new List <Vehiculostbl>(), Negocio = new List <Negociostbl>(), Pagos = new List <Pagostbl>(), User = userInDB, }; _context.Propietariostbls.Add(propietario); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.ToString()); return(View(model)); } } ModelState.AddModelError(string.Empty, response.Errors.FirstOrDefault().Description); } model.TipoViviendaVM = _combosHelper.GetComboTipoVivienda(); model.TipoIdentificacionVM = _combosHelper.GetComboTipoIdentificacion(); model.TipoPersonaVM = _combosHelper.GetComboTipoPersona(); return(View(model)); }
public IActionResult AddUser() { AddUserViewModel addUserViewModel = new AddUserViewModel { Roles = _roleManager.Roles, }; return(View(addUserViewModel)); }
public PartialViewResult AddUserToGroup(int id) { AddUserViewModel model = new AddUserViewModel { GroupId = id }; return(PartialView("AddUserToGroup", model)); }
public IActionResult Add(AddUserViewModel addUserViewModel) { if (ModelState.IsValid) { UserData.Add(addUserViewModel.CreateUser()); return(Redirect("/User")); } return(View(addUserViewModel)); }
public async Task <UserViewModel> AddUser(AddUserViewModel viewModel) { var user = _mappingEngine.Map <User>(viewModel); user.Email = aspNetIdentityRequiredEmail; await CreateAsync(user, viewModel.Password); return(await GetUserViewModel(user.Id)); }
public async Task AddUser(AddUserViewModel viewModel) { var user = _mappingEngine.Map <User>(viewModel); viewModel.RoleIds.ToList().ForEach(roleId => user.Roles.Add(new UserRole { RoleId = roleId })); await CreateAsync(user, viewModel.Password); }
public IActionResult AppLicationUser(QueryOptions options, AddUserViewModel model) { var Userrole = _roleManager.FindByNameAsync("User").Result; if (Userrole == null) { } return(View(_repository.UsersList(options, Userrole.Id, model.UserId, true))); }
public void CanCreateUser_ValidForm_ReturnsTrue() { var vm = new AddUserViewModel(); vm.FirstName = "Fn"; vm.LastName = "Ln"; Assert.True(vm.CanCreateUser); }
public IActionResult Register() { AddUserViewModel model = new AddUserViewModel { Teams = _combosHelper.GetComboTeams() }; return(View(model)); }
public IActionResult Index() { AddUserViewModel model = new AddUserViewModel { Users = UserData.GetAll() }; return(View(model)); }
public IActionResult Register() { var model = new AddUserViewModel { Roles = _combosHelper.GetComboRoles() }; return(View(model)); }
public User MapNewUserVMToUser(AddUserViewModel addusr) { return new User { Username = addusr.Username, Password = addusr.Password }; }
public ActionResult AddUser(AddUserViewModel auvm) { if (Session["UserId"] != null) { if (ModelState.IsValid == true) { int num = _db.IsUsernameAvailable(auvm.Username); if (num == 0) { int num2 = this._db.InsertNewUser(this.usrMaps.MapNewUserVMToUser(auvm)); if (num2 == 1) { //if (HomeController.<AddUser>o__SiteContainer2.<>p__Site3 == null) //{ // HomeController.<AddUser>o__SiteContainer2.<>p__Site3 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "Message", typeof(HomeController), new CSharpArgumentInfo[] // { // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null) // })); //} //HomeController.<AddUser>o__SiteContainer2.<>p__Site3.Target(HomeController.<AddUser>o__SiteContainer2.<>p__Site3, base.get_ViewBag(), "User Added Successfully"); ViewBag.Message = "User Added Successfully"; return View(); } else { //if (HomeController.<AddUser>o__SiteContainer2.<>p__Site4 == null) //{ // HomeController.<AddUser>o__SiteContainer2.<>p__Site4 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "error", typeof(HomeController), new CSharpArgumentInfo[] // { // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null) // })); //} //HomeController.<AddUser>o__SiteContainer2.<>p__Site4.Target(HomeController.<AddUser>o__SiteContainer2.<>p__Site4, base.get_ViewBag(), "Error Occured while Inserting New User"); ViewBag.error = "Error Occured while Inserting New User"; return View(); } } else { //if (HomeController.<AddUser>o__SiteContainer2.<>p__Site5 == null) //{ // HomeController.<AddUser>o__SiteContainer2.<>p__Site5 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "error", typeof(HomeController), new CSharpArgumentInfo[] // { // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), // CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null) // })); //} //HomeController.<AddUser>o__SiteContainer2.<>p__Site5.Target(HomeController.<AddUser>o__SiteContainer2.<>p__Site5, base.get_ViewBag(), "Username Already avilable"); ViewBag.error = "Username Already avilable"; return View(); } } else { return View(); } } else { return RedirectToAction("LogIn"); } }