public ResultDto AddTask([FromBody] LongTaskEntity entity) { var result = new ResultDto(); if (!entity.IsLongTerm) { var taskEntity = new TaskEntity { TaskDate = entity.TaskDate, StartTime = entity.StartTime, EndTime = entity.EndTime, Content = entity.Content, IsRemind = entity.IsRemind, IsDone = false }; taskEntity.AuditCreation(_kardSession.UserId.Value); var createResult = _defaultRepository.CreateAndGetId <TaskEntity, long>(taskEntity); result.Result = createResult.Result; result.Message = createResult.Message; return(result); } entity.AuditCreation(_kardSession.UserId.Value); result = _defaultRepository.AddTask(entity); return(result); }
public ResultDto AddTask(LongTaskEntity entity) { var taskDate = entity.StartDate; var taskWeekDay = (int)taskDate.DayOfWeek; var taskWeekList = entity.Week.Split(',').Select(w => Convert.ToInt32(w)); return(_defaultRepository.TransExecute((conn, trans) => { var createResult = new ResultDto(); var createLongResult = conn.CreateAndGetId <LongTaskEntity, long>(entity, trans); if (!createLongResult.Result) { _logger.LogError("添加长期目标失败,已撤销:" + createLongResult.Message); createResult.Result = false; createResult.Message = "添加长期目标失败"; return createResult; } var taskEntityList = new List <TaskEntity>(); while (taskDate <= entity.EndDate) { if (taskWeekList.Contains(taskWeekDay)) { var taskEntity = new TaskEntity() { LongTaskId = createLongResult.Data, TaskDate = taskDate, StartTime = entity.StartTime, EndTime = entity.EndTime, Content = entity.Content, IsRemind = entity.IsRemind, IsDone = false }; taskEntity.AuditCreation(entity.CreatorUserId.Value); taskEntityList.Add(taskEntity); } taskDate = taskDate.AddDays(1); taskWeekDay = (taskWeekDay + 1) % 7; } if (!conn.CreateList(taskEntityList, trans).Result) { //_logger.LogError("添加小目标失败,已撤销"); createResult.Result = false; createResult.Message = "添加小目标失败"; return createResult; } createResult.Result = true; return createResult; })); }