public bool AddMenu(Guid roleId, List <Guid> menus) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); foreach (var menu in menus) { var roleMenu1 = new RoleMenuBO().Get(this.ConnectionHandler, roleId, menu); if (roleMenu1 == null) { var roleMenu = new RoleMenu { MenuId = menu, RoleId = roleId }; if (!new RoleMenuBO().Insert(this.ConnectionHandler, roleMenu)) { throw new Exception("خطایی در ذخیره منوی نقش وجو دارد"); } } } this.ConnectionHandler.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public IEnumerable <Menu> SearchNotAddedInRole(IConnectionHandler connectionHandler, Guid roleId, string value) { var predicateBuilder = new PredicateBuilder <Menu>(); var guids = new RoleMenuBO().Select(connectionHandler, x => x.MenuId, x => x.RoleId == roleId, true); if (guids.Any()) { predicateBuilder.And(x => x.Id.NotIn(guids)); } predicateBuilder.And(x => x.Enabled); if (!string.IsNullOrEmpty(value)) { predicateBuilder.And(x => x.Url.Contains(value) || x.Title.Contains(value)); } return(this.OrderBy(connectionHandler, x => x.Title, predicateBuilder.GetExpression())); }