示例#1
0
        /// <summary>
        /// The simple list.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="startId">
        /// The start id.
        /// </param>
        /// <param name="limit">
        /// The limit.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public static List <Topic> SimpleList(this IRepository <Topic> repository, [CanBeNull] int startId = 0, [CanBeNull] int limit = 500)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.Get(t => t.ID >= limit && t.ID < startId + limit).OrderBy(t => t.ID).ToList());
        }
示例#2
0
        /// <summary>
        /// The get password hash async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual async Task <string> GetPasswordHashAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(await Task.FromResult(user.PasswordHash));
        }
示例#3
0
        /// <summary>
        /// The get email confirmed async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual async Task <bool> GetEmailConfirmedAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(await Task.FromResult(user.EmailConfirmed));
        }
        /// <summary>
        /// The add or update.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="userID">
        /// The user id.
        /// </param>
        /// <param name="topicID">
        /// The topic id.
        /// </param>
        public static void AddOrUpdate(this IRepository <TopicReadTracking> repository, int userID, int topicID)
        {
            CodeContracts.VerifyNotNull(repository);

            repository.DbFunction.Query.readtopic_addorupdate(UserID: userID, TopicID: topicID, UTCTIMESTAMP: DateTime.UtcNow);
        }
示例#5
0
        /// <summary>
        /// The delete async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual Task DeleteAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(Task.FromResult(this.GetRepository <AspNetUsers>().Delete(u => u.Id == user.Id)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardModuleManager{TModule}"/> class.
        /// </summary>
        /// <param name="modules">
        /// The modules.
        /// </param>
        public StandardModuleManager([NotNull] IEnumerable <TModule> modules)
        {
            CodeContracts.VerifyNotNull(modules, "modules");

            this._modules = modules.ToList();
        }
示例#7
0
        /// <summary>
        /// The resync.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        public static void Resync(this IRepository <Board> repository, int?boardID = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            repository.DbFunction.Query.board_resync(BoardID: boardID);
        }
示例#8
0
        /// <summary>
        /// Deletes all unapproved users older than x days
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        /// <param name="days">
        /// The days.
        /// </param>
        public static void DeleteOld(this IRepository <User> repository, [NotNull] int boardID, [NotNull] int days)
        {
            CodeContracts.VerifyNotNull(repository);

            repository.DbFunction.Scalar.user_deleteold(BoardID: boardID, Days: days, UTCTIMESTAMP: DateTime.UtcNow);
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CurrentTaskModuleProvider"/> class.
        /// </summary>
        /// <param name="httpApplicationState">
        /// The http application state.
        /// </param>
        public CurrentTaskModuleProvider([NotNull] HttpApplicationStateBase httpApplicationState)
        {
            CodeContracts.VerifyNotNull(httpApplicationState, "httpApplicationState");

            this._httpApplicationState = httpApplicationState;
        }
示例#10
0
        public static int Delete <T>([NotNull] this IRepository <T> repository, Expression <Func <T, bool> > criteria) where T : class, IEntity, new()
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbAccess.Execute(db => db.Connection.Delete(criteria)));
        }
示例#11
0
        /// <summary>
        /// Approves all unapproved users
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        public static void ApproveAll(this IRepository <User> repository, [NotNull] int boardID)
        {
            CodeContracts.VerifyNotNull(repository);

            repository.DbFunction.Scalar.user_approveall(BoardID: boardID);
        }
示例#12
0
        /// <summary>
        /// Gets a single entity by its ID.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <typeparam name="T">
        /// The type parameter.
        /// </typeparam>
        /// <returns>
        /// The <see cref="T"/> .
        /// </returns>
        public static T GetById <T>([NotNull] this IRepository <T> repository, int id) where T : IEntity, IHaveID, new()
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbAccess.Execute(db => db.Connection.SingleById <T>(id)));
        }
示例#13
0
        /// <summary>
        /// The delete async.
        /// </summary>
        /// <param name="role">
        /// The role.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual Task DeleteAsync([NotNull] AspNetRoles role)
        {
            CodeContracts.VerifyNotNull(role);

            return(Task.FromResult(0));
        }
示例#14
0
        private static byte[] Hash([NotNull] byte[] clearBytes, [NotNull] HashAlgorithmType hashAlgorithmType)
        {
            CodeContracts.ArgumentNotNull(clearBytes, "clearBytes");

            return(HashAlgorithm.Create(hashAlgorithmType.GetStringValue()).ComputeHash(clearBytes));
        }
示例#15
0
        public static IEnumerable <T> FindControlType <T>([NotNull] this Control sourceControl)
        {
            CodeContracts.ArgumentNotNull(sourceControl, "sourceControl");

            return(sourceControl.Controls.OfType <T>());
        }
        /// <summary>
        /// Gets the Current DB Version Name
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <returns>
        /// Returns the Current DB Version Name
        /// </returns>
        public static string GetDbVersionName(this IRepository <Registry> repository)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.GetSingle(r => r.Name.ToLower() == "versionname").Value);
        }
        /// <summary>
        /// Get an instance of a module (based on it's id).
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// Instance of TModule or null if not found.
        /// </returns>
        public TModule GetBy([NotNull] string id)
        {
            CodeContracts.VerifyNotNull(id, "id");

            return(this._modules.SingleOrDefault(e => e.ModuleId.Equals(id)));
        }
        /// <summary>
        /// Gets the user signature.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>Returns the user points</returns>
        public static string GetSignature(this IRepository <User> repository, int userId)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.GetById(userId).Signature);
        }
示例#19
0
        /// <summary>
        /// The list.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/>.
        /// </returns>
        public static DataTable List(this IRepository <Board> repository, int?boardID = null)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.board_list(BoardID: boardID));
        }
        /// <summary>
        /// Gets the user points.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>Returns the user points</returns>
        public static int GetPoints(this IRepository <User> repository, int userId)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.GetById(userId).Points);
        }
示例#21
0
        /// <summary>
        /// The userstats.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="boardID">
        /// The board id.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/>.
        /// </returns>
        public static DataRow Userstats(this IRepository <Board> repository, int?boardID)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(((DataTable)repository.DbFunction.GetData.board_userstats(BoardID: boardID)).Rows[0]);
        }
        protected IEnumerable <SearchCondition> BuildWhatConditions(
            [NotNull] string toSearchWhat,
            SearchWhatFlags searchWhatMethod,
            [NotNull] string dbField,
            bool useFullText)
        {
            CodeContracts.VerifyNotNull(toSearchWhat, "toSearchWhat");
            CodeContracts.VerifyNotNull(dbField, "dbField");

            toSearchWhat = toSearchWhat.Replace("'", "''").Trim();

            var conditions = new List <SearchCondition>();

            var conditionType = SearchConditionType.AND;

            if (searchWhatMethod == SearchWhatFlags.AnyWords)
            {
                conditionType = SearchConditionType.OR;
            }

            var wordList = new List <string> {
                toSearchWhat
            };

            if (searchWhatMethod == SearchWhatFlags.AllWords || searchWhatMethod == SearchWhatFlags.AnyWords)
            {
                wordList =
                    toSearchWhat.Replace(@"""", string.Empty)
                    .Split(' ')
                    .Where(x => x.IsSet())
                    .Select(x => x.Trim())
                    .ToList();
            }

            if (useFullText)
            {
                var list = new List <SearchCondition>();

                list.AddRange(
                    wordList.Select(
                        word =>
                        new SearchCondition
                {
                    Condition     = @"""{0}""".FormatWith(word),
                    ConditionType = conditionType
                }));

                conditions.Add(
                    new SearchCondition
                {
                    Condition =
                        "CONTAINS ({1}, N' {0} ')".FormatWith(list.BuildSql(false), dbField),
                    ConditionType = conditionType
                });
            }
            else
            {
                conditions.AddRange(
                    wordList.Select(
                        word =>
                        new SearchCondition
                {
                    Condition     = "{1} LIKE N'%{0}%'".FormatWith(word, dbField),
                    ConditionType = conditionType
                }));
            }

            return(conditions);
        }
示例#23
0
        public static int GetDBSize([NotNull] this IDbFunction dbFunction)
        {
            CodeContracts.VerifyNotNull(dbFunction, "dbFunction");

            return(dbFunction.ValidateAndExecute <int>("DBSize", f => f.GetScalar <int>(s => s.DBSize())));
        }
        protected IEnumerable <SearchCondition> BuildWhoConditions(
            [NotNull] string toSearchFromWho,
            SearchWhatFlags searchFromWhoMethod,
            bool searchDisplayName)
        {
            CodeContracts.VerifyNotNull(toSearchFromWho, "toSearchFromWho");

            toSearchFromWho = toSearchFromWho.Replace("'", "''").Trim();

            var conditions = new List <SearchCondition>();

            var conditionType = SearchConditionType.AND;

            if (searchFromWhoMethod == SearchWhatFlags.AnyWords)
            {
                conditionType = SearchConditionType.OR;
            }

            var wordList = new List <string> {
                toSearchFromWho
            };

            if (searchFromWhoMethod == SearchWhatFlags.AllWords || searchFromWhoMethod == SearchWhatFlags.AnyWords)
            {
                wordList =
                    toSearchFromWho.Replace(@"""", string.Empty)
                    .Split(' ')
                    .Where(x => x.IsSet())
                    .Select(x => x.Trim())
                    .ToList();
            }

            foreach (string word in wordList)
            {
                int userId;

                string conditionSql;
                if (int.TryParse(word, out userId))
                {
                    conditionSql = "c.UserID IN ({0})".FormatWith(userId);
                }
                else
                {
                    if (searchFromWhoMethod == SearchWhatFlags.ExactMatch)
                    {
                        conditionSql =
                            "(c.Username IS NULL AND b.{1} = N'{0}') OR (c.Username = N'{0}')".FormatWith(
                                word,
                                searchDisplayName ? "DisplayName" : "Name");
                    }
                    else
                    {
                        conditionSql =
                            "(c.Username IS NULL AND b.{1} LIKE N'%{0}%') OR (c.Username LIKE N'%{0}%')".FormatWith(
                                word,
                                searchDisplayName ? "DisplayName" : "Name");
                    }
                }

                conditions.Add(new SearchCondition {
                    Condition = conditionSql, ConditionType = conditionType
                });
            }

            return(conditions);
        }
示例#25
0
        /// <summary>
        /// The update async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual Task UpdateAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(this.UpdateUser(user));
        }
        /// <summary>
        /// Builds the search SQL.
        /// </summary>
        /// <param name="context">The search context.</param>
        /// <returns>Returns the full SQL script</returns>
        public string BuildSearchSql([NotNull] ISearchContext context)
        {
            CodeContracts.VerifyNotNull(context, "context");

            var builtStatements = new List <string>();

            if (context.MaxResults > 0)
            {
                builtStatements.Add("SET ROWCOUNT {0};".FormatWith(context.MaxResults));
            }

            string searchSql =
                "SELECT a.ForumID, a.TopicID, a.Topic, b.UserID, IsNull(c.Username, b.Name) as Name, c.MessageID, c.Posted, [Message] = '', c.Flags ";

            searchSql +=
                "\r\nfrom {databaseOwner}.{objectQualifier}topic a left join {databaseOwner}.{objectQualifier}message c on a.TopicID = c.TopicID left join {databaseOwner}.{objectQualifier}user b on c.UserID = b.UserID join {databaseOwner}.{objectQualifier}vaccess x on x.ForumID=a.ForumID ";
            searchSql +=
                "\r\nwhere x.ReadAccess<>0 AND x.UserID={0} AND c.IsApproved = 1 AND a.TopicMovedID IS NULL AND a.IsDeleted = 0 AND c.IsDeleted = 0"
                .FormatWith(context.UserID);

            if (context.ForumIDs.Any())
            {
                searchSql += " AND a.ForumID IN ({0})".FormatWith(context.ForumIDs.ToDelimitedString(","));
            }

            if (context.ToSearchFromWho.IsSet())
            {
                searchSql +=
                    "\r\nAND ({0})".FormatWith(
                        this.BuildWhoConditions(
                            context.ToSearchFromWho,
                            context.SearchFromWhoMethod,
                            context.SearchDisplayName).BuildSql(true));
            }

            if (context.ToSearchWhat.IsSet())
            {
                if (!context.SearchTitleOnly)
                {
                    builtStatements.Add(searchSql);

                    builtStatements.Add(
                        "AND ({0})".FormatWith(
                            this.BuildWhatConditions(
                                context.ToSearchWhat,
                                context.SearchWhatMethod,
                                "c.Message",
                                context.UseFullText).BuildSql(true)));

                    builtStatements.Add("UNION");
                }

                builtStatements.Add(searchSql);

                builtStatements.Add(
                    "AND ({0})".FormatWith(
                        this.BuildWhatConditions(
                            context.ToSearchWhat,
                            context.SearchWhatMethod,
                            "a.Topic",
                            context.UseFullText).BuildSql(true)));
            }
            else
            {
                builtStatements.Add(searchSql);
            }

            builtStatements.Add("ORDER BY c.Posted DESC");

            string builtSql = builtStatements.ToDelimitedString("\r\n");

            Debug.WriteLine("Build Sql: [{0}]".FormatWith(builtSql));

            return(builtSql);
        }
示例#27
0
        /// <summary>
        /// The get security stamp async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual async Task <string> GetSecurityStampAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(await Task.FromResult(user.SecurityStamp));
        }
示例#28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadPageVariablesFromQuery"/> class.
        /// </summary>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        public LoadPageVariablesFromQuery([NotNull] IServiceLocator serviceLocator)
        {
            CodeContracts.ArgumentNotNull(serviceLocator, "serviceLocator");

            this.ServiceLocator = serviceLocator;
        }
示例#29
0
        /// <summary>
        /// The get phone number async.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual async Task <string> GetPhoneNumberAsync([NotNull] AspNetUsers user)
        {
            CodeContracts.VerifyNotNull(user);

            return(await Task.FromResult(user.PhoneNumber));
        }
示例#30
0
        /// <summary>
        /// The simple list as data table.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="startId">
        /// The start id.
        /// </param>
        /// <param name="limit">
        /// The limit.
        /// </param>
        /// <returns>
        /// The <see cref="DataTable"/>.
        /// </returns>
        public static DataTable SimpleListAsDataTable(this IRepository <Topic> repository, [CanBeNull] int startId = 0, [CanBeNull] int limit = 500)
        {
            CodeContracts.VerifyNotNull(repository, "repository");

            return(repository.DbFunction.GetData.topic_simplelist(StartID: startId, Limit: limit));
        }