Пример #1
0
        public async Task <IActionResult> Save([FromBody] GoodsModel goods)
        {
            if (goods == null)
            {
                return(BadRequest());
            }

            //处理商品主图
            if (!string.IsNullOrEmpty(goods.picture))
            {
                goods.picture = ParseUploadFile(goods.picture);
            }
            //处理附件
            if (goods.downloads != null && goods.downloads.Any())
            {
                foreach (var item in goods.downloads)
                {
                    item.url = ParseUploadFile(item.url);
                }
            }

            //如果有id,则为修改,否则就是新增。
            if (goods.id > 0)
            {
                await goodsService.Update(goods.ToEntity(), goods.attrs.ToEntity(), goods.downloads.ToEntity());
            }
            else
            {
                await goodsService.Insert(goods.ToEntity(), goods.attrs.ToEntity(), goods.downloads.ToEntity());
            }
            return(Ok());
        }
Пример #2
0
        public virtual IActionResult AddGoods(GoodsModel model)
        {
            if (!permissionService.Authorize(StandardPermissionProvider.ManageConsignmentOrders))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var entity = consignmentOrderService.Get(model.OrderId);
                if (null == entity)
                {
                    return(Json(new { Result = false }));
                }

                var entityItem = model.ToEntity <Goods>();
                entityItem.CTime = DateTime.UtcNow;
                entity.Goods.Add(entityItem);
                consignmentOrderService.Update(entity);

                return(Json(new { Result = true }));
            }
            else
            {
                var errors = ModelState.Where(x => x.Value.Errors.Any())
                             .ToDictionary(
                    x => x.Key,
                    y => string.Join(Environment.NewLine,
                                     y.Value.Errors.Select(e =>
                                                           string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.Exception.Message : e.ErrorMessage))
                    );

                return(Json(new { Result = false, Error = string.Join(Environment.NewLine, errors.Values) }));
            }
        }