コード例 #1
0
 public static async Task <int> FetchNumOfApplicationsAsync(int period)
 {
     using (var cmd = new SqlCommand(SelectNumOfApplications))
     {
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.AddWithValue("@Period", period);
         return(Convert.ToInt32(await DbHelper.ExecuteScalarAsync(!(await RedisHelper.GetZeroActivityApplyCacheOnPeriod(period)), cmd)));
     }
 }
コード例 #2
0
 public static async Task <bool> HasZeroActivityApplicationSubmittedAsync(Guid userId, int period)
 {
     using (var cmd = new SqlCommand(NumOfZeroActivityApplications))
     {
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.AddWithValue("@UserID", userId);
         cmd.Parameters.AddWithValue("@Period", period);
         return(Convert.ToInt32(await DbHelper.ExecuteScalarAsync(!(await RedisHelper.GetZeroActivityApplyCacheOnPeriod(period)) || !(await RedisHelper.GetZeroActivityApplyCacheOnUserId(userId)), cmd)) > 0);
     }
 }
コード例 #3
0
        public static async Task <IEnumerable <SelectedTestReport> > SelectChosenUserReportsAsync(int period)
        {
            using (var cmd = new SqlCommand(SelectChosenUserReports))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@Period", period);
                return(await DbHelper.ExecuteQueryAsync(!(await RedisHelper.GetZeroActivityApplyCacheOnPeriod(period)), cmd, (dt) =>
                {
                    var result = new List <SelectedTestReport>();
                    if (dt?.Rows?.OfType <DataRow>() == null || !dt.Rows.OfType <DataRow>().Any())
                    {
                        return result;
                    }
                    foreach (var dr in dt.Rows.OfType <DataRow>())
                    {
                        if (dr != null)
                        {
                            var testReport = new SelectedTestReport();
                            if (!(dr["UserID"] is DBNull))
                            {
                                testReport.UserId = new Guid(dr["UserID"].ToString());
                            }

                            if (!(dr["CommentStatus"] is DBNull) && Convert.ToInt32(dr["CommentStatus"]) == 2 && !(dr["CommentType"] is DBNull) && Convert.ToInt32(dr["CommentType"]) == 3)
                            {
                                if (!(dr["CommentId"] is DBNull))
                                {
                                    testReport.CommentId = Convert.ToInt32(dr["CommentId"]);
                                }
                                testReport.ReportTitle = dr["SingleTitle"]?.ToString();
                                testReport.ReportAbstract = (dr["CommentContent"]?.ToString() != null && dr["CommentContent"].ToString().Length > 100)
                                                               ? dr["CommentContent"].ToString().Substring(0, 100) : dr["CommentContent"]?.ToString();
                                if (!(dr["CreateTime"] is DBNull))
                                {
                                    testReport.ReportCreateTime = Convert.ToDateTime(dr["CreateTime"]);
                                }
                                if (!(dr["CommentImages"] is DBNull) && !string.IsNullOrWhiteSpace(dr["CommentImages"].ToString()))
                                {
                                    testReport.ReportImages = dr["CommentImages"].ToString().Split(';');
                                }
                            }
                            result.Add(testReport);
                        }
                    }
                    return result.GroupBy(_ => _.UserId).Select(_ => _.OrderByDescending(ur => ur.CommentId == null ? 0 : 1).FirstOrDefault()).Where(_ => _ != null).ToList();
                }));
            }
        }