コード例 #1
0
ファイル: GoodsController.cs プロジェクト: xiaopohou/YoShop
        public async Task <IActionResult> Edit(SellerGoodsRequest request, uint id)
        {
            var goods = await _fsql.Select <Goods>().Where(c => c.GoodsId == id).ToOneAsync();

            if (goods == null)
            {
                return(NoOrDeleted());
            }
            try
            {
                request.GoodsId    = goods.GoodsId;
                request.WxappId    = goods.WxappId;
                request.CreateTime = goods.CreateTime.ConvertToDateTime();
                request.UpdateTime = DateTime.Now;

                // 更新商品
                var model = request.Mapper <Goods>();
                await _fsql.Update <Goods>().SetSource(model).ExecuteAffrowsAsync();

                // 更新图片
                await _fsql.Delete <GoodsImage>().Where(l => l.GoodsId == goods.GoodsId).ExecuteAffrowsAsync();

                var goodsImages = request.BuildGoodsImages(goods.GoodsId);
                if (goodsImages != null && goodsImages.Any())
                {
                    await _fsql.Insert <GoodsImage>().AppendData(goodsImages).ExecuteAffrowsAsync();
                }
                // 更新规格
                await _fsql.Delete <GoodsSpec>().Where(l => l.GoodsId == goods.GoodsId).ExecuteAffrowsAsync();

                await _fsql.Delete <GoodsSpecRel>().Where(l => l.GoodsId == goods.GoodsId).ExecuteAffrowsAsync();

                if (request.SpecType == SpecType.单规格)
                {
                    var goodsSpec = request.BuildGoodsSpec(goods.GoodsId);
                    await _fsql.Insert <GoodsSpec>().AppendData(goodsSpec).ExecuteAffrowsAsync();
                }
                else
                {
                    var goodsSpecs = request.BuildGoodsSpecs(goods.GoodsId);
                    await _fsql.Insert <GoodsSpec>().AppendData(goodsSpecs).ExecuteAffrowsAsync();

                    var goodsSpecRels = request.BuildGoodsSpecRels(goods.GoodsId);
                    await _fsql.Insert <GoodsSpecRel>().AppendData(goodsSpecRels).ExecuteAffrowsAsync();
                }
            }
            catch (Exception e)
            {
                LogManager.Error(GetType(), e);
                return(No(e.Message));
            }
            return(YesRedirect("编辑成功!", "/goods/index"));
        }
コード例 #2
0
ファイル: GoodsController.cs プロジェクト: xiaopohou/YoShop
        public async Task <IActionResult> Add(SellerGoodsRequest request)
        {
            request.WxappId    = GetSellerSession().WxappId;
            request.CreateTime = DateTime.Now;
            request.UpdateTime = DateTime.Now;

            try
            {
                // 保存商品
                var goods   = request.Mapper <Goods>();
                var goodsId = await _fsql.Insert <Goods>().AppendData(goods).ExecuteIdentityAsync();

                // 保存图片
                var goodsImages = request.BuildGoodsImages((uint)goodsId);
                if (goodsImages != null && goodsImages.Any())
                {
                    await _fsql.Insert <GoodsImage>().AppendData(goodsImages).ExecuteAffrowsAsync();
                }
                // 保存规格
                if (request.SpecType == SpecType.单规格)
                {
                    var goodsSpec = request.BuildGoodsSpec((uint)goodsId);
                    await _fsql.Insert <GoodsSpec>().AppendData(goodsSpec).ExecuteAffrowsAsync();
                }
                else
                {
                    var goodsSpecs = request.BuildGoodsSpecs((uint)goodsId);
                    await _fsql.Insert <GoodsSpec>().AppendData(goodsSpecs).ExecuteAffrowsAsync();

                    var goodsSpecRels = request.BuildGoodsSpecRels((uint)goodsId);
                    await _fsql.Insert <GoodsSpecRel>().AppendData(goodsSpecRels).ExecuteAffrowsAsync();
                }
            }
            catch (Exception e)
            {
                LogManager.Error(GetType(), e);
                return(No(e.Message));
            }
            return(YesRedirect("添加成功!", "/goods/index"));
        }