Пример #1
0
		public IQueryable<TaskTagEntity> GetTaskTagsByCondition(TaskTagSearchCondition condition)
		{
			var query = _tasktagRepository.Table;
			try
			{
				if (!string.IsNullOrEmpty(condition.Name))
                {
                    query = query.Where(q => q.Name.Contains(condition.Name));
                }
				if (!string.IsNullOrEmpty(condition.Describe))
                {
                    query = query.Where(q => q.Describe.Contains(condition.Describe));
                }
				if (!string.IsNullOrEmpty(condition.Value))
                {
                    query = query.Where(q => q.Value.Contains(condition.Value));
                }
				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
				if(condition.OrderBy.HasValue)
				{
					switch (condition.OrderBy.Value)
                    {
						case EnumTaskTagSearchOrderBy.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;
			}
		}
Пример #2
0
        public HttpResponseMessage AddTaskTag([FromBody]TaskTagModel taskTagModel)
        {
            if (!string.IsNullOrWhiteSpace(taskTagModel.Name))
            {
                Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
                var m = reg.IsMatch(taskTagModel.Name);
                if (!m)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "目标名称存在非法字符!"));
                }
                if (!string.IsNullOrEmpty(taskTagModel.Describe))
                {
                    var m1 = reg.IsMatch(taskTagModel.Describe);

                    if (!m1)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "描述存在非法字符!"));
                    }
                }
                var model = new TaskTagEntity
                {
                    Id = taskTagModel.Id,
                    Name = taskTagModel.Name,
                    Describe = taskTagModel.Describe,
                    Value = taskTagModel.Value
                };
                var mo1 = new TaskTagSearchCondition
               {
                   NameRe = taskTagModel.Name
               };
                if (taskTagModel.Type == "add")
                {
                    int taskTagCount = _taskTagService.GetTaskTagCount(mo1);
                    if (taskTagCount > 0)
                    { return PageHelper.toJson(PageHelper.ReturnValue(false, "名称重复,请更换")); }
                    else
                    {
                        try
                        {
                            _taskTagService.Create(model);
                            return PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功"));
                        }
                        catch (Exception)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败"));
                        }
                    }
                }
                if (taskTagModel.Type == "edit")
                {
                    try
                    {
                        _taskTagService.Update(_taskTagService.GetTaskTagById(taskTagModel.Id));
                        return PageHelper.toJson(PageHelper.ReturnValue(true, "操作成功"));
                    }
                    catch (Exception)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败"));
                    }
                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "类型名称不能为空"));
        }
Пример #3
0
 public HttpResponseMessage TaskTagList()
 {
     //var condition = new TaskTagSearchCondition
     //{
     //    OrderBy = EnumTaskTagSearchOrderBy.OrderById
     //};
     //return PageHelper.toJson(_taskTagService.GetTaskTagsByCondition(condition).ToList());
     var condition = new TaskTagSearchCondition
     {
         OrderBy = EnumTaskTagSearchOrderBy.OrderById
     };
     var typelist = _taskTagService.GetTaskTagsByCondition(condition).Select(p => new
     {
         Id = p.Id,
         Name = p.Name
     }).ToList();
     return PageHelper.toJson(typelist);
 }
Пример #4
0
		public int GetTaskTagCount (TaskTagSearchCondition condition)
		{
			var query = _tasktagRepository.Table;
			try
			{
				if (!string.IsNullOrEmpty(condition.Name))
                {
                    query = query.Where(q => q.Name.Contains(condition.Name));
                }
                if (!string.IsNullOrEmpty(condition.NameRe))
                {
                    query = query.Where(q => q.Name==condition.NameRe);
                }
				if (!string.IsNullOrEmpty(condition.Describe))
                {
                    query = query.Where(q => q.Describe.Contains(condition.Describe));
                }
				if (!string.IsNullOrEmpty(condition.Value))
                {
                    query = query.Where(q => q.Value.Contains(condition.Value));
                }
				if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
				return query.Count();
			}
			catch(Exception e)
			{
				_log.Error(e,"数据库操作出错");
                return -1;
			}
		}