示例#1
0
        private string Where(WhisperCondiiton condition, ref DynamicParameters dynamicParameters)
        {
            IList <string> sqlList = new List <string>();

            if (condition != null)
            {
                if (!string.IsNullOrEmpty(condition.Account))
                {
                    dynamicParameters.Add("Account", condition.Account);
                    sqlList.Add("whisper_account = @Account");
                }
                if (condition.IsPassing.HasValue)
                {
                    dynamicParameters.Add("IsPassing", condition.IsPassing.Value, DbType.Boolean);
                    sqlList.Add("whisper_ispassing = @IsPassing");
                }
                if (condition.Id.HasValue)
                {
                    dynamicParameters.Add("id", condition.Id.Value);
                    sqlList.Add("whisper_id = @id");
                }
            }
            sqlList.Add(" 1=1 ");
            string sql = string.Join(" AND ", sqlList);

            return(sql);
        }
示例#2
0
        public int SelectCount(WhisperCondiiton condiiton = null)
        {
            DynamicParameters parameters = new DynamicParameters();

            string where = Where(condiiton, ref parameters);
            string sql = "SELECT COUNT(*) FROM T_Whisper WHERE " + where;

            return(DbConnection.ExecuteScalar <int>(sql, parameters));
        }
示例#3
0
        private WhisperCondiiton ConvertCondition(WhisperConditionModel whisperCondition)
        {
            WhisperCondiiton condiiton = new WhisperCondiiton();

            condiiton.Account = whisperCondition.Account;
            if (whisperCondition.Id != 0)
            {
                condiiton.Id = whisperCondition.Id;
            }
            return(condiiton);
        }
示例#4
0
        public ApiResult LoadTotal([FromBody] WhisperConditionModel whisperConditionModel)
        {
            WhisperCondiiton whisperCondiiton = new WhisperCondiiton();

            if (whisperConditionModel.LoginUser)
            {
                whisperCondiiton.Account = Auth.GetLoginUser(_httpContext).Account;
            }
            else
            {
                whisperCondiiton.Account = whisperCondiiton.Account;
            }
            int total = _whisperRepository.SelectCount(whisperCondiiton);

            return(ApiResult.Success(total));
        }
示例#5
0
        public IEnumerable <Whisper> SelectByPage(int pageIndex, int pageSize, WhisperCondiiton condiiton = null)
        {
            int pageId = pageSize * (pageIndex - 1);
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("pageId", pageId, DbType.Int32);
            parameters.Add("pageSize", pageSize, DbType.Int32);
            string where = Where(condiiton, ref parameters);
            string sql = "SELECT w.*,u.user_username " +
                         "FROM T_Whisper  w INNER JOIN T_User u on w.whisper_account=u.user_account  WHERE " +
                         where + " ORDER BY whisper_createtime DESC LIMIT @pageId,@pageSize";
            IEnumerable <dynamic> dynamics     = Select(sql, parameters);
            IList <Whisper>       whispers     = new List <Whisper>();
            List <string>         commentGuids = new List <string>();

            foreach (var d in dynamics)
            {
                Whisper whisper = new Whisper(
                    d.whisper_id
                    , d.whisper_account
                    , d.user_username
                    , d.whisper_content
                    , Convert.ToBoolean(d.whisper_ispassing)
                    , (string)d.whisper_commentguids
                    , d.whisper_createtime);
                whispers.Add(whisper);
                commentGuids.AddRange(Whisper.GetCommentGuidList(whisper));
            }
            IList <Comment> comments = _commentRepository.SelectByIds(commentGuids);
            IList <Whisper> list     = new List <Whisper>();

            foreach (var item in whispers)
            {
                commentGuids = Whisper.GetCommentGuidList(item).ToList();
                Whisper whisper = new Whisper(
                    item.Id
                    , item.Account
                    , item.AccountName
                    , item.Content
                    , item.IsPassing
                    , item.CommentGuids
                    , comments.Where(s => commentGuids.Contains(s.Guid)).ToList()
                    , item.CreateTime.Value);
                list.Add(whisper);
            }
            return(list);
        }
示例#6
0
        public int SelectCount(WhisperConditionModel conditionModel = null)
        {
            WhisperCondiiton condiiton = ConvertCondition(conditionModel);

            return(_whisperRepository.SelectCount(condiiton));
        }