예제 #1
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();
                }
            }
        }
예제 #2
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();
                }
            }
        }