Example #1
0
		public bool Delete(PartImageEntity entity)
		{
			try
            {
                _partimageRepository.Delete(entity);
                return true;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return false;
            }
		}
Example #2
0
		public PartImageEntity Update (PartImageEntity entity)
		{
			try
            {
                _partimageRepository.Update(entity);
                return entity;
            }
            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, "数据验证错误!"));
        }