Ejemplo n.º 1
0
 public IHttpActionResult PostEmployeeLanguage(EmployeeLanguageDTO employeeLanguage)
 {
     if (employeeLanguage == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         EmployeeLanguage language   = employeeLanguage.FromDTO();
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         language.Id = language.NewId(unitOfWork);
         unitOfWork.EmployeeLanguagesRepository.Insert(language);
         unitOfWork.Save();
         EmployeeLanguageDTO dto = unitOfWork.EmployeeLanguagesRepository.Get(d => d.Id == language.Id, includeProperties: "Language,EmployeeLanguageType").FirstOrDefault().ToDTO();
         return(CreatedAtRoute("GetEmployeeLanguage", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 2
0
 public IHttpActionResult DeleteEmployeeLanguage(int id)
 {
     try
     {
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         EmployeeLanguage language   = unitOfWork.EmployeeLanguagesRepository.Get(d => d.Id == id, includeProperties: "Language,EmployeeLanguageType").FirstOrDefault();
         language.Deleted = true;
         unitOfWork.EmployeeLanguagesRepository.Update(language);
         unitOfWork.Save();
         EmployeeLanguageDTO dto = language.ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 3
0
 public IHttpActionResult PutEmployeeLanguage(int id, EmployeeLanguageDTO employeeLanguage)
 {
     if (employeeLanguage == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != employeeLanguage.Id)
     {
         return(BadRequest());
     }
     try
     {
         EmployeeLanguage language   = employeeLanguage.FromDTO();
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         unitOfWork.EmployeeLanguagesRepository.Update(language);
         unitOfWork.Save();
         EmployeeLanguageDTO dto = unitOfWork.EmployeeLanguagesRepository.Get(d => d.Id == id, includeProperties: "Language,EmployeeLanguageType").FirstOrDefault().ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }