public async Task <IActionResult> EditRole(RolesViewModel ViewModel) { if (ModelState.IsValid) { var Role = await _roleManager.FindByIdAsync(ViewModel.RoleID); if (Role == null) { return(NotFound()); } if (await _roleManager.RoleExistsAsync(ViewModel.RoleName)) { ViewBag.Error = "خطا !!! این نقش تکراری است."; } else { Role.Name = ViewModel.RoleName; var Result = await _roleManager.UpdateAsync(Role); if (Result.Succeeded) { ViewBag.Success = "ذخیره تغییرات با موفقیت انجام شد."; } else { ViewBag.Error = "خطایی در ذخیره تغییرات رخ داده است."; } } } return(View(ViewModel)); }
public ActionResult ManageRole(int?roleID, string operation) { RolesViewModel model = null; if (roleID == null) { model = new RolesViewModel(); } else { //get floor plan by ID model = _roleBAL.GetRoleByID(roleID.Value); } if (model == null) { ViewBag.msg = "No record found"; model = new RolesViewModel(); } string message = string.Empty; if (operation != null) { if (operation == AppConstants.ADDED) { message = "Sections added successfully."; } else if (operation == AppConstants.UPDATED) { message = "Sections updated successfully."; } ViewBag.Message = message; } return(View(model)); }
public async Task <IActionResult> AddRole(RolesViewModel ViewModel) { if (ModelState.IsValid) { if (await _roleManager.RoleExistsAsync(ViewModel.RoleName)) { ViewBag.Error = "خطا !!! این نقش تکراری است."; } else { var Result = await _roleManager.CreateAsync(new IdentityRole(ViewModel.RoleName)); if (Result.Succeeded) { return(RedirectToAction("Index")); } ViewBag.Error = "در ذخیره اطلاعات خطایی رخ داده است."; return(View(ViewModel)); } } return(View(ViewModel)); }
public async Task <IActionResult> RolesEdit(RolesViewModel model) { try { if (ModelState.IsValid) { var role = await _roleManager.FindByIdAsync(model.Id.ToString()); if (role != null) { role.Name = model.Name; role.IsActive = model.IsActive; await _roleManager.UpdateAsync(role); return(Json(new { Message = "Rol kayıdı düzenlendi!", IsSuccess = true })); } return(NotFound()); } return(Json(new { Message = "Hata oluştu!", IsSuccess = false })); } catch (Exception ex) { var logger = LogManager.GetLogger("FileLogger"); logger.Log(NLog.LogLevel.Error, $"\nHata Mesajı: {ex.Message}\nStackTrace:{ex.StackTrace}"); return(Json(new { Message = $"Hata: {ex.Message}", IsSuccess = false })); } }
public async Task <IActionResult> RolesEdit(int id) { try { if (id == 0) { return(BadRequest()); } var role = await _roleManager.FindByIdAsync(id.ToString()); var model = new RolesViewModel(); model.Id = role.Id; model.Name = role.Name; model.IsActive = role.IsActive; if (role == null) { return(NotFound()); } return(View(model)); } catch (Exception ex) { var logger = LogManager.GetLogger("FileLogger"); logger.Log(NLog.LogLevel.Error, $"\nHata Mesajı: {ex.Message}\nStackTrace:{ex.StackTrace}"); return(View()); } }
public ActionResult Roles(RolesViewModel model) { if (ModelState.IsValid) { var userName = model.userName.ToString(); var _user = UserManager.FindByName(userName); if (_user == null) { ViewBag.ErrorMsg = "can not found a register user with name '" + userName + "'."; return(View()); } var rolesForUser = UserManager.GetRoles(_user.Id); var roleAdmin = "Admin"; if (rolesForUser.Contains(roleAdmin)) { ViewBag.ErrorMsg = "the user with name '" + userName + "' is already in the admin role."; return(View()); } try { UserManager.AddToRole(_user.Id, roleAdmin); } catch (Exception ex) { ViewBag.ErrorMsg = "system error: " + ex.Message; return(View()); } ViewBag.Success = "success authorization."; } return(View()); }
public async Task <ActionResult> CreandoRol(RolesViewModel model) { var role = new IdentityRole { Name = model.Name }; //var result = await this.Request.GetOwinContext().GetUserManager<ApplicationRoleManager>().CreateAsync(role); var result = await this.AppRoleManager.CreateAsync(role); if (!result.Succeeded) { return(View()); } else { return(RedirectToAction("Index", "Roles")); } //if (ModelState.IsValid) //{ // AspNetRoles Rol = new AspNetRoles() // { // Id = rol.Id, // Name = rol.Name, // }; // context.AspNetRoles.Add(Rol); // context.SaveChanges(); //} //return RedirectToAction("CreandoRol"); }
public PartialViewResult RoleList(string searchTerm, int?pageNo) { var pageSize = 3; pageNo = pageNo ?? 1; RolesViewModel model = new RolesViewModel(); model.SearchTerm = searchTerm; var roles = RoleManager.Roles; if (!string.IsNullOrEmpty(searchTerm)) { roles = roles.Where(x => x.Name.ToLower().Contains(searchTerm.ToLower())); } var skipCount = pageSize * (pageNo.Value - 1); model.Roles = roles.OrderBy(x => x.Name).Skip(skipCount).Take(pageSize).ToList(); model.pager = new Pager(roles.Count(), pageNo, pageSize); return(PartialView(model)); }
public async Task <IActionResult> AddEditApplicationRole(string id, RolesViewModel model) { if (ModelState.IsValid) { bool isExist = !String.IsNullOrEmpty(id); ApplicationRoles applicationRole = isExist ? await _roleManager.FindByIdAsync(id) : new ApplicationRoles { CreatedDate = DateTime.UtcNow }; applicationRole.Name = model.Name; applicationRole.Description = model.Description; applicationRole.IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(); IdentityResult roleResult = isExist ? await _roleManager.UpdateAsync(applicationRole) : await _roleManager.CreateAsync(applicationRole); string header = String.IsNullOrEmpty(id) ? "Add" : "Edit"; ViewBag.header = header; if (roleResult.Succeeded) { return(RedirectToAction("Index")); } } return(View(model)); }
public async Task <IActionResult> DeletedRole(string id) { if (id == null) { return(NotFound()); } var Role = await _roleManager.FindByIdAsync(id); if (Role == null) { return(NotFound()); } var Result = await _roleManager.DeleteAsync(Role); if (Result.Succeeded) { return(RedirectToAction("Index")); } ViewBag.Error = "در حذف اطلاعات خطایی رخ داده است."; RolesViewModel ViewModel = new RolesViewModel() { RoleID = Role.Id, RoleName = Role.Name, }; return(View(ViewModel)); }
public ProfilePage() { InitializeComponent(); GetUserById(); //GetUserRoles(); BindingContext = new RolesViewModel(); }
public ActionResult Create() { RolesViewModel viewModel = new RolesViewModel(); viewModel.DataModels = unit.Role.GetAll().ToList(); return(View(viewModel)); }
public IActionResult Roles() { RolesViewModel vm = new RolesViewModel() { GridControl = new GridControlModel() { PageSize = 10, CurrentPage = 1, TotalRecords = 2 }, GridData = new List <RoleGridRowModel>() { new RoleGridRowModel() { RoleId = "1", Name = "Administrator" }, new RoleGridRowModel() { RoleId = "2", Name = "Super User" } } }; return(View(vm)); }
public async Task <IActionResult> Roles(RolesViewModel model) { if (ModelState.IsValid) { var user = _userManager.Users.Where(u => u.Id == model.Id).First(); var userRoles = await _userManager.GetRolesAsync(user); var selectedRoles = model.Roles .Where(x => x.Selected == true && !userRoles.Contains(x.Name)) .Select(x => x.Name) .ToList(); var unselectedRoles = model.Roles .Where(x => x.Selected == false && userRoles.Contains(x.Name)) .Select(x => x.Name) .ToList(); await _userManager.AddToRolesAsync(user, selectedRoles); await _userManager.RemoveFromRolesAsync(user, unselectedRoles); return(RedirectToAction("Users", new { Message = ManageMessageId.RoleChangeSuccess })); } return(View(model)); }
public async Task <ActionResult> CreateRole(RolesViewModel model) { if (ModelState.IsValid) { var result = IdentityResult.Success; if (RoleManager.RoleExists(model.Name)) { result = IdentityResult.Failed(new string[] { "El Rol ya Existe" }); } else { var role = new Role { Nombre = model.Name }; result = await RoleManager.CreateAsync(new IdentityRole(model.Name)); if (result.Succeeded) { result = await RolControllerBLL.Instance.Create(role); if (result.Succeeded) { return(RedirectToAction("Roles")); } } } AddErrors(result); } // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario return(View(model)); }
public ActionResult UserPerm() { var userRoles = new List <RolesViewModel>(); var context = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); foreach (var user in userStore.Users.ToList()) { var r = new RolesViewModel { UserName = user.UserName, UserId = user.Id }; if (userManager.IsInRole(user.Id, "Admin")) { r.IsAdmin = true; } if (userManager.IsInRole(user.Id, "Manager")) { r.IsManager = true; } if (User.Identity.GetUserId() != r.UserId && r.UserName != "*****@*****.**") { userRoles.Add(r); } } return(View(userRoles)); }
//[Bind(Include = "RolId,RolNombre")] public async Task <ActionResult> Create(RolesViewModel model) { if (ModelState.IsValid) { try { db.Roles.Add(model.Rol); db.SaveChanges(); await db.SaveChangesAsync(); //Objetos foreach (var obj in model.Objetos) { if (obj.Seleccionado) { RolObjeto ao = new RolObjeto(); ao.RolId = model.Rol.RolId; ao.ObjetoId = obj.ObjetoId; ao.RolObjetoActivo = true; db.RolObjeto.Add(ao); } } //Apps foreach (var app in model.Apps) { if (app.Seleccionado) { RolAplicacion ao = new RolAplicacion(); ao.AplicacionId = app.AplicacionId; ao.RolId = model.Rol.RolId; db.RolAplicaciones.Add(ao); } } if (!ModelState.Values.Any(ms => ms.Errors.Count > 0)) { await db.SaveChangesAsync(); AddLog("", model.Rol.RolId, model); return(RedirectToAction("Index", GetReturnSearch())); } //Guarda Objetos al rol // guardaRolObjeto(RolObjetoList, rol.RolId); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.Error = e.ToString(); } } return(View(new RolesViewModel { Rol = model.Rol, Objetos = model.Objetos, Apps = model.Apps })); }
public async Task <ActionResult> EditRole([Bind(Include = "Id,Name")] RolesViewModel rolesViewModel) { if (ModelState.IsValid) { var rol = await RoleManager.FindByIdAsync(rolesViewModel.Id); string name = rol.Name; rol.Name = rolesViewModel.Name; var result = IdentityResult.Success; result = await RoleManager.UpdateAsync(rol); if (result.Succeeded) { result = await RolControllerBLL.Instance.Edit(new Role { Nombre = rolesViewModel.Name }, name); if (result.Succeeded) { return(RedirectToAction("Roles")); } } AddErrors(result); } // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario return(View(rolesViewModel)); }
public async Task <IActionResult> CreateOrUpdate(RolesViewModel viewModel) { if (ModelState.IsValid) { IdentityResult result; if (viewModel.Id != null) { var role = await _roleManager.FindByIdAsync(viewModel.Id.ToString()); result = await _roleManager.UpdateAsync(_mapper.Map(viewModel, role)); } else { result = await _roleManager.CreateAsync(_mapper.Map <Role>(viewModel)); } if (result.Succeeded) { TempData["notification"] = OperationSuccess; } else { ModelState.AddErrorsFromResult(result); } } return(PartialView("_RenderRole", viewModel)); }
public ActionResult Index() { var userRoles = new List <RolesViewModel>(); var context = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); //Get all the usernames foreach (var _user in userStore.Users.Where(x => x.UserName != User.Identity.Name).ToList()) { var r = new RolesViewModel { UserName = _user.UserName, Apellido = _user.Apellido, Nombre = _user.Nombre, Rut = _user.Rut, Isbloqued = _user.Isbloqued, }; userRoles.Add(r); } //Get all the Roles for our users foreach (var _user in userRoles) { _user.RoleNames = userManager.GetRoles(userStore.Users.First(s => s.UserName == _user.UserName).Id); } var user = UserManager.Users.ToList(); return(View(userRoles)); }
public NRolesView(RolesViewModel NRolesView) { InitializeComponent(); NRolesViewModel Modelo = new NRolesViewModel(NRolesView); this.DataContext = Modelo; }
public async Task <IActionResult> EditRole(RolesViewModel ViewModel) { if (ModelState.IsValid) { var Role = await _roleManager.FindByIdAsync(ViewModel.RoleID); if (Role == null) { return(NotFound()); } Role.Name = ViewModel.RoleName; var Result = await _roleManager.UpdateAsync(Role); if (Result.Succeeded) { ViewBag.Message = "alert-success"; return(View(ViewModel)); } ViewBag.Message = "alert-danger"; return(View(ViewModel)); } return(View(ViewModel)); }
public async Task <JsonResult> RolesCreate(RolesViewModel model) { try { if (ModelState.IsValid) { var role = new AppRole { Name = model.Name, IsActive = model.IsActive }; var result = await _roleManager.CreateAsync(role); if (result.Succeeded) { return(Json(new { Message = "Rol kayıdı oluşturulmuştur!", IsSuccess = true })); } return(Json(new { Message = "Rol kayıdı oluşturulamadı!", IsSuccess = false })); } return(Json(new { Message = "Hata oluştu!", IsSuccess = false })); } catch (Exception ex) { var logger = LogManager.GetLogger("FileLogger"); logger.Log(NLog.LogLevel.Error, $"\nHata Mesajı: {ex.Message}\nStackTrace:{ex.StackTrace}"); return(Json(new { Message = $"Hata: {ex.Message}", IsSuccess = false })); } }
public ResponseModel <IEnumerable <RolesViewModel> > Roles_Get() { var list = _db.AspNetRoles.Where(x => true); List <RolesViewModel> reList = new List <RolesViewModel>(); try { foreach (var item in list) { RolesViewModel model = new RolesViewModel { Id = item.Id, Name = item.Name }; reList.Add(model); } reList.AsEnumerable(); } catch (Exception e) { return(new ResponseModel <IEnumerable <RolesViewModel> > { code = (int)code.GetRoleFail, data = null, message = "角色信息获取失败," + e.Message, }); } return(new ResponseModel <IEnumerable <RolesViewModel> > { code = (int)code.Success, data = reList, message = ""//角色信息获取成功 }); }
public async Task <IActionResult> EditRole(RolesViewModel ViewModel) { if (ModelState.IsValid) { var Role = await _roleManager.FindByIdAsync(ViewModel.RoleID); if (Role == null) { return(NotFound()); } Role.Name = ViewModel.RoleName; Role.Description = ViewModel.Description; var Result = await _roleManager.UpdateAsync(Role); if (Result.Succeeded) { ViewBag.Success = "ذخیره تغییرات با موفقیت انجام شد."; } foreach (var item in Result.Errors) { ModelState.AddModelError("", item.Description); } } return(View(ViewModel)); }
public async Task <JsonResult> OnPostCreateOrEditAsync(string id, RolesViewModel role) { if (ModelState.IsValid && role.Name != "SuperAdmin" && role.Name != "Basic") { if (string.IsNullOrEmpty(id)) { await _roleManager.CreateAsync(new IdentityRole(role.Name)); } else { var existingRole = await _roleManager.FindByIdAsync(id); existingRole.Name = role.Name; existingRole.NormalizedName = role.Name.ToUpper(); await _roleManager.UpdateAsync(existingRole); } var roles = await _roleManager.Roles.ToListAsync(); Roles = Mapper.Map <IEnumerable <RolesViewModel> >(roles); var html = await Renderer.RenderPartialToStringAsync("_ViewAllRoles", Roles); return(new JsonResult(new { isValid = true, html = html })); } else { var html = await Renderer.RenderPartialToStringAsync <RolesViewModel>("_CreateOrEdit", role); return(new JsonResult(new { isValid = false, html = html })); } }
public ActionResult Index() { var userRoles = new List <RolesViewModel>(); var context = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); //Get all the usernames foreach (var user in userStore.Users) { var r = new RolesViewModel { UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, NickName = user.NickName }; userRoles.Add(r); } //Get all the Roles for our users foreach (var user in userRoles) { user.RoleNames = userManager.GetRoles(userStore.Users.First(s => s.UserName == user.UserName).Id); } return(View(userRoles)); }
public RolesView() { InitializeComponent(); RolesViewModel ModeloDatos = new RolesViewModel(); this.DataContext = ModeloDatos; }
public Roles() { InitializeComponent(); PageAnimation.SetObject(front, back); viewModel = new RolesViewModel(); this.Loaded += (s, e) => { this.DataContext = this.viewModel; }; }
public async Task <IActionResult> Put(string id, [FromBody] RolesViewModel item) { await _documentClient.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, id), item); return(Ok()); }
public AddRoleViewModel() { vml = new ViewModelLocator(); qvm = vml.Roles; AddQuestionCommand = new RelayCommand(AddQuestion); }
public ActionResult Roles(RolesViewModel model) { if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal") return RedirectToAction("Index", "Home"); ViewBag.Menu = ClasesVarias.GetMenuUsuario(); ViewBag.Title = Resources.RolesResource.RolesPageTitle; ViewBag.PageHeader = Resources.RolesResource.RolesHeaderPage; model.Roles = ClasesVarias.GetNivelesUsuario(); model.showModulos = false; if (model.RolID > 0) { model.showModulos = true; using (SeguricelEntities db = new SeguricelEntities()) { model.Modulos = (from d in db.Modulo select new RolViewModel { Asignado = (d.Modulo_TipoUsuario.Where(x => x.IdTipoUsuario == model.RolID).Count() > 0), FechaAsignacion = (DateTime)d.Modulo_TipoUsuario.Where(x => x.IdTipoUsuario == model.RolID).FirstOrDefault().FechaAsignacion, IdModulo = d.IdModulo, IdTipoUsuario = model.RolID, Modulo = d.Nombre, ModuloPadre = (d.Modulo2 != null ? d.Modulo2.Nombre : string.Empty) }).ToList(); } } else { model.showModulos = false; model.Modulos = new List<RolViewModel>(); } return View(model); }