Ejemplo n.º 1
0
    public async Task SeedAsync()
    {
        if (_context.Set <Department>().Any())
        {
            return;
        }

        var employees   = GetEmployees();
        var departments = GetDepartments();
        var jobs        = GetJobs();

        employees[0].AssignJob(departments[0], jobs[0], DateTime.Parse("2018-07-01"));
        employees[1].AssignJob(departments[1], jobs[1], DateTime.Parse("2018-07-01"));
        employees[2].AssignJob(departments[2], jobs[2], DateTime.Parse("2018-07-01"));
        employees[3].AssignJob(departments[3], jobs[2], DateTime.Parse("2018-07-15"));
        employees[4].AssignJob(departments[4], jobs[2], DateTime.Parse("2018-08-04"));
        employees[5].AssignJob(departments[1], jobs[3], DateTime.Parse("2018-08-04"));
        employees[6].AssignJob(departments[2], jobs[6], DateTime.Parse("2018-08-04"));
        employees[7].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[8].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[9].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[10].AssignJob(departments[4], jobs[5], DateTime.Parse("2018-08-04"));
        employees[11].AssignJob(departments[4], jobs[5], DateTime.Parse("2018-08-04"));

        _context.Set <Employee>().AddRange(employees);
        _context.Set <Department>().AddRange(departments);
        _context.Set <Job>().AddRange(jobs);

        _context.LogEvents();
        await _context.SaveChangesAsync();
    }
Ejemplo n.º 2
0
        public async Task <List <T> > GetAll()
        {
            var task = await Task.Run(() => {
                return(db.Set <T>()
                       .AsNoTracking()
                       .ToList());
            });

            return(task);
        }
Ejemplo n.º 3
0
 public JobRepository(HRContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _jobs    = context.Set <Job>();
 }
Ejemplo n.º 4
0
 public EmployeeRepository(HRContext context)
 {
     _context   = context ?? throw new ArgumentNullException(nameof(context));
     _employees = context.Set <Employee>();
 }
Ejemplo n.º 5
0
 public async Task <ActionResult <T> > GetById(int id)
 {
     return(await _context.Set <T>().FindAsync(id));
 }
Ejemplo n.º 6
0
 public DepartmentRepository(HRContext context)
 {
     _context     = context ?? throw new ArgumentNullException(nameof(context));
     _departments = context.Set <Department>();
 }