public HttpResponseMessage Put(ProductParameterModel model)
        {
            var product = _productService.GetProductById(model.ProductId);

            if (product == null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "商品不存在")));
            }
            var parameterValue = _parameterValueService.GetParameterValuesByCondition(new ParameterValueSearchCondition {
                Ids = model.ValueIds
            }).ToList().Select(pv => new ProductParameterEntity
            {
                Product        = product,
                AddTime        = DateTime.Now,
                AddUser        = _workContext.CurrentUser.Id,
                Parameter      = pv.Parameter,
                ParameterValue = pv,
                Sort           = 0,
                UpdTime        = DateTime.Now,
                UpdUser        = _workContext.CurrentUser.Id
            }).ToList();
            var productParams =
                _productParameterService.GetProductParametersByCondition(new ProductParameterSearchCondition
            {
                ProductId = product.Id
            }).ToList();

            if (productParams.Count > 0)
            {
                foreach (var item in productParams)
                {
                    _productParameterService.Delete(item);
                }
                //var parameterValue =
                //    _parameterValueService.GetParameterValuesByCondition(new ParameterValueSearchCondition
                //    {
                //        Ids = model.ValueIds
                //    }).ToList().Select(pv => new ProductParameterEntity
                //    {
                //        Product = product,
                //        AddTime = DateTime.Now,
                //        AddUser = _workContext.CurrentUser.Id,
                //        Parameter = pv.Parameter,
                //        ParameterValue = pv,
                //        Sort = 0,
                //        UpdTime = DateTime.Now,
                //        UpdUser = _workContext.CurrentUser.Id
                //    }).ToList();
                _productParameterService.BulkCreate(parameterValue);
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功")));
            }
            _productParameterService.BulkCreate(parameterValue);
            return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功")));
        }
Beispiel #2
0
        public HttpResponseMessage Get(string ParameterId)
        {
            var condition = new ParameterValueSearchCondition
            {
                Parameters = _parameterService.GetParameterById(Convert.ToInt32(ParameterId))
            };
            var model = _parameterValueService.GetParameterValuesByCondition(condition).Select(c => new
            {
                Id            = c.Id,
                ParameterName = c.Parameter.Name,
                Value         = c.Value,
                Sort          = c.Sort,
                AddTime       = c.AddTime
            }).ToList();

            return(PageHelper.toJson(model));
        }