Ejemplo n.º 1
0
 public Employee DTOToEmployee(EmployeeDTO a)
 {
     Console.WriteLine("-------------" + a.RoleID);
     if (a.AddressID <= 0)
     {
         return new Employee {
                    Address = null, Role = dbm.FindRoleByID(a.RoleID), DateOfBirth = DateTime.Parse(a.DateOfBirth), PhoneNumber = a.PhoneNumber, Email = a.Email, EmployeeID = a.EmployeeID, FirstName = a.FirstName, HireDate = DateTime.Parse(a.HireDate), Username = a.Username, LastName = a.LastName
         }
     }
     ;
     else
     {
         return new Employee {
                    Address = dbm.FindAddressByID(a.AddressID.Value), DateOfBirth = DateTime.Parse(a.DateOfBirth), PhoneNumber = a.PhoneNumber, Email = a.Email, EmployeeID = a.EmployeeID, FirstName = a.FirstName, HireDate = DateTime.Parse(a.HireDate), Username = a.Username, LastName = a.LastName, Role = dbm.FindRoleByID(a.RoleID)
         }
     };
 }
Ejemplo n.º 2
0
        public void DeleteEmployee(int id)
        {
            var emp = db.Employee.Include(x => x.Address).First(x => x.EmployeeID == id);
            var et  = dbm.FindEmployeeTeamsByEmployeeID(id);

            for (int i = 0; i < et.Count; i++)
            {
                db.EmployeeTeam.Remove(et[i]);
            }

            if (emp.Address != null)
            {
                var add = dbm.FindAddressByID(emp.Address.AddressID);
                if (db.Employee.Include(x => x.Address).Where(x => x.Address.AddressID == add.AddressID).ToList().Count() <= 1)
                {
                    db.Address.Remove(add);
                }
            }

            db.Employee.Remove(emp);

            db.SaveChanges();
        }
Ejemplo n.º 3
0
 public AddressDTO GetAddress(int id)
 {
     return(converter.AddressToDTO(dbm.FindAddressByID(id)));
 }