Beispiel #1
0
		public TaskEntity Update (TaskEntity entity)
		{
			try
            {
                _taskRepository.Update(entity);
                return entity;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return null;
            }
		}
Beispiel #2
0
		public bool Delete(TaskEntity entity)
		{
			try
            {
                _taskRepository.Delete(entity);
                return true;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return false;
            }
		}
Beispiel #3
0
        public HttpResponseMessage AddTask([FromBody]TaskModel taskModel)
        {
            if (!string.IsNullOrEmpty(taskModel.Taskname))
            {
                //用正则表达式验证是否存在非法字符/^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/
                Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$");
                var m = reg.IsMatch(taskModel.Taskname);
                if (!m)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "任务名称存在非法字符!"));
                }

                //验证日期格式
                if (taskModel.Endtime == null)
                {

                    return PageHelper.toJson(PageHelper.ReturnValue(false, "结束时间格式错误!"));
                }

                if (DateTime.Today >= Convert.ToDateTime(taskModel.Endtime))
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "结束时间至少是明天!"));
                }
                if (!string.IsNullOrEmpty(taskModel.Describe))
                {
                    var m1 = reg.IsMatch(taskModel.Describe);

                    if (!m1)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "描述存在非法字符!"));
                    }
                }
                var user = (UserBase)_workContext.CurrentUser;
                var model = new TaskEntity
                {
                    Id = user.Id,
                    TaskPunishment = _taskPunishmentService.GetTaskPunishmentById(taskModel.TaskPunishmentId),
                    TaskAward = _taskAwardService.GetTaskAwardById(taskModel.TaskAwardId),
                    TaskTag = _taskTagService.GetTaskTagById(taskModel.TaskTagId),
                    TaskType = _taskTypeService.GetTaskTypeById(taskModel.TaskTypeId),
                    Taskname = taskModel.Taskname,
                    Describe = taskModel.Describe,
                    Endtime = Convert.ToDateTime(taskModel.Endtime),
                    Adduser = _workContext.CurrentUser.Id,
                    Addtime = DateTime.Now,
                    Upuser = 0,
                    Uptime = DateTime.Now,
                };
                var mo1 = new TaskSearchCondition
                {
                    TasknameRe = taskModel.Taskname
                };
                if (taskModel.Type == "add")
                {
                    //判断是否存在同名名称
                    int taskCount = _taskService.GetTaskCount(mo1);
                    if (taskCount == 0)
                    {
                        try
                        {
                            if (_taskService.Create(model) != null)
                            {
                                return PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功"));
                            }
                        }
                        catch (Exception)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败"));
                        }
                    }
                    else
                    { return PageHelper.toJson(PageHelper.ReturnValue(false, "任务名称已存在,请换名称")); }
                }
                if (taskModel.Type == "edit")
                {
                    var cond = new TaskListSearchCondition()
                    {
                        TaskId = taskModel.Id
                    };
                    //判断任务是否被接手

                    int tlistcout = _taskListService.GetTaskListCount(cond);
                    //判断是否存在同名名称
                    var mo11 = new TaskSearchCondition
                    {
                        TasknameRe = taskModel.Taskname,
                        Id = taskModel.Id
                    };
                    int tasknameCount = _taskService.GetTaskCount(mo11);
                    if (tlistcout > 0) { return PageHelper.toJson(PageHelper.ReturnValue(false, "不能修改,已经有人接手任务")); }

                    else if (tasknameCount > 0) { return PageHelper.toJson(PageHelper.ReturnValue(false, "任务名称已存在,请换名称")); }
                    else
                    {
                        var mdel = _taskService.GetTaskById(taskModel.Id);
                        mdel.Id = taskModel.Id;
                        mdel.TaskPunishment = _taskPunishmentService.GetTaskPunishmentById(taskModel.TaskPunishmentId);
                        mdel.TaskAward = _taskAwardService.GetTaskAwardById(taskModel.TaskAwardId);
                        mdel.TaskTag = _taskTagService.GetTaskTagById(taskModel.TaskTagId);
                        mdel.TaskType = _taskTypeService.GetTaskTypeById(taskModel.TaskTypeId);
                        mdel.Taskname = taskModel.Taskname;
                        mdel.Describe = taskModel.Describe;
                        mdel.Endtime = Convert.ToDateTime(taskModel.Endtime);
                        mdel.Upuser = _workContext.CurrentUser.Id;
                        mdel.Uptime = DateTime.Now;
                        try
                        {
                            _taskService.Update(mdel);
                            return PageHelper.toJson(PageHelper.ReturnValue(true, "修改成功"));
                        }
                        catch (Exception)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败"));
                        }
                    }
                }
            }
            else
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "任务名称不能为空!"));
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证失败"));
        }