Beispiel #1
0
        public HttpResponseMessage AddTaskPunishment([FromBody]TaskPunishmentModel taskPunishmentModel)
        {
            if (!string.IsNullOrWhiteSpace(taskPunishmentModel.Name))
            {
                Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
                var m = reg.IsMatch(taskPunishmentModel.Name);
                if (!m)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "惩罚名称存在非法字符!"));
                }
                if (!string.IsNullOrEmpty(taskPunishmentModel.Describe))
                {
                    var m1 = reg.IsMatch(taskPunishmentModel.Describe);

                    if (!m1)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "描述存在非法字符!"));
                    }
                }
                var model = new TaskPunishmentEntity
                {
                    Id = taskPunishmentModel.Id,
                    Name = taskPunishmentModel.Name,
                    Describe = taskPunishmentModel.Describe,
                    Value = taskPunishmentModel.Value
                };
                var mo1 = new TaskPunishmentSearchCondition
                {
                    NameRe = taskPunishmentModel.Name
                };
                if (taskPunishmentModel.Type == "add")
                {
                    int taskPunishCount = _taskPunishmentService.GetTaskPunishmentCount(mo1);
                    if (taskPunishCount > 0)
                    { return PageHelper.toJson(PageHelper.ReturnValue(false, "名称重复,请更换")); }
                    else
                    {
                        try
                        {
                            _taskPunishmentService.Create(model);
                            return PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功"));
                        }
                        catch (Exception)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败"));
                        }
                    }
                }
                if (taskPunishmentModel.Type == "edit")
                {
                    try
                    {
                        _taskPunishmentService.Update(_taskPunishmentService.GetTaskPunishmentById(taskPunishmentModel.Id));
                        return PageHelper.toJson(PageHelper.ReturnValue(true, "修改失败"));
                    }
                    catch (Exception)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败"));
                    }
                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "类型名称不能为空"));
        }
Beispiel #2
0
 public HttpResponseMessage TaskPunishmentList()
 {
     //var condition = new TaskPunishmentSearchCondition
     //{
     //    OrderBy = EnumTaskPunishmentSearchOrderBy.OrderById
     //};
     //return PageHelper.toJson(_taskPunishmentService.GetTaskPunishmentsByCondition(condition).ToList());
     var condition = new TaskPunishmentSearchCondition
     {
         OrderBy = EnumTaskPunishmentSearchOrderBy.OrderById
     };
     var typelist = _taskPunishmentService.GetTaskPunishmentsByCondition(condition).Select(p => new
     {
         Id = p.Id,
         Name = p.Name
     }).ToList();
     return PageHelper.toJson(typelist);
 }