コード例 #1
0
 public HttpResponseMessage Create(ContentDetailModel model)
 {
     Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
     var m = reg.IsMatch(model.Title);
     if (!m)
     {
         return PageHelper.toJson(PageHelper.ReturnValue(false, "标题存在非法字符!"));
     }
     else
     {                              
             var newChannel = _channelService.GetChannelById(model.ChannelId);
             if (newChannel == null)
             {
                 return PageHelper.toJson(PageHelper.ReturnValue(false, "请选择频道!"));
             }
             var content = new ContentEntity
             {
                 Title = model.Title,
                 TitleImg = model.TitleImg,
                 Content = model.Content,
                 Status = model.Status,
                 Channel = newChannel,
                 Adduser = _workContent.CurrentUser.Id,
                 Addtime = DateTime.Now,
                 UpdUser = _workContent.CurrentUser.Id,
                 UpdTime = DateTime.Now,
                 AdSubTitle=model.AdSubTitle
             };
             if (_contentService.Create(content) != null)
             {
                 return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!"));
             }
             else
             {
                 return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!"));
             }
     }
 }
コード例 #2
0
 public HttpResponseMessage Detailed(int id)
 {
     var content = _contentService.GetContentById(id);
     if (content == null)
     {
         return PageHelper.toJson(PageHelper.ReturnValue(false, "该数据不存在!"));
     }
     var contentDetail = new ContentDetailModel
     {
         Id = content.Id,
         Title = content.Title,
         TitleImg = content.TitleImg,
         Content = content.Content,
         ChannelName = content.Channel.Name,
         ChannelId = content.Channel.Id,
         Status=content.Status,
         AdSubTitle=content.AdSubTitle
     };
     return PageHelper.toJson(contentDetail);
 }
コード例 #3
0
 public HttpResponseMessage Edit(ContentDetailModel model)
 {
     Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
     var m = reg.IsMatch(model.Title);
     if (!m)
     {
         return PageHelper.toJson(PageHelper.ReturnValue(false, "标题存在非法字符!"));
     }
     else
     {
         var content = _contentService.GetContentById(model.Id);
         var newChannel = _channelService.GetChannelById(model.ChannelId);
         content.Title = model.Title;
         content.Content = model.Content;
         content.Status = model.Status;
         content.AdSubTitle = model.AdSubTitle;
         content.UpdUser = _workContent.CurrentUser.Id;
         content.UpdTime = DateTime.Now;
         content.Channel = newChannel;
         if (_contentService.Update(content) != null)
         {
             return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
         }
         else
         {
             return PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败!"));
         }
     }
 }