Exemplo n.º 1
0
 public List <Country> GetList()
 {
     using (var db = new EmployeesDBContext())
     {
         return(db.Countries.ToList());
     }
 }
 public Employee GetById(int id)
 {
     using (var db = new EmployeesDBContext())
     {
         return(db.Employees.FirstOrDefault(e => e.Id == id));
     }
 }
Exemplo n.º 3
0
 public List <CityVM> GetListByCountryId(int countryId)
 {
     using (var db = new EmployeesDBContext())
     {
         return(db.Cities.Where(c => c.CountryId == countryId).Select(c => new CityVM
         {
             Id = c.Id,
             Name = c.Name
         }).ToList());
     }
 }
 public bool Create(Employee employee)
 {
     using (var db = new EmployeesDBContext())
     {
         try
         {
             db.Employees.Add(employee);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
 public List <EmployeeListVM> GetList()
 {
     using (var db = new EmployeesDBContext())
     {
         var employees = db.Employees.Select(e => new EmployeeListVM
         {
             Id        = e.Id,
             Name      = e.Name,
             Gender    = e.Gender,
             Birthdate = e.Birthdate,
             CityId    = e.CityId,
             CiyName   = e.CityId != null?e.City.Name:null
         }).ToList();
         return(employees);
     }
 }
 public bool Delete(int id)
 {
     using (var db = new EmployeesDBContext())
     {
         try
         {
             var q = db.Employees.FirstOrDefault(x => x.Id == id);
             if (q != null)
             {
                 db.Employees.Remove(q);
                 db.SaveChanges();
             }
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
 public bool Update(Employee employee)
 {
     using (var db = new EmployeesDBContext())
     {
         try
         {
             var q = db.Employees.FirstOrDefault(e => e.Id == employee.Id);
             if (q != null)
             {
                 q.Id        = employee.Id;
                 q.Name      = employee.Name;
                 q.Gender    = employee.Gender;
                 q.Birthdate = employee.Birthdate;
                 q.CityId    = employee.CityId;
                 db.SaveChanges();
             }
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemplo n.º 8
0
 public AccountController(EmployeesDBContext context)
 {
     _context = context;
 }
Exemplo n.º 9
0
 public ManagerService(EmployeesDBContext db)
     : base(db)
 {
 }
Exemplo n.º 10
0
 protected Service(EmployeesDBContext db)
 {
     this.db = db;
 }
Exemplo n.º 11
0
 public EmployeeService(EmployeesDBContext db)
     : base(db)
 {
 }
Exemplo n.º 12
0
 public PeopleController(EmployeesDBContext context)
 {
     _context = context;
 }
Exemplo n.º 13
0
 public EmployeesController(EmployeesDBContext context)
 {
     _context = context;
 }
Exemplo n.º 14
0
 public DBInitializeService(EmployeesDBContext db)
     : base(db)
 {
 }