public int GetPartImageCount (PartImageSearchCondition condition)
		{
			var query = _partimageRepository.Table;
			try
			{
                if (condition.CrowdId != null)
                {
                    query = query.Where(q => q.Crowd.Id == condition.CrowdId);
                }
				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.UptimeBegin.HasValue)
                {
                    query = query.Where(q => q.Uptime>= condition.UptimeBegin.Value);
                }
                if (condition.UptimeEnd.HasValue)
                {
                    query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
                }
				if (!string.IsNullOrEmpty(condition.Imgurl))
                {
                    query = query.Where(q => q.Imgurl.Contains(condition.Imgurl));
                }
				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
				if (condition.Crowds != null && condition.Crowds.Any())
                {
                    query = query.Where(q => condition.Crowds.Contains(q.Crowd));
                }
				if (condition.Orderbys != null && condition.Orderbys.Any())
                {
                    query = query.Where(q => condition.Orderbys.Contains(q.Orderby));
                }
				if (condition.Addusers != null && condition.Addusers.Any())
                {
                    query = query.Where(q => condition.Addusers.Contains(q.Adduser));
                }
				if (condition.Upusers != null && condition.Upusers.Any())
                {
                    query = query.Where(q => condition.Upusers.Contains(q.Upuser));
                }
				return query.Count();
			}
			catch(Exception e)
			{
				_log.Error(e,"数据库操作出错");
                return -1;
			}
		}
		public IQueryable<PartImageEntity> GetPartImagesByCondition(PartImageSearchCondition condition)
		{
			var query = _partimageRepository.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.UptimeBegin.HasValue)
                {
                    query = query.Where(q => q.Uptime>= condition.UptimeBegin.Value);
                }
                if (condition.UptimeEnd.HasValue)
                {
                    query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
                }
				if (!string.IsNullOrEmpty(condition.Imgurl))
                {
                    query = query.Where(q => q.Imgurl.Contains(condition.Imgurl));
                }
				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
				if (condition.Crowds != null && condition.Crowds.Any())
                {
                    query = query.Where(q => condition.Crowds.Contains(q.Crowd));
                }
				if (condition.Orderbys != null && condition.Orderbys.Any())
                {
                    query = query.Where(q => condition.Orderbys.Contains(q.Orderby));
                }
				if (condition.Addusers != null && condition.Addusers.Any())
                {
                    query = query.Where(q => condition.Addusers.Contains(q.Adduser));
                }
				if (condition.Upusers != null && condition.Upusers.Any())
                {
                    query = query.Where(q => condition.Upusers.Contains(q.Upuser));
                }
                if (condition.CrowdId != null) {
                    query = query.Where(q => q.Crowd.Id == condition.CrowdId);
                }
				if(condition.OrderBy.HasValue)
				{
					switch (condition.OrderBy.Value)
                    {
						case EnumPartImageSearchOrderBy.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 AddCrowdInfo([FromBody]CrowdModel crowdModel)
        {
            if (crowdModel != null)
            {
                var entity = new CrowdEntity
                {
                    Uptime = DateTime.Now,
                    Addtime = DateTime.Now,
                    Adduser = 1,
                    Upuser = 1,
                    Ttitle = crowdModel.Ttitle,
                    Intro = crowdModel.Intro,
                    Starttime = DateTime.Now,
                    Endtime = DateTime.Now,
                    Status = 1,
                    crowdUrl = crowdModel.crowdUrl
                };
                var entityImg = new PartImageEntity
                {
                    Orderby = 1,
                    Imgurl = "",
                    Adduser = 2,
                    Addtime = DateTime.Now,
                    Uptime = DateTime.Now,
                    Upuser = 2,
                    Crowd = null
                };
                try
                {
                    int id;
                    if (crowdModel.Id > 0) //修改众筹
                    {
                        id = crowdModel.Id;
                        entity = _crowdService.GetCrowdById(id);
                        entity.Intro = crowdModel.Intro;
                        entity.Ttitle = crowdModel.Ttitle;
                        entity.crowdUrl = crowdModel.crowdUrl;
                        _crowdService.Update(entity);//更新众筹表crowd
                        var enImg = new PartImageSearchCondition
                        {
                            OrderBy = EnumPartImageSearchOrderBy.OrderById,
                            CrowdId = id
                        };
                        var model = _partImageService.GetPartImagesByCondition(enImg);//根据众筹id查询众筹图片
                        foreach (var p in model)
                        {
                            _partImageService.Delete(p);//删除众筹图片
                        }
                        if (crowdModel.ImgList1.Count > 0)
                        {
                            entityImg.Crowd = _crowdService.GetCrowdById(id);
                            for (int i = 0; i < crowdModel.ImgList1.Count; i++)//添加众筹图片
                            {
                                entityImg.Imgurl = crowdModel.ImgList1[i];

                                _partImageService.Create(entityImg);
                            }

                        }
                        return PageHelper.toJson(PageHelper.ReturnValue(true, "数据保存成功!"));

                    }
                    else//新增众筹
                    {
                        id = _crowdService.Create(entity).Id;
                        //插入众筹图片
                        if (crowdModel.ImgList1.Count > 0)
                        {
                            entityImg.Crowd = _crowdService.GetCrowdById(id);
                            for (int i = 0; i < crowdModel.ImgList1.Count; i++)
                            {
                                entityImg.Imgurl = crowdModel.ImgList1[i];

                                _partImageService.Create(entityImg);
                            }

                        }
                        return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!"));
                    }


                }
                catch
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!"));
                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误!"));
        }