public int GetProductParameterCount (ProductParameterSearchCondition condition)
		{
			var query = _productparameterRepository.Table;
			try
			{

				if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }


				if (condition.UpdtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Updtime>= condition.UpdtimeBegin.Value);
                }
                if (condition.UpdtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value);
                }


				if (!string.IsNullOrEmpty(condition.Adduser))
                {
                    query = query.Where(q => q.Adduser.Contains(condition.Adduser));
                }



				if (!string.IsNullOrEmpty(condition.Upduser))
                {
                    query = query.Where(q => q.Upduser.Contains(condition.Upduser));
                }

                

				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                //=============================================彭贵飞 20150708 start=====================================
               
                if (condition.ProductId.HasValue)
                {
                    query = query.Where(q => condition.ProductId == q.Product.Id);
                }
                if (condition.ParameterId.HasValue)
                {
                    query = query.Where(q => condition.ParameterId == q.Parameter.Id);
                }
                //=============================================end                  =====================================
				if (condition.ParameterValues != null && condition.ParameterValues.Any())
                {
                    query = query.Where(q => condition.ParameterValues.Contains(q.ParameterValue));
                }


				if (condition.Parameters != null && condition.Parameters.Any())
                {
                    query = query.Where(q => condition.Parameters.Contains(q.Parameter));
                }


				if (condition.Products != null && condition.Products.Any())
                {
                    query = query.Where(q => condition.Products.Contains(q.Product));
                }


				if (condition.Sorts != null && condition.Sorts.Any())
                {
                    query = query.Where(q => condition.Sorts.Contains(q.Sort));
                }



				return query.Count();
			}
			catch(Exception e)
			{
				_log.Error(e,"数据库操作出错");
                return -1;
			}
		}
		public IQueryable<ProductParameterEntity> GetProductParametersByCondition(ProductParameterSearchCondition condition)
		{
			var query = _productparameterRepository.Table;
			try
			{

				if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }


				if (condition.UpdtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Updtime>= condition.UpdtimeBegin.Value);
                }
                if (condition.UpdtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value);
                }


				if (!string.IsNullOrEmpty(condition.Adduser))
                {
                    query = query.Where(q => q.Adduser.Contains(condition.Adduser));
                }



				if (!string.IsNullOrEmpty(condition.Upduser))
                {
                    query = query.Where(q => q.Upduser.Contains(condition.Upduser));
                }



				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                //=============================================彭贵飞 20150708 start=====================================

                if (condition.ProductId.HasValue)
                {
                    query = query.Where(q => condition.ProductId == q.Product.Id);
                }
                if (condition.ParameterId.HasValue)
                {
                    query = query.Where(q => condition.ParameterId == q.Parameter.Id);
                }
                //=============================================end                  =====================================

				if (condition.ParameterValues != null && condition.ParameterValues.Any())
                {
                    query = query.Where(q => condition.ParameterValues.Contains(q.ParameterValue));
                }


				if (condition.Parameters != null && condition.Parameters.Any())
                {
                    query = query.Where(q => condition.Parameters.Contains(q.Parameter));
                }


				if (condition.Products != null && condition.Products.Any())
                {
                    query = query.Where(q => condition.Products.Contains(q.Product));
                }


				if (condition.Sorts != null && condition.Sorts.Any())
                {
                    query = query.Where(q => condition.Sorts.Contains(q.Sort));
                }




				if(condition.OrderBy.HasValue)
				{
					switch (condition.OrderBy.Value)
                    {

						case EnumProductParameterSearchOrderBy.OrderById:
							query = condition.IsDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id);
							break;

                    }
					
				}

				else
				{
					query = query.OrderBy(q=>q.Id);
				}

				if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1)*condition.PageCount.Value).Take(condition.PageCount.Value);
                }
				return query;
			}
			catch(Exception e)
			{
				_log.Error(e,"数据库操作出错");
                return null;
			}
		}
 public HttpResponseMessage UpdateProductParameterVaule(int parameterValueId, int productId)
 {
     try
     {
         var parameterValue = _parameterValueService.GetParameterValueById(parameterValueId);
         var parameter = parameterValue.Parameter;
         var con = new ProductParameterSearchCondition
         {
             ProductId = productId,
             ParameterId = parameter.Id
         };
         var productParameter = _productParameterService.GetProductParametersByCondition(con).FirstOrDefault();
         if (productParameter != null)
         {
             productParameter.ParameterValue = parameterValue;
             productParameter.Upduser = _workContext.CurrentUser.Id.ToString();
             productParameter.Updtime = DateTime.Now;
             _productParameterService.Update(productParameter);
             return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功"));
         }
         var newProductParameter = new ProductParameterEntity()
         {
             Addtime = DateTime.Now,
             Adduser = _workContext.CurrentUser.Id.ToString(),
             Parameter = parameter,
             ParameterValue = parameterValue,
             Product = _productService.GetProductById(productId),
             Updtime = DateTime.Now,
             Upduser = _workContext.CurrentUser.Id.ToString(),
             Sort = 0
         };
         _productParameterService.Create(newProductParameter);
         return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功"));
     }
     catch (Exception e)
     {
         return PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败"));
     }
 }