예제 #1
0
        public bool AddEmployee(EmployeesRequestDto newEmployee)
        {
            try
            {
                var employeeToAdd = new Pracownik
                {
                    Imie        = newEmployee.FirstName,
                    Nazwisko    = newEmployee.LastName,
                    RokUr       = newEmployee.BirthYear,
                    Miasto      = newEmployee.City,
                    Stanowisko  = newEmployee.Job,
                    Email       = newEmployee.Email,
                    NrTel       = newEmployee.PhoneNo,
                    TablicaInfo = newEmployee.Info
                };

                context.Pracownik.Add(employeeToAdd);
                context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #2
0
 public IActionResult UpdateEmployee(int id, EmployeesRequestDto requestDto)
 {
     if (_service.UpdateEmployee(id, requestDto))
     {
         return(Ok($"Employee with id ({id}) has been updated."));
     }
     else
     {
         return(BadRequest($"Employee with provided id ({id}) not found"));
     }
 }
예제 #3
0
 public IActionResult AddEmployee(EmployeesRequestDto requestDto)
 {
     if (_service.AddEmployee(requestDto))
     {
         return(Ok("New employee created"));
     }
     else
     {
         return(BadRequest("Something went wrong"));
     }
 }
예제 #4
0
        public bool UpdateEmployee(int id, EmployeesRequestDto updateEmployee)
        {
            var employeeToEdit = context.Pracownik.SingleOrDefault(x => x.Idpracownik == id);

            if (employeeToEdit == null)
            {
                return(false);
            }
            else
            {
                employeeToEdit.Imie        = updateEmployee.FirstName;
                employeeToEdit.Nazwisko    = updateEmployee.LastName;
                employeeToEdit.RokUr       = updateEmployee.BirthYear;
                employeeToEdit.Miasto      = updateEmployee.City;
                employeeToEdit.Stanowisko  = updateEmployee.Job;
                employeeToEdit.Email       = updateEmployee.Email;
                employeeToEdit.NrTel       = updateEmployee.PhoneNo;
                employeeToEdit.TablicaInfo = updateEmployee.Info;
                context.SaveChanges();
                return(true);
            }
        }