Example #1
0
 //分页 获取数据条数
 public async Task <int> GetDataCount(Guid userId)
 {
     using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
     {
         return(await commodityService.GetAll().CountAsync(m => m.UserId == userId));
     }
 }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
                }
            }
        }
Example #4
0
        public async Task <List <CommodityDto> > GetAllCommodities(Guid userId, int pageIndex = 1, int pageSize = 3, bool asc = true)
        {
            using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
            {
                var list = await commodityService.GetAll(m => m.UserId == userId, 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();

                using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService())
                {
                    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);
            }
        }
Example #5
0
 public async Task <bool> ExistsCommodity(Guid commodityId)
 {
     using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
     {
         return(await commodityService.GetAll(m => m.Id == commodityId).AnyAsync());
     }
 }
Example #6
0
        public async Task EditCommodity(Guid commodityId, string title, string content, Guid[] categoryIds, string mainImg, string tbUrl)
        {
            using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
            {
                var commodity = await commodityService.GetOneByIdAsync(commodityId);

                commodity.Title     = title;
                commodity.Content   = content;
                commodity.MainImage = mainImg;
                commodity.TaobaoUrl = tbUrl;
                await commodityService.EditAsync(commodity);

                using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService())
                {
                    //删除原有类别
                    foreach (var comtocateId in comtoCategoryService.GetAll(m => m.CommodityId == commodityId))
                    {
                        await comtoCategoryService.RemoveAsync(comtocateId, false);
                    }

                    //保存现有类别
                    foreach (var categoryId in categoryIds)
                    {
                        await comtoCategoryService.CreateAsync(new ComtoCategory()
                        {
                            CategoryId  = categoryId,
                            CommodityId = commodityId
                        });
                    }

                    await comtoCategoryService.SaveAsync();
                }
            }
        }
Example #7
0
        //商品操作
        public async Task CreateCommodity(string title, string content, Guid[] categoryIds, Guid userId, string mainImg, string tbUrl)
        {
            using (IDAL.ICommodityService comSvc = new DAL.CommodityService())
            {
                Commodity commodity = new Commodity()
                {
                    Title     = title,
                    Content   = content,
                    UserId    = userId,
                    MainImage = mainImg,
                    TaobaoUrl = tbUrl
                };
                await comSvc.CreateAsync(commodity);

                Guid commodityId = commodity.Id;

                using (IDAL.IComtoCategoryService comtoSvc = new DAL.ComtoCategoryService())
                {
                    foreach (var categoryId in categoryIds)
                    {
                        await comtoSvc.CreateAsync(new ComtoCategory()
                        {
                            CommodityId = commodityId,
                            CategoryId  = categoryId
                        }, false);
                    }

                    await comtoSvc.SaveAsync();
                }
            }
        }
Example #8
0
        public async Task RemoveCommodity(Guid commodityId)
        {
            using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
            {
                var commodity = await commodityService.GetOneByIdAsync(commodityId);

                await commodityService.RemoveAsync(commodity);
            }
        }
Example #9
0
        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);
            }
        }
Example #10
0
        public async Task BadCount(Guid commodityId)
        {
            using (IDAL.ICommodityService commodityService = new DAL.CommodityService())
            {
                var commodity = await commodityService.GetOneByIdAsync(commodityId);

                commodity.BadCount++;
                await commodityService.EditAsync(commodity);
            }
        }
Example #11
0
        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
                    });
                }
            }
        }