public void Edit(WorkTask task) { RepositoryAction.Transaction((c, t) => { var row = WorkTaskTableRow.FromDomainObject(task); var dao = new WorkTaskDao(c, t); dao.Update(row); }); }
public WorkTaskWithTimesDto[] SelectByYmd(YmdString ymd, bool containsCompleted) { var list = new List <WorkTaskWithTimesDto>(); RepositoryAction.Query(c => { var workTaskDao = new WorkTaskDao(c, null); var workingTimeDao = new WorkingTimeDao(c, null); var processes = new WorkProcessDao(c, null).SelectAll(); var products = new ProductDao(c, null).SelectAll(); var clients = new ClientDao(c, null).SelectAll(); var completedDao = new WorkTaskCompletedDao(c, null); var tasks = workTaskDao.SelectPlaned(ymd, containsCompleted); var times = workingTimeDao.SelectByTaskIds(tasks.Select(t => t.Id).Distinct().ToArray()); var completed = completedDao.SelectCompleted(tasks.Select(t => t.Id).Distinct().ToArray()); foreach (var task in tasks) { var dto = new WorkTaskWithTimesDto { TaskId = new Identity <Domain.Domain.Tasks.WorkTask>(task.Id), ClientName = clients.FirstOrDefault(c => c.Id == task.ClientId)?.Name ?? "", ProcessName = processes.FirstOrDefault(p => p.Id == task.ProcessId)?.Title ?? "", ProductName = products.FirstOrDefault(p => p.Id == task.ProductId)?.Name ?? "", TaskCategory = task.TaskCategory, Title = task.Title, IsCompleted = completed.Any(c => c == task.Id), IsScheduled = task.TaskSource == Domain.Domain.Tasks.TaskSource.Schedule, }; dto.WorkingTimes = times.Where(t => t.TaskId == task.Id) .Select(t => t.ToDomainObject()) .OrderBy(t => t.TimePeriod.StartDateTime) .ThenBy(t => t.Id) .ToArray(); list.Add(dto); } }); try { return(list.OrderBy(i => i.WorkingTimes.Any(t => t.IsDoing) ? 0 : 1) .ThenByDescending(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Max(t => t.TimePeriod.StartDateTime) : DateTime.MinValue) .ThenBy(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Min(t => t.TimePeriod.StartDateTime) : DateTime.MaxValue) .ThenBy(i => i.TaskId.Value).ToArray()); } catch (Exception) { return(list.ToArray()); } }
public WorkTask SelectById(Identity <WorkTask> identity) { WorkTask results = null; RepositoryAction.Query(c => { var dao = new WorkTaskDao(c, null); results = dao.SelectById(identity.Value)?.ConvertToDomainObject(); }); return(results); }
public WorkTask SelectById(Identity <WorkTask> identity) { WorkTask results = null; RepositoryAction.Query(c => { var dao = new WorkTaskDao(c, null); var compDao = new WorkTaskCompletedDao(c, null); var exist = compDao.IsCompleted(identity.Value); results = WorkTaskFactory.Create(dao.SelectById(identity.Value), exist); }); return(results); }
public void Edit(WorkTask task) { RepositoryAction.Transaction((c, t) => { var row = WorkTaskTableRow.FromDomainObject(task); var dao = new WorkTaskDao(c, t); var compDao = new WorkTaskCompletedDao(c, t); dao.Update(row); if (task.IsCompleted) { compDao.InsertIfNotExist(task.Id.Value); } else { compDao.DeleteByWorkTaskId(task.Id.Value); } }); }
private WorkTask AddCore(WorkTask task, ImportedTask workTaskImportSource) { var row = WorkTaskTableRow.FromDomainObject(task); RepositoryAction.Transaction((c, t) => { var dao = new WorkTaskDao(c, t); var id = dao.Insert(row); // ID採番結果 row.Id = id; // スケジュールからの取込の場合は取込歴にも残す if (task.IsScheduled) { var importDao = new ImportedTaskDao(c, t); importDao.Insert(ImportedTaskTableRow.FromDomainObject(id, workTaskImportSource)); } }); return(WorkTaskFactory.Create(row, task.IsCompleted)); }
public WorkTask Add(WorkTask task) { var row = WorkTaskTableRow.FromDomainObject(task); RepositoryAction.Transaction((c, t) => { var dao = new WorkTaskDao(c, t); var id = dao.Insert(row); // ID採番結果 row.Id = id; // スケジュールからの取込の場合は取込歴にも残す if (task.IsScheduled) { var importDao = new ImportedTaskDao(c, t); importDao.Insert(ImportedTaskTableRow.FromDomainObject(task)); } }); return(row.ConvertToDomainObject()); }
public DailyWorkResults SelectByYearMonth(YearMonth yearMonth) { var list = new List <WorkingTimeRecordForReport>(); var listWorkingHour = new List <WorkingHour>(); RepositoryAction.Query(c => { var workTaskDao = new WorkTaskDao(c, null); var workingTimeDao = new WorkingTimeDao(c, null); var processes = new WorkProcessDao(c, null).SelectAll() .Select(d => d.ToDomainObject()) .ToDictionary(p => p.Id); var products = new ProductDao(c, null).SelectAll() .Select(d => d.ToDomainObject()) .ToDictionary(p => p.Id); var clients = new ClientDao(c, null).SelectAll() .Select(d => d.ToDomainObject()) .ToDictionary(p => p.Id); var param = new { start = yearMonth.StartDate.ToString("yyyyMMdd"), end = yearMonth.EndDate.ToString("yyyyMMdd") }; var rows = c.Query <TableRow>(sql, param); foreach (var task in rows) { processes.TryGetValue(new Identity <WorkProcess>(task.WorkProcessId), out WorkProcess targetProcess); products.TryGetValue(new Identity <Product>(task.ProductId), out Product targetProduct); clients.TryGetValue(new Identity <Client>(task.ClientId), out Client targetClient); if (string.IsNullOrEmpty(task.EndTime)) { continue; } var dto = new WorkingTimeRecordForReport { Ymd = new YmdString(task.Ymd), TaskCategory = task.TaskCategory, WorkProcess = targetProcess, Product = targetProduct ?? Product.Empty, Client = targetClient ?? Client.Empty, StartDateTime = DateTimeParser.ConvertFromYmdHHmmss(task.Ymd, task.StartTime).Value, EndDateTime = DateTimeParser.ConvertFromYmdHHmmss(task.Ymd, task.EndTime).Value, Title = task.Title, WorkingTimeId = new Identity <WorkingTimeRange>(task.WorkingTimeId), WorkTaskId = new Identity <WorkTask>(task.WorkTaskId), IsTemporary = task.IsTemporary == "1", IsScheduled = string.IsNullOrEmpty(task.ImportKey) == false, }; list.Add(dto); } var workingHourDao = new WorkingHourDao(c, null); listWorkingHour.AddRange(workingHourDao.SelectByYmdRange(param.start, param.end).Select(r => r.ConvertToDomainObjects())); }); return(new DailyWorkResults { WorkingTimeRecordForReports = list.OrderBy(t => t.StartDateTime).ToArray(), WorkingHours = listWorkingHour.OrderBy(h => h.Ymd).ToArray(), }); }