public IHttpActionResult PostEmployeeInternationalPassport(EmployeeInternationalPassportDTO employeeInternationalPassport) { if (employeeInternationalPassport == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } try { EmployeeInternationalPassport passport = employeeInternationalPassport.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); passport.Id = passport.NewId(unitOfWork); unitOfWork.EmployeeInternationalPassportsRepository.Insert(passport); unitOfWork.Save(); EmployeeInternationalPassportDTO dto = passport.ToDTO(); return(CreatedAtRoute("GetEmployeeInternationalPassport", new { id = dto.Id }, dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult DeleteEmployeeInternationalPassport(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeInternationalPassport passport = unitOfWork.EmployeeInternationalPassportsRepository.GetByID(id); passport.Deleted = true; unitOfWork.EmployeeInternationalPassportsRepository.Update(passport); unitOfWork.Save(); EmployeeInternationalPassportDTO dto = passport.ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PutEmployeeInternationalPassport(int id, EmployeeInternationalPassportDTO employeeInternationalPassport) { if (employeeInternationalPassport == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeInternationalPassport.Id) { return(BadRequest()); } try { EmployeeInternationalPassport passport = employeeInternationalPassport.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); unitOfWork.EmployeeInternationalPassportsRepository.Update(passport); unitOfWork.Save(); EmployeeInternationalPassportDTO dto = passport.ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult GetEmployeeInternationalPassport(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeInternationalPassportDTO internationalPassport = unitOfWork.EmployeeInternationalPassportsRepository.GetByID(id).ToDTO(); return(Ok(internationalPassport)); } catch (Exception e) { return(BadRequest()); } }