示例#1
0
		public IQueryable<TaskAwardEntity> GetTaskAwardsByCondition(TaskAwardSearchCondition condition)
		{
			var query = _taskawardRepository.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 EnumTaskAwardSearchOrderBy.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 AddTaskAward([FromBody]TaskAwardModel taskAwardModel)
        {
            if (!string.IsNullOrWhiteSpace(taskAwardModel.Name))
            {
                Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
                var m = reg.IsMatch(taskAwardModel.Name);
                if (!m)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "奖励名称存在非法字符!"));
                }
                if (!string.IsNullOrEmpty(taskAwardModel.Describe))
                {
                    var m1 = reg.IsMatch(taskAwardModel.Describe);

                    if (!m1)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "描述存在非法字符!"));
                    }
                }
                var model = new TaskAwardEntity
                {
                    Id = taskAwardModel.Id,
                    Name = taskAwardModel.Name,
                    Describe = taskAwardModel.Describe,
                    Value = taskAwardModel.Value
                };
                var mo1 = new TaskAwardSearchCondition
                {
                    NameRe = taskAwardModel.Name
                };
                if (taskAwardModel.Type == "add")
                {
                    int taskTypeCount = _taskAwardService.GetTaskAwardCount(mo1);
                    if (taskTypeCount > 0)
                    { return PageHelper.toJson(PageHelper.ReturnValue(false, "名称重复,请更换")); }
                    else
                    {
                        try
                        {
                            _taskAwardService.Create(model);
                            return PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功"));
                        }
                        catch (Exception)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败"));
                        }
                    }
                }
                if (taskAwardModel.Value == "edit")
                {
                    try
                    {
                        _taskAwardService.Update(_taskAwardService.GetTaskAwardById(taskAwardModel.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 TaskAwardList()
 {
     //var condition = new TaskAwardSearchCondition
     //{
     //    OrderBy = EnumTaskAwardSearchOrderBy.OrderById
     //};
     //return PageHelper.toJson(_taskAwardService.GetTaskAwardsByCondition(condition).ToList());
     var condition = new TaskAwardSearchCondition
     {
         OrderBy = EnumTaskAwardSearchOrderBy.OrderById
     };
     var typelist = _taskAwardService.GetTaskAwardsByCondition(condition).Select(p => new
     {
         Id = p.Id,
         Name = p.Name
     }).ToList();
     return PageHelper.toJson(typelist);
 }
示例#4
0
		public int GetTaskAwardCount (TaskAwardSearchCondition condition)
		{
			var query = _taskawardRepository.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;
			}
		}