// Puts sample data into the database protected override void Seed(TimeSheetDb context) { // LeaveApplications List <LeaveApplication> applications = new List <LeaveApplication>(); List <TimeRecord> timeRecords = new List <TimeRecord>(); DateTime startDate = new DateTime(2017, 1, 1); Task.Run(() => ADUser.GetADUser()); for (int i = 0; i < 10; i++) { LeaveApplication newApplication = new LeaveApplication(); newApplication.UserID = "*****@*****.**"; newApplication.UserName = "******"; newApplication.ManagerIDs = "*****@*****.**"; newApplication.StartTime = startDate.AddDays(i * 4); newApplication.EndTime = startDate.AddDays(i * 4 + 3); newApplication.leaveType = (_leaveType)(i % 3); newApplication.status = (_status)(i % 4); newApplication.SubmittedTime = new DateTime(2017, 2, 1); if (newApplication.status == _status.approved || newApplication.status == _status.rejected) { newApplication.ApprovedTime = new DateTime(2017, 1, 10); newApplication.ApprovedBy = newApplication.ManagerIDs; } newApplication.TotalLeaveTime = 30; applications.Add(newApplication); // TimeRecords for (int j = 0; j < 4; j++) { TimeRecord newTimeRecord = new TimeRecord(startDate.AddDays(i * 4 + j)); newTimeRecord.UserID = "*****@*****.**"; newTimeRecord.LeaveType = (_leaveType)(i % 3); PayPeriod.SetPublicHoliday(newTimeRecord); if (!newTimeRecord.IsHoliday) { newTimeRecord.LeaveTime = 7.5; newTimeRecord.SetAttendence(null, null, 0); timeRecords.Add(newTimeRecord); } } } for (int i = 0; i < 10; i++) { LeaveApplication newApplication = new LeaveApplication(); newApplication.UserID = "*****@*****.**"; newApplication.UserName = "******"; newApplication.ManagerIDs = "*****@*****.**"; newApplication.StartTime = startDate.AddDays(i * 3); newApplication.EndTime = startDate.AddDays(i * 3 + 2); newApplication.leaveType = (_leaveType)((i + 1) % 3); newApplication.status = (_status)(i % 4 + 1); newApplication.SubmittedTime = new DateTime(2017, 1, 10); if (newApplication.status == _status.approved || newApplication.status == _status.rejected) { newApplication.ApprovedTime = new DateTime(2017, 1, 10); newApplication.ApprovedBy = newApplication.ManagerIDs; } newApplication.TotalLeaveTime = 22.5; applications.Add(newApplication); // TimeRecords for (int j = 0; j < 3; j++) { TimeRecord newTimeRecord = new TimeRecord(startDate.AddDays(i * 3 + j)); newTimeRecord.UserID = "*****@*****.**"; newTimeRecord.LeaveType = (_leaveType)((i + 1) % 3); PayPeriod.SetPublicHoliday(newTimeRecord); if (!newTimeRecord.IsHoliday) { newTimeRecord.LeaveTime = 7.5; newTimeRecord.SetAttendence(null, null, 0); timeRecords.Add(newTimeRecord); } } } for (int i = 0; i < 10; i++) { LeaveApplication newApplication = new LeaveApplication(); newApplication.UserID = "*****@*****.**"; newApplication.UserName = "******"; newApplication.ManagerIDs = "*****@*****.**"; newApplication.StartTime = startDate.AddDays(i * 3); newApplication.EndTime = startDate.AddDays(i * 3 + 2); newApplication.leaveType = (_leaveType)((i + 1) % 3); newApplication.status = (_status)(i % 4 + 1); newApplication.SubmittedTime = new DateTime(2017, 1, 1); if (newApplication.status == _status.approved || newApplication.status == _status.rejected) { newApplication.ApprovedTime = new DateTime(2017, 1, 10); newApplication.ApprovedBy = newApplication.ManagerIDs; } newApplication.TotalLeaveTime = 22.5; applications.Add(newApplication); // TimeRecords for (int j = 0; j < 3; j++) { TimeRecord newTimeRecord = new TimeRecord(startDate.AddDays(i * 3 + j)); newTimeRecord.UserID = "*****@*****.**"; newTimeRecord.LeaveType = (_leaveType)((i + 1) % 3); PayPeriod.SetPublicHoliday(newTimeRecord); if (!newTimeRecord.IsHoliday) { newTimeRecord.LeaveTime = 7.5; newTimeRecord.SetAttendence(null, null, 0); timeRecords.Add(newTimeRecord); } } } applications.ForEach(a => context.LeaveApplications.Add(a)); timeRecords.ForEach(t => context.TimeRecords.Add(t)); context.SaveChanges(); // Initialise Leaves context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.annual, AvailableLeaveHours = 100.39 }); context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.flexi, AvailableLeaveHours = 22.5 }); context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.sick, AvailableLeaveHours = 20 }); context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.annual, AvailableLeaveHours = 123 }); context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.flexi, AvailableLeaveHours = 34 }); context.LeaveBalances.Add(new LeaveBalance { UserID = "*****@*****.**", LeaveType = _leaveType.sick, AvailableLeaveHours = 1.53 }); context.ADUsers.Add(new ADUser { UserName = "******", Email = "*****@*****.**", JobCode = "Lecturer", Department = "IT" }); context.ADUsers.Add(new ADUser { UserName = "******", Email = "*****@*****.**", JobCode = "Lecturer", Department = "IT" }); context.SaveChanges(); }