using CZFW.Framework.Logic; using CZFW.Framework.Model.Entity; using CZKJ.GBRS2.Entity; using CZKJ.GBRS2.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CZKJ.GBRS2.Logic { public class PriceAnnouncementLogic : LogicBase, IPriceAnnouncement { public IList GetList(int typeId, DateTime? startTime, DateTime? endTime, int pageIndex, int pageSize, out int rowsCount) { IQueryable query = DbContext.Set(); if (typeId != 0) { query = query.Where(x => x.Typeofinsuance == typeId); } if (startTime.HasValue && endTime.HasValue) { query = query.Where(x => x.DateTime.Month >= startTime.Value.Month && x.DateTime.Month <= endTime.Value.Month); } rowsCount = query.Count(); var result = query.Join(DbContext.Set(), x => x.Typeofinsuance, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.DateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return result.Select(x => new PriceAnnouncementEntity { TypeName = x.Name, Id = x.x.Id, Typeofinsuance = x.x.Typeofinsuance, DateTime = x.x.DateTime, DayInterestRate = x.x.DayInterestRate, YearInterestRate = x.x.YearInterestRate, }).ToList(); } public int GetMaxYear() { var query = DbContext.Set(); var count = query.Count(); if (count > 0) { return int.Parse(DbContext.Set().Max(x => x.DateTime).ToString("yyyy")); } else { return 2015; } } public int GetMinYear() { var query = DbContext.Set(); var count = query.Count(); if (count > 0) { return int.Parse(DbContext.Set().Max(x => x.DateTime).ToString("yyyy")); } else { return 2040; } } public IList GetTableList(int? typeId, int pageIndex, int pageSize, out int rowsCount) { IQueryable query = DbContext.Set(); if (typeId.HasValue) { query = query.Where(x => x.Typeofinsuance == typeId); } rowsCount = query.Count(); var result = query.Join(DbContext.Set(), x => x.Typeofinsuance, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.DateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return result.Select(x => new PriceAnnouncementEntity { TypeName = x.Name, Id = x.x.Id, Typeofinsuance = x.x.Typeofinsuance, DateTime = x.x.DateTime, DayInterestRate = x.x.DayInterestRate, YearInterestRate = x.x.YearInterestRate, }).ToList(); } } }