Ejemplo n.º 1
0
 public HttpResponseMessage Create(ChannelModel model)
 {
     Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
     var m = reg.IsMatch(model.Name);
     if (!m)
     {
         return PageHelper.toJson(PageHelper.ReturnValue(false, "存在非法字符!"));
     }
     else
     {
         var channelCon = new ChannelSearchCondition
         {
             Name = model.Name               
         };
         var totalCount = _channelService.GetChannelCount(channelCon);
         if (totalCount > 0)
         {
             return PageHelper.toJson(PageHelper.ReturnValue(false, "数据已存在!"));
         }
         else
         {
             var newParent = model.ParentId == 0 ? null : _channelService.GetChannelById(model.ParentId);
             var channel = new ChannelEntity
             {
                 Name = model.Name,
                 Status = model.Status,
                 Parent = newParent,
                 Adduser = _workContent.CurrentUser.Id,
                 Addtime = DateTime.Now,
                 UpdUser = _workContent.CurrentUser.Id,
                 UpdTime = DateTime.Now
             };
             if (_channelService.Create(channel) != null)
             {
                 return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!"));
             }
             else
             {
                 return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!"));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public HttpResponseMessage Edit(ChannelModel model)
 {
     Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
     var m = reg.IsMatch(model.Name);
    if (!m)
    {
        return PageHelper.toJson(PageHelper.ReturnValue(false, "存在非法字符!"));
    }
    else
    {
        var channel = _channelService.GetChannelById(model.Id);
        if (channel.Name == model.Name)
        {
            var newParent = _channelService.GetChannelById(model.ParentId);
            channel.Name = model.Name;
            channel.Status = model.Status;
            channel.UpdUser = _workContent.CurrentUser.Id;
            channel.UpdTime = DateTime.Now;
            channel.Parent = newParent;
            if (_channelService.Update(channel) != null)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
            }
            else
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败!"));
            }
        }
        else
        {
              var channelCon = new ChannelSearchCondition
              {
                  Name = model.Name
              };
              var totalCount = _channelService.GetChannelCount(channelCon);
              if (totalCount > 0)
              {
                  return PageHelper.toJson(PageHelper.ReturnValue(false, "数据已存在!"));
              }
              else
              {
                  var newParent = _channelService.GetChannelById(model.ParentId);
                  channel.Name = model.Name;
                  channel.Status = model.Status;
                  channel.UpdUser = _workContent.CurrentUser.Id;
                  channel.UpdTime = DateTime.Now;
                  channel.Parent = newParent;
                  if (_channelService.Update(channel) != null)
                  {
                      return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
                  }
                  else
                  {
                      return PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败!"));
                  }
              }
        }
    }          
 }
Ejemplo n.º 3
0
 public HttpResponseMessage Detailed(int id)
 {
     var channel = _channelService.GetChannelById(id);
     if (channel == null) {
         return PageHelper.toJson(PageHelper.ReturnValue(false,"该数据不存在!"));
     }
     var channelDetail = new ChannelModel
     {
         Id = channel.Id,
         Name = channel.Name,
         Status = channel.Status,
         ParentId=channel.Parent==null?0:channel.Parent.Id
     };
     return PageHelper.toJson(channelDetail);
 }