public async Task <List <CommodityDto> > GetAllCommoditiesByCateId(string categoryId) { List <CommodityDto> list = new List <CommodityDto>(); using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService()) { if (!string.IsNullOrWhiteSpace(categoryId)) { Guid catId = Guid.Parse(categoryId); List <Guid> comtocateList = await comtoCategoryService.GetAll(m => m.CategoryId == catId).Select(m => m.CommodityId).ToListAsync(); list = await commodityService.GetAll(m => comtocateList.Contains(m.Id)).Include(m => m.User).Select(m => new Dto.CommodityDto() { Title = m.Title, Content = m.Content, GoodCount = m.GoodCount, BadCount = m.BadCount, CreateTime = m.CreateTime, Id = m.Id, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl, Email = m.User.Email, ImagePath = m.User.ImagePath }).ToListAsync(); } else { list = await commodityService.GetAll(m => true).Include(m => m.User).Select(m => new Dto.CommodityDto() { Title = m.Title, Content = m.Content, GoodCount = m.GoodCount, BadCount = m.BadCount, CreateTime = m.CreateTime, Id = m.Id, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl, Email = m.User.Email, ImagePath = m.User.ImagePath }).ToListAsync(); } foreach (var item in list) { var cates = await comtoCategoryService.GetAll(m => m.CommodityId == item.Id).Include(m => m.Category).ToListAsync(); item.CategoryIds = cates.Select(m => m.CategoryId).ToArray(); item.CategoryNames = cates.Select(m => m.Category.CategoryName).ToArray(); } } return(list); } }
public async Task <List <CommodityDto> > GetAllCommoditiesByCateId(Guid?categoryId, int pageIndex = 1, int pageSize = 3, bool asc = true) { List <CommodityDto> list = new List <CommodityDto>(); using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService()) { if (categoryId != null) { List <Guid> comtocateList = await comtoCategoryService.GetAll(m => m.CategoryId == categoryId.Value).Select(m => m.CommodityId).ToListAsync(); list = await commodityService.GetAll(m => comtocateList.Contains(m.Id), asc, pageSize, pageIndex).Include(m => m.User).Select(m => new Dto.CommodityDto() { Title = m.Title, Content = m.Content, GoodCount = m.GoodCount, BadCount = m.BadCount, CreateTime = m.CreateTime, Id = m.Id, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl, Email = m.User.Email, ImagePath = m.User.ImagePath }).ToListAsync(); } else { list = await commodityService.GetAll(m => true, asc, pageSize, pageIndex).Include(m => m.User).Select(m => new Dto.CommodityDto() { Title = m.Title, Content = m.Content, GoodCount = m.GoodCount, BadCount = m.BadCount, CreateTime = m.CreateTime, Id = m.Id, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl, Email = m.User.Email, ImagePath = m.User.ImagePath }).ToListAsync(); } foreach (var item in list) { var cates = await comtoCategoryService.GetAll(m => m.CommodityId == item.Id).Include(m => m.Category).ToListAsync(); item.CategoryIds = cates.Select(m => m.CategoryId).ToArray(); item.CategoryNames = cates.Select(m => m.Category.CategoryName).ToArray(); } } return(list); } }
//分页 获取数据条数 public async Task <int> GetDataCount(Guid userId) { using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { return(await commodityService.GetAll().CountAsync(m => m.UserId == userId)); } }
public async Task <CommodityDto> GetOneCommodityById(Guid commodityId) { using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { var data = await commodityService.GetAll(m => m.Id == commodityId, false).Include(m => m.User).Select(m => new Dto.CommodityDto() { Id = m.Id, Title = m.Title, Content = m.Content, CreateTime = m.CreateTime, Email = m.User.Email, GoodCount = m.GoodCount, BadCount = m.BadCount, ImagePath = m.User.ImagePath, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl, }).FirstAsync(); using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService()) { var cates = await comtoCategoryService.GetAll(m => m.CommodityId == data.Id).Include(m => m.Category).ToListAsync(); data.CategoryIds = cates.Select(m => m.CategoryId).ToArray(); data.CategoryNames = cates.Select(m => m.Category.CategoryName).ToArray(); return(data); } } }
public async Task <List <CommodityDto> > GetAllCommodities(int count) { using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { var list = await commodityService.GetAll(m => true, false).Take(count).Include(m => m.User).Select(m => new CommodityDto() { Id = m.Id, Title = m.Title, Content = m.Content, CreateTime = m.CreateTime, Email = m.User.Email, GoodCount = m.GoodCount, BadCount = m.BadCount, ImagePath = m.User.ImagePath, MainImage = m.MainImage, TaobaoUrl = m.TaobaoUrl }).ToListAsync(); using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService()) { foreach (var item in list) { var contocates = await comtoCategoryService.GetAll(m => m.CommodityId == item.Id).Include(m => m.Category).ToListAsync(); item.CategoryIds = contocates.Select(m => m.CategoryId).ToArray(); item.CategoryNames = contocates.Select(m => m.Category.CategoryName).ToArray(); } } return(list); } }
public async Task <bool> ExistsCommodity(Guid commodityId) { using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { return(await commodityService.GetAll(m => m.Id == commodityId).AnyAsync()); } }
public async Task <NextPrevDto> BeforeOne(Guid comid) { var commodity = await GetOneCommodityById(comid); using (IDAL.ICommodityService commodityService = new DAL.CommodityService()) { var comNext = await commodityService.GetAll(m => m.CreateTime < commodity.CreateTime).FirstOrDefaultAsync(); if (comNext == null) { return(null); } else { return(new NextPrevDto() { Id = comNext.Id, Title = comNext.Title }); } } }