Exemplo n.º 1
0
 /// <summary>
 /// dodanie pracownika do bazy danych
 /// </summary>
 public void AddEmployee(Models.Employee employee)
 {
     using (DatabaseEntities1 context = new DatabaseEntities1())
     {
         context.Employees.Add(new Employee
         {
             FirstName = employee.FirstName,
             LastName = employee.LastName,
             Mail = employee.Mail,
             PhoneOffice = employee.OfficePhone,
             PhoneMobile = employee.MobilePhone,
             Position = employee.Position,
             Salary = employee.Salary,
             EmploymentDate = employee.EmploymentDate
         });
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// edycja danych pracownika
        /// </summary>
        public void UpdateEmployee(Models.Employee employee)
        {
            using (DatabaseEntities1 context = new DatabaseEntities1())
            {
               var employeeToUpdate = from u in context.Employees where u.Id == employee.Id select u;

                if (employeeToUpdate != null)
                {
                    foreach (var i in employeeToUpdate)
                    {
                        i.FirstName = employee.FirstName;
                        i.LastName = employee.LastName;
                        i.PhoneMobile = employee.MobilePhone;
                        i.PhoneOffice = employee.OfficePhone;
                        i.Mail = employee.Mail;
                        i.Position = employee.Position;
                        i.Salary = employee.Salary;
                        i.EmploymentDate = employee.EmploymentDate;
                    }
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// usunięcie pracownika z bazy danych
        /// </summary>
        public void DeleteEmployee(Models.Employee employee)
        {
            using (DatabaseEntities1 context = new DatabaseEntities1())
            {
                var employeeToDelete = (from d in context.Employees where d.Id == employee.Id select d).FirstOrDefault();

                if (employeeToDelete != null)
                {
                    context.Employees.Remove(employeeToDelete);
                    context.SaveChanges();
                }
            }
        }