Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 public async Task <List <ComtoCategoryDto> > GetAllCategoryIdsByCommodityId(Guid commodityId)
 {
     using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService())
     {
         return(await comtoCategoryService.GetAll(m => m.CommodityId == commodityId).Select(m => new ComtoCategoryDto()
         {
             CategoryId = m.CategoryId,
             CommodityId = m.CommodityId
         }).ToListAsync());
     }
 }
Ejemplo n.º 8
0
        public async Task DeleteAllCategoryIdsByCommodityId(Guid commodityId)
        {
            using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService())
            {
                var comList = comtoCategoryService.GetAll(m => m.CommodityId == commodityId);
                foreach (var item in comList)
                {
                    await comtoCategoryService.RemoveAsync(item, false);
                }

                await comtoCategoryService.SaveAsync();
            }
        }
Ejemplo n.º 9
0
 public async Task <int> GetComCount(Guid?cateId)
 {
     using (IDAL.IComtoCategoryService comtoCategoryService = new DAL.ComtoCategoryService())
     {
         if (cateId == null)
         {
             return(await comtoCategoryService.GetAll().Select(m => m.CommodityId).Distinct().CountAsync());
         }
         else
         {
             return(await comtoCategoryService.GetAll(m => m.CategoryId == cateId.Value).CountAsync());
         }
     }
 }