Esempio n. 1
0
        public IQueryable <TaskTypeEntity> GetTaskTypesByCondition(TaskTypeSearchCondition condition)
        {
            var query = _tasktypeRepository.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 (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }



                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                    case EnumTaskTypeSearchOrderBy.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);
            }
        }
Esempio n. 2
0
        public HttpResponseMessage TaskTypeList()
        {
            var condition = new TaskTypeSearchCondition
            {
                OrderBy = EnumTaskTypeSearchOrderBy.OrderById
            };
            var typelist = _taskTypeService.GetTaskTypesByCondition(condition).Select(p => new
            {
                Id   = p.Id,
                Name = p.Name
            }).ToList();

            return(PageHelper.toJson(typelist));
        }
Esempio n. 3
0
        public int GetTaskTypeCount(TaskTypeSearchCondition condition)
        {
            var query = _tasktypeRepository.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 (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);
            }
        }
Esempio n. 4
0
        public HttpResponseMessage AddTaskTpye([FromBody] TaskTypeModel taskTypeModel)
        {
            if (!string.IsNullOrWhiteSpace(taskTypeModel.Name))
            {
                Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
                var   m   = reg.IsMatch(taskTypeModel.Name);
                if (!m)
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "类型名称存在非法字符!")));
                }
                if (taskTypeModel.Describe != "")
                {
                    var m1 = reg.IsMatch(taskTypeModel.Describe);

                    if (!m1)
                    {
                        return(PageHelper.toJson(PageHelper.ReturnValue(false, "描述存在非法字符!")));
                    }
                }
                var model = new TaskTypeEntity
                {
                    Id       = taskTypeModel.Id,
                    Name     = taskTypeModel.Name,
                    Describe = taskTypeModel.Describe
                };
                var mo1 = new TaskTypeSearchCondition
                {
                    NameRe = taskTypeModel.Name
                };

                if (taskTypeModel.Type == "add")
                {
                    int taskTypeCount = _taskTypeService.GetTaskTypeCount(mo1);
                    if (taskTypeCount > 0)
                    {
                        return(PageHelper.toJson(PageHelper.ReturnValue(false, "名称重复,请更换")));
                    }
                    else
                    {
                        try
                        {
                            if (_taskTypeService.Create(model) != null)
                            {
                                return(PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功")));
                            }
                        }
                        catch (Exception)
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败")));
                        }
                    }
                }
                if (taskTypeModel.Type == "edit")
                {
                    try
                    {
                        _taskTypeService.Update(_taskTypeService.GetTaskTypeById(taskTypeModel.Id));
                        return(PageHelper.toJson(PageHelper.ReturnValue(true, "修改成功")));
                    }
                    catch (Exception)
                    {
                        return(PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败")));
                    }
                }
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "类型名称不能为空!")));
        }