コード例 #1
0
        public BaseListResponse <ProvideHelpDto> Search(ProvideHelpQuery query)
        {
            var response = new BaseListResponse <ProvideHelpDto>();

            try
            {
                int count        = 0;
                var provideHelps = _repository.Search(query, out count);
                response.TotalItems = count;
                response.PageIndex  = query.PageIndex;
                response.PageSize   = query.PageSize;

                ProvideHelp fake = new ProvideHelp();
                string[]    excludeProperties =
                {
                    TypeHelper.GetPropertyName(() => fake.Id)
                };

                var provideHelpDtos = MapperUtils.ConvertToList <ProvideHelp, ProvideHelpDto>(provideHelps, excludeProperties);

                if (provideHelpDtos != null)
                {
                    foreach (var dto in provideHelpDtos)
                    {
                        // tinh so ngay sap complete (ngay lai~ sap do? vao BI Balance)
                        double daysStartTransferBI = (dto.StartDate - dto.CreateDate).TotalDays;
                        double daysPassed          = (DateTime.Now - dto.CreateDate).TotalDays;
                        dto.DaysPassed = (int)daysPassed;

                        if (daysPassed >= daysStartTransferBI)
                        {
                            dto.PercentComplete = 100;
                        }
                        else
                        {
                            dto.PercentComplete = (int)((daysPassed / daysStartTransferBI) * 100);
                        }

                        // tinh so tien BI da kiem duoc
                        dto.EarningBIAmount = CommonUtils.FoatBTCAmount(dto.ProfitRate * dto.BTCAmount * daysPassed);
                    }
                }

                response.Data = provideHelpDtos;
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
            }

            return(response);
        }
コード例 #2
0
        public List <ProvideHelp> Search(ProvideHelpQuery query, out int count)
        {
            var limit = query.PageSize;
            var start = (query.PageIndex - 1) * limit;

            IQueryable <ProvideHelp> linqQuery = this.Table();

            if (!string.IsNullOrWhiteSpace(query.Username))
            {
                linqQuery = linqQuery.Where(x => x.Username == query.Username);
            }

            if (query.Status != -1)
            {
                linqQuery = linqQuery.Where(x => x.Status == query.Status);
            }

            if (!string.IsNullOrWhiteSpace(query.FromDate))
            {
                DateTime fromDate = DateTime.Now;
                bool     isDate   = CommonUtils.ToDate(query.FromDate, out fromDate);
                if (isDate)
                {
                    linqQuery = linqQuery.Where(x => x.CreateDate.Date.CompareTo(fromDate.Date) >= 0);
                }
            }


            if (!string.IsNullOrWhiteSpace(query.ToDate))
            {
                DateTime toDate = DateTime.Now;
                bool     isDate = CommonUtils.ToDate(query.ToDate, out toDate);
                if (isDate)
                {
                    linqQuery = linqQuery.Where(x => x.CreateDate.Date.CompareTo(toDate.Date) <= 0);
                }
            }

            count = linqQuery.Count();

            linqQuery = linqQuery.OrderByDescending(x => x.CreateDate).ThenBy(x => x.CreateDate.TimeOfDay);

            linqQuery = linqQuery.Skip(start).Take(limit);
            return(linqQuery.ToList());
        }