コード例 #1
0
ファイル: CommodityManager.cs プロジェクト: weqan/NewWq
        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();
                }
            }
        }
コード例 #2
0
ファイル: CommodityManager.cs プロジェクト: weqan/NewWq
        //商品操作
        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();
                }
            }
        }
コード例 #3
0
ファイル: CommodityManager.cs プロジェクト: weqan/NewWq
        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();
            }
        }