public ActionResult Create(FormCollection formCollection, CreateProductRequest request, int? authuid)
        {
            request.AuthUid = authuid.Value;
            request.Description = UrlDecode(request.Description);
            request.Favorable = UrlDecode(request.Favorable);
            request.Name = UrlDecode(request.Name);
            request.RecommendedReason = UrlDecode(request.RecommendedReason);
            request.RecommendUser = request.AuthUid;
            request.Files = Request.Files;

            this._productDataService.CreateProduct(request);

            return View();
        }
예제 #2
0
        public ExecuteResult<ProductInfoResponse> CreateProduct(CreateProductRequest request)
        {
            if (request == null)
            {
                return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" };
            }
            /*
            if (request.Is4Sale.HasValue && request.Is4Sale.Value == true && string.IsNullOrEmpty(request.UPCCode))
            {
                return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "可销售商品需要设置商品货号" };
            }
            */
            if (request.RecommendUser == 0)
            {
                request.RecommendUser = request.AuthUid;

            }

            request.RecommendSourceId = request.RecommendUser;
            request.RSourceType = request.AuthUser.Level == UserLevel.Daren
                                              ? RecommendSourceType.Daren
                                              : RecommendSourceType.StoreManager;

            //判断当前用户是否是 管理员或者 level 是达人?
            var inEntity = MappingManager.ProductEntityMapping(request);
            inEntity.Is4Sale = request.Is4Sale;

            if (request.Files != null && request.Files.Count > 0)
            {
                foreach (string f in request.Files)
                {
                    if (request.Files[f].HasFile())
                    {
                        inEntity.IsHasImage = true;

                        break;
                    }
                }
            }
            if (!inEntity.IsHasImage)
                return new ExecuteResult<ProductInfoResponse>(null)
                {
                    StatusCode = StatusCode.ClientError
                    ,
                    Message = "没有图片信息"
                };
            inEntity.SortOrder = 0;
            ProductEntity entity = null;
            using (var ts = new TransactionScope())
            {
                entity = _productRepository.Insert(inEntity);
                //insert product code map
                if (!string.IsNullOrEmpty(request.UPCCode))
                {
                    _productcodemapRepo.Insert(new ProductCode2StoreCodeEntity()
                    {
                        ProductId = entity.Id,
                        Status = (int)DataStatus.Normal,
                        StoreId = entity.Store_Id,
                        ExPId = int.Parse(request.UPCCode),
                        UpdateDate = DateTime.Now,
                        UpdateUser = request.AuthUser.Id
                    });
                }
                //insert properties if any
                if (request.PropertyModel != null)
                {
                    foreach (var property in request.PropertyModel)
                    {
                        if (string.IsNullOrEmpty(property.PropertyName))
                            continue;
                        var productPropertyEntity = _productpropertyRepo.Insert(new ProductPropertyEntity()
                        {
                            ProductId = entity.Id,
                            PropertyDesc = property.PropertyName,
                            SortOrder = 0,
                            Status = (int)DataStatus.Normal,
                            UpdateDate = DateTime.Now,
                            UpdateUser = request.RecommendUser
                        });
                        foreach (var value in property.Values)
                        {
                            if (string.IsNullOrEmpty(value))
                                continue;
                            _productpropertyvalueRepo.Insert(new ProductPropertyValueEntity()
                            {
                                CreateDate = DateTime.Now,
                                PropertyId = productPropertyEntity.Id,
                                Status = (int)DataStatus.Normal,
                                UpdateDate = DateTime.Now,
                                ValueDesc = value
                            });
                        }
                    }
                }
                //处理 图片
                //处理文件上传
                if (request.Files != null && request.Files.Count > 0)
                {
                    List<ResourceEntity> listImage = null;
                    try
                    {
                        listImage = _resourceService.Save(request.Files, request.AuthUid, 0, entity.Id, SourceType.Product);

                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);

                        //DEL 上传的产品

                        _productRepository.Delete(entity);

                        throw;
                    }

                    if (listImage == null || listImage.Count == 0)
                    {
                        //set ishasimage
                        if (entity.IsHasImage)
                        {
                            _productRepository.SetIsHasImage(entity.Id, false, DataStatus.Default, request.AuthUid,
                                        "set ishasimage false");
                        }
                    }
                }
                ts.Complete();
            }
            return new ExecuteResult<ProductInfoResponse>(MappingManager.ProductInfoResponseMapping(entity));
        }
예제 #3
0
        public ActionResult Create(CreateProductRequest request, int? authuid, UserModel authUser)
        {
            request.AuthUid = authuid.Value;
            request.AuthUser = authUser;
            request.Description = UrlDecode(request.Description);
            request.Favorable = UrlDecode(request.Favorable);
            request.Name = UrlDecode(request.Name);
            request.RecommendedReason = UrlDecode(request.RecommendedReason);
            request.RecommendUser = request.AuthUid;
            request.Files = Request.Files;

            return new RestfulResult { Data = this._productDataService.CreateProduct(request) };
        }