private void LoginSV(String name, String id) { if (name.Equals("")) { HttpContext.Session.Remove("User_Name"); HttpContext.Session.Remove("UserID"); HttpContext.Session.Remove("Ad"); } else { HttpContext.Session.SetString("User_Name", name); HttpContext.Session.SetString("UserID", id); int idint = Int32.Parse(id); int role = _context.Users.Find(idint).RoleID; RoleAuthorization existAcess = _context.RoleAuthorization.Where(e => e.RoleFK == role).FirstOrDefault(); if (existAcess != null) { HttpContext.Session.SetString("Ad", "Ad"); } else { int x = -1; } } }
public ActionResult RoleAuthorization(string MenuId) { GenelRepository gnlDB = RepositoryManager.GetRepository <GenelRepository>(); RoleAuthorization model = new RoleAuthorization(); model.MenuId = MenuId; SessionContext.Current.ActiveUser.MenuId = MenuId; model.activeRoles = gnlDB.GetActiveRoles(); if (model.activeRoles != null && model.activeRoles.Count > 0) { model.SelectedRoleId = model.activeRoles[0].role_id.ToString(); SessionContext.Current.ActiveUser.SelectedRoleId = model.SelectedRoleId; } return(View(model)); }
public ActionResult RoleAuthorization(RoleAuthorization model, FormCollection formCollection) { GenelRepository gnlDB = RepositoryManager.GetRepository <GenelRepository>(); model.activeRoles = gnlDB.GetActiveRoles(); ViewBag.Success = true; SessionContext.Current.ActiveUser.FromUpdateButton = model.FromUpdateButton; SessionContext.Current.ActiveUser.SelectedRoleId = model.SelectedRoleId; if (SessionContext.Current.ActiveUser.FromUpdateButton == "1") { try { gnlDB.DeleteRoleRights(model.SelectedRoleId); DataSet dsMenu = BaseDB.DBManager.AppConnection.GetDataSet("select * from gnl_menu"); foreach (DataRow row in dsMenu.Tables[0].Rows) { bool menuRight = false; bool deleteRight = false; bool updateRight = false; bool reportRight = false; bool newRecordRight = false; foreach (var key in formCollection.AllKeys) { string[] arr = key.Split('_'); if (arr.Length > 1) { if (arr[1] != "" && BaseFunctions.getInstance().IsNumeric(arr[1]) && arr[1] == row["menu_id"].ToString()) { if (arr[0] == "Show") { menuRight = true; } if (arr[0] == "Update") { updateRight = true; } if (arr[0] == "Delete") { deleteRight = true; } if (arr[0] == "Report") { reportRight = true; } if (arr[0] == "NewRecord") { newRecordRight = true; } } } } gnl_role_rights rights = new gnl_role_rights(); gnlDB.AddRoleRights(rights, Guid.Parse(model.SelectedRoleId), Convert.ToInt32(row["menu_id"].ToString()), menuRight, updateRight, deleteRight, reportRight, newRecordRight); } ViewBag.ResultMessage = Resources.GlobalResource.transaction_success; } catch (Exception exp) { ViewBag.Success = false; ModelState.AddModelError("Error", exp.Message); } } return(View(model)); }
public async Task <IActionResult> Create([Bind("RoleID,RoleName")] Roles roles) { System.Diagnostics.Debug.WriteLine("******************************************************"); System.Diagnostics.Debug.WriteLine("Entrou"); System.Diagnostics.Debug.WriteLine("******************************************************"); if (!GetAuthorization(2, 'c')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (!checkValues(roles)) { setViewBags(-1); return(View(roles)); } if (ModelState.IsValid) { _context.Add(roles); _context.SaveChanges(); var componenets = _context.Components.ToList(); foreach (var comp in componenets) { string selectedOptions = Request.Form[comp.Name].ToString(); string[] selectedOptionsList = selectedOptions.Split(','); RoleAuthorization rAutho = new RoleAuthorization { ComponentFK = comp.ComponentID, RoleFK = roles.RoleID, Create = false, Read = false, Update = false, Delete = false }; if (selectedOptionsList[0] != "") { foreach (var val in selectedOptionsList) { int id = Int32.Parse(val); switch (id) { case 1: rAutho.Create = true; break; case 2: rAutho.Read = true; break; case 3: rAutho.Update = true; break; case 4: rAutho.Delete = true; break; default: break; } } } if (rAutho.Delete || rAutho.Create || rAutho.Update) { rAutho.Read = true; } _context.Add(rAutho); _context.SaveChanges(); } await _context.SaveChangesAsync(); TempData["Message"] = "Permissão criada com sucesso!"; return(RedirectToAction(nameof(Index))); } TempData["Message"] = "Model de errado aconteceu!"; setViewBags(-1); return(View(roles)); }
public async Task <IActionResult> Edit(int id, [Bind("RoleID,RoleName")] Roles roles) { if (!GetAuthorization(2, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (id != roles.RoleID) { return(NotFound()); } if (!checkValues(roles)) { setViewBags(id); return(View(roles)); } if (ModelState.IsValid) { try { _context.Update(roles); var componenets = _context.Components.ToList(); var roleRules = _context.RoleAuthorization.Where(e => e.RoleFK == id); foreach (RoleAuthorization roleAutho in roleRules.ToList()) { _context.Remove(roleAutho); _context.SaveChanges(); } foreach (var comp in componenets) { string selectedOptions = Request.Form[comp.Name].ToString(); string[] selectedOptionsList = selectedOptions.Split(','); RoleAuthorization rAutho = new RoleAuthorization { ComponentFK = comp.ComponentID, RoleFK = roles.RoleID, Create = false, Read = false, Update = false, Delete = false }; if (selectedOptionsList[0] != "") { foreach (var val in selectedOptionsList) { int crudID = Int32.Parse(val); switch (crudID) { case 1: rAutho.Create = true; break; case 2: rAutho.Read = true; break; case 3: rAutho.Update = true; break; case 4: rAutho.Delete = true; break; default: break; } } } if (rAutho.Delete || rAutho.Create || rAutho.Update) { rAutho.Read = true; } _context.Add(rAutho); _context.SaveChanges(); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RolesExists(roles.RoleID)) { System.Diagnostics.Debug.WriteLine("*************************"); System.Diagnostics.Debug.WriteLine("Caught Exception"); System.Diagnostics.Debug.WriteLine("*************************"); return(NotFound()); } else { throw; } } TempData["Message"] = "Permissão editada com sucesso!"; return(RedirectToAction(nameof(Index))); } setViewBags(id); return(View(roles)); }