/// <summary> /// Gets rights for a role type defined as default rights available for right type. /// </summary> /// <param name="typeID">pass role type id</param> /// <returns>list of rights for a role type</returns> public Dictionary<string, UserRight> GetRights(short typeID) { var roleType = new BORoleType(typeID); var rightRoleTypes = BORightRoleTypeX.GetAllForRoleType(roleType).Cast<BORightRoleTypeX>().ToList(); var roleTypeRights = new Dictionary<string, UserRight>(); foreach (BORightRoleTypeX itemRoleType in rightRoleTypes) { var objBORight = new BORight(itemRoleType.Right.ID); if (!roleTypeRights.ContainsKey(objBORight.Key.Trim())) { UserRight userRight = new UserRight() { ShowCreate = objBORight.ShowCreate, ShowDelete = objBORight.ShowDelete, ShowUpdate = objBORight.ShowUpdate, ShowExecute = objBORight.ShowExecute, ShowRead = objBORight.ShowRead, Name = objBORight.Name.Trim(), Key = objBORight.Key.Trim(), Description = objBORight.Description.Trim(), }; roleTypeRights.Add(objBORight.Key.Trim(), userRight); } } return roleTypeRights; }
public ActionResult Create(RightViewModel model) { if (ModelState.IsValid) { BORight right = new BORight(); Mapper.Map<RightViewModel, BORight>(model, right); RightResult rightResult = _rightService.Save(right); if (rightResult == RightResult.Success) _cacheService.Remove<MenuStructure>(CacheKeys.MenuStructure); switch (rightResult) { case RightResult.Success: return RedirectToAction("Index"); case RightResult.RightNameAlreadyExists: ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.RightNameAlreadyExists)); break; case RightResult.RightKeyAlreadyExists: ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.RightKeyAlreadyExists)); break; default: ModelState.AddModelError("Message", GlobalResource(GlobalResourceUser.Unknown)); break; } } return View(model); }
public static BORight GetByKey(string key) { logger.Trace("GetbyKey"); BORight a = new BORight(); SqlConnection con = new SqlConnection(BOBase.GetConnectionString()); con.Open(); try { SqlCommand cmd = new SqlCommand("P_Right_GetbyKey", con); cmd.CommandType = CommandType.StoredProcedure; SQLPersistent.SetVarCharParameter(cmd.Parameters, "@RIT_Key", 100, key, false); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleResult); try { if (rdr.Read()) a = new BORight(rdr); else return null; } catch (Exception ex) { logger.ErrorException("Failed to fetch record", ex); return null; } finally { rdr.Close(); } } finally { con.Close(); } return a; }
public BORightComparer(BORight.Columns column, BORight.SortDirections direction) { _column = column; _direction = direction; }
public RightResult Save(BORight right) { bool sameName = false, sameKey = false; foreach (BORight curr in _rightRepository.GetAll()) { sameName = string.Equals(right.Name.Trim(), curr.Name.Trim(), StringComparison.CurrentCulture); sameKey = string.Equals(right.Key.Trim(), curr.Key.Trim(), StringComparison.CurrentCulture); if (sameName && sameKey && curr.ID == right.ID) { continue; } if (sameName) { return RightResult.RightNameAlreadyExists; } if (sameKey) { return RightResult.RightKeyAlreadyExists; } } _rightRepository.Save(right); _cacheProvider.Remove<BORight>(CacheKeys.Prefixes.Rights + right.ID); _cacheProvider.Remove<IEnumerable<BORight>>(CacheKeys.Prefixes.Rights + CacheKeys.All); return RightResult.Success; }
public static BORoleRightX GetByRoleAndRight(string roleId, BORight right) { logger.Trace("GetByRoleId"); BORoleRightX a = new BORoleRightX(); SqlConnection con = new SqlConnection(BOBase.GetConnectionString()); con.Open(); try { SqlCommand cmd = new SqlCommand("P_RoleRightX_GetByRoleAndRight", con); cmd.CommandType = CommandType.StoredProcedure; SQLPersistent.SetVarCharParameter(cmd.Parameters, "@RORI_ROLGUID", 50, roleId, false); SQLPersistent.SetInt64Parameter(cmd.Parameters, "@RORI_RITID", right.ID, false); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleResult); try { if (rdr.Read()) a = new BORoleRightX(rdr); else return null; } catch (Exception ex) { logger.ErrorException("Failed to fetch record", ex); return null; } finally { rdr.Close(); } } finally { con.Close(); } return a; }