public IEnumerable <Menu> SearchNotAddedInUser(IConnectionHandler connectionHandler, Guid userId, string value) { var predicateBuilder = new PredicateBuilder <Menu>(); var guids = new UserMenuBO().Select(connectionHandler, x => x.MenuId, x => x.UserId == userId, 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())); }
public bool AddMenu(Guid userId, List <Guid> menulist) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var userMenuBO = new UserMenuBO(); foreach (var guid in menulist) { var userMenu = userMenuBO.Get(this.ConnectionHandler, userId, guid); if (userMenu == null) { var userOperation = new UserMenu { UserId = userId, MenuId = guid }; if (!userMenuBO.Insert(this.ConnectionHandler, userOperation)) { 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); } }