public void DeleteTime(int id) { Timesheet timeSheet = _context.TimeSheets.SingleOrDefault(t => t.Id == id); if (timeSheet != null) { _context.Remove(timeSheet); _context.SaveChanges(); } }
public MainWindow() { InitializeComponent(); OnReloadButtonClick(null, null); using (var db = new TimeLoggerContext()) { var todayData = db.AttendanceLeaves.Where(a => a.TargetDate == DateTime.Today).ToList(); if (todayData == null || todayData.Count == 0) { var attendance = new AttendanceWindow(); attendance.Topmost = true; Task startupTask = attendance.doAttendance(); if (startupTask != null) { onTaskStart(startupTask); } var attendanceRecord = new AttendanceLeave(); attendanceRecord.TargetDate = DateTime.Today; attendanceRecord.Attendance = DateTime.Now; db.AttendanceLeaves.Add(attendanceRecord); db.SaveChanges(); } } if (runningTask == null) { CurrentTaskLabel.Content = "未割当"; } }
private void onLeaveClick(object sender, RoutedEventArgs e) { onTaskStop(runningTask); using (var db = new TimeLoggerContext()) { var todayData = db.AttendanceLeaves.Where(a => a.TargetDate == DateTime.Today).First(); todayData.Leave = DateTime.Now; db.SaveChanges(); } Close(); }
private void onTaskStart(Task task) { if (runningTask != null) { onTaskStop(runningTask); } runningTask = task; runningFact = new TaskWorkFact(); runningFact.TaskId = task.Id.Value; runningFact.StartAt = DateTime.Now; using (var db = new TimeLoggerContext()) { db.TaskWorkFacts.Add(runningFact); db.SaveChanges(); } CurrentTaskLabel.Content = runningTask; }
private void onTaskStop(Task task) { if (runningTask == null) { return; } runningFact.EndAt = DateTime.Now; runningFact.updateManhour(); using (var db = new TimeLoggerContext()) { db.TaskWorkFacts.Attach(runningFact); db.Entry(runningFact).State = EntityState.Modified; db.SaveChanges(); } runningFact = null; runningTask = null; CurrentTaskLabel.Content = "未割当"; }
private void OnOkButtonClick(object sender, RoutedEventArgs e) { using (var db = new TimeLoggerContext()) { var tasks = taskTable.ItemsSource.OfType <Task>().ToList(); foreach (var task in tasks) { if (task.Id == null) { db.Tasks.Add(task); } else { db.Tasks.Attach(task); // FIXME すべてのレコードが必ず更新される db.Entry(task).State = System.Data.Entity.EntityState.Modified; } } db.SaveChanges(); } Close(); }