public ActivitiesController(ActivityTrackerContext context)
 {
     _context = context;
     if (!context.Activities.Any())
     {
         Seed(_context);
     }
 }
示例#2
0
 public RolesController(ActivityTrackerContext context)
 {
     _context = context;
 }
 public ProjectsController(ActivityTrackerContext context)
 {
     _context = context;
 }
 public EmployeesController(ActivityTrackerContext context)
 {
     _context = context;
 }
 // Fills database with test data.
 private static void Seed(ActivityTrackerContext context)
 {
     context.Roles.AddRange(
         new Role
     {
         Id   = 1,
         Name = "software engineer"
     },
         new Role
     {
         Id   = 2,
         Name = "software architect"
     },
         new Role
     {
         Id   = 3,
         Name = "team lead"
     }
         );
     context.ActivityTypes.AddRange(
         new ActivityType
     {
         Id   = 1,
         Name = "regular work"
     },
         new ActivityType
     {
         Id   = 2,
         Name = "overtime"
     }
         );
     context.Projects.AddRange(
         new Project
     {
         Id        = 1,
         Name      = "Ableton",
         DateStart = DateTime.Today,
         DateEnd   = DateTime.Today.AddDays(14)
     },
         new Project
     {
         Id        = 2,
         Name      = "Logic Pro",
         DateStart = DateTime.Today,
         DateEnd   = DateTime.Today.AddDays(10)
     }
         );
     context.Employees.AddRange(
         new Employee
     {
         Id          = 1,
         Name        = "Mykola",
         Sex         = Sex.Male,
         DateOfBirth = DateTime.Today.AddYears(-20)
     },
         new Employee
     {
         Id          = 2,
         Name        = "Sasha",
         Sex         = Sex.Female,
         DateOfBirth = DateTime.Today.AddYears(-20)
     }
         );
     context.Activities.AddRange(
         new Activity
     {
         Id             = 1,
         Date           = DateTime.Parse("2020-08-03"),
         HoursOfWork    = 10,
         EmployeeId     = 1,
         ProjectId      = 1,
         RoleId         = 1,
         ActivityTypeId = 1
     },
         new Activity
     {
         Id             = 2,
         Date           = DateTime.Parse("2020-08-03"),
         HoursOfWork    = 5,
         EmployeeId     = 1,
         ProjectId      = 2,
         RoleId         = 2,
         ActivityTypeId = 2
     },
         new Activity
     {
         Id             = 3,
         Date           = DateTime.Parse("2020-08-09"),
         HoursOfWork    = 7,
         EmployeeId     = 1,
         ProjectId      = 2,
         RoleId         = 3,
         ActivityTypeId = 1
     },
         new Activity
     {
         Id             = 4,
         Date           = DateTime.Parse("2020-08-10"),
         HoursOfWork    = 7,
         EmployeeId     = 1,
         ProjectId      = 2,
         RoleId         = 3,
         ActivityTypeId = 1
     }
         );
     context.SaveChanges();
 }