Esempio n. 1
0
 public bool Delete(int id)
 {
     try
     {
         using (Employee_RecoredEntities db = new Employee_RecoredEntities())
         {
             Employee employee = (from x in db.Employees
                                  where x.Id == id
                                  select x).FirstOrDefault();
             if (employee == null)
             {
                 return(false);
             }
             else
             {
                 db.Employees.Remove(employee);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 2
0
        public bool Update(EmployeeDB employee)
        {
            try
            {
                using (Employee_RecoredEntities db = new Employee_RecoredEntities())
                {
                    Employee item = (from x in db.Employees
                                     where x.Id == employee.Id
                                     select x).FirstOrDefault();
                    if (item == null)
                    {
                        return(false);
                    }

                    item.EmpName     = employee.EmpName;
                    item.Email       = employee.Email;
                    item.DateofBirth = employee.DateofBirth;
                    item.Phone       = employee.Phone;
                    item.Gender      = employee.Gender;
                    item.Address     = employee.Address;
                    item.City        = employee.City;
                    item.Department  = employee.Department;
                    item.Salary      = employee.Salary;
                    item.JoiningDate = employee.JoiningDate;
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 3
0
 public EmployeeDB Insert(EmployeeDB employee)
 {
     try
     {
         Employee emp = new Employee();
         emp.EmpName     = employee.EmpName;
         emp.Email       = employee.Email;
         emp.DateofBirth = employee.DateofBirth;
         emp.Phone       = employee.Phone;
         emp.Gender      = employee.Gender;
         emp.Address     = employee.Address;
         emp.City        = employee.City;
         emp.Department  = employee.Department;
         emp.Salary      = employee.Salary;
         emp.JoiningDate = employee.JoiningDate;
         using (Employee_RecoredEntities db = new Employee_RecoredEntities())
         {
             db.Employees.Add(emp);
             db.SaveChanges();
         }
         employee.Id = emp.Id;
         return(employee);
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         throw;
     }
 }