public IEnumerable <UserScore> GetScoresByUser(UserScoreCriteria criteria) { string sql = @"SELECT * FROM UserScore us INNER JOIN [User] u on us.UserId = u.Id WHERE us.UserId = @userId AND us.CreateTime BETWEEN @start AND @end"; return(Conn.Query <UserScore, User, UserScore>(sql, (us, u) => { us.User = u; return us; }, new { userId = criteria.RefUserId, start = criteria.StartDate, end = criteria.EndDate })); }
public ActionResult PopReward(UserScoreCriteria criteria) { IEnumerable <UserScore> scores = null; decimal total = 0.00000M; if (!criteria.StartDate.HasValue) { criteria.StartDate = DateTime.Now.AddYears(-5); } if (!criteria.EndDate.HasValue) { criteria.EndDate = DateTime.Now.AddYears(5); } if (criteria.RefUserId > 0) { scores = ur.GetUserRewardScores(criteria); } else { criteria.RefUserId = CurrentUser.Id; scores = ur.GetRefUserRewardScores(criteria); } if (criteria.TypeId > 0) { scores = scores.Where(s => s.TypeId == criteria.TypeId); } if (scores != null && scores.Any()) { total = scores.Sum(s => s.Score); } ViewBag.TotalScore = total; return(View(scores)); }
public IEnumerable <UserScore> GetRefUserRewardScores(UserScoreCriteria criteria) { string sql = @"SELECT * FROM UserScore us INNER JOIN [User] u on us.UserId = u.Id WHERE TypeId IN (4, 10, 20) AND us.UserPath LIKE @path AND us.CreateTime BETWEEN @start AND @end"; return(Conn.Query <UserScore, User, UserScore>(sql, (us, u) => { us.User = u; return us; }, new { path = criteria.RefUserId + "%", start = criteria.StartDate, end = criteria.EndDate })); }