Exemple #1
0
 public void updateEmployee(int Id, string Name)
 {
     //will update all the employee
     using (EmployeeDbContainer db = new EmployeeDbContainer())
     {
         var emp = db.Employees.Where(x => x.Id == Id).FirstOrDefault();
         emp.Name = Name;
         db.SaveChanges();
     }
 }
Exemple #2
0
 public void deleteEmployee(int Id)
 {
     //will delete all employee
     using (EmployeeDbContainer db = new EmployeeDbContainer())
     {
         var emp = db.Employees.Where(x => x.Id == Id).FirstOrDefault();
         db.Employees.Remove(emp);
         db.SaveChanges();
     }
 }
Exemple #3
0
 public void saveEmployee(EmployeeEntity obj)
 {
     //will save all the employee
     using (EmployeeDbContainer db = new EmployeeDbContainer())
     {
         Employee emp = new Employee
         {
             Id   = obj.Id,
             Name = obj.Name
         };
         db.Employees.Add(emp);
         db.SaveChanges();
     }
 }
Exemple #4
0
        public void getAllEmployee()
        {
            //this will get all the employee from the databasea
            List <EmployeeEntity> listEmp = new List <EmployeeEntity>();

            using (EmployeeDbContainer db = new EmployeeDbContainer())
            {
                listEmp = db.Employees.Select(x => new EmployeeEntity {
                    Id = x.Id, Name = x.Name
                }).ToList();
            }
            //populating the datagridview
            dgvEmployee.DataSource = listEmp;
        }
Exemple #5
0
        public int getTempID()
        {
            //getting a temporary ID
            int Id = 0;

            using (EmployeeDbContainer db = new EmployeeDbContainer())
            {
                var empID = db.Employees.OrderByDescending(x => x.Id).FirstOrDefault();
                if (empID == null)
                {
                    Id = 0;
                }
                else
                {
                    Id = empID.Id;
                }
            }
            return(Id + 1);
        }