public IHttpActionResult DeleteEmployeeContact(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeContact employeeContact = unitOfWork.EmployeeContactsRepository.Get(d => d.Id == id, includeProperties: "ContactType").FirstOrDefault(); employeeContact.Deleted = true; unitOfWork.EmployeeContactsRepository.Update(employeeContact); unitOfWork.Save(); EmployeeContactDTO dto = employeeContact.ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PostEmployeeContact(EmployeeContactDTO employeeContact) { if (employeeContact == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } try { EmployeeContact contact = employeeContact.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); contact.Id = contact.NewId(unitOfWork); unitOfWork.EmployeeContactsRepository.Insert(contact); unitOfWork.Save(); EmployeeContactDTO dto = unitOfWork.EmployeeContactsRepository.Get(d => d.Id == contact.Id, includeProperties: "ContactType").FirstOrDefault().ToDTO(); return(CreatedAtRoute("GetEmployeeContact", new { id = dto.Id }, dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult GetEmployeeContact(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeContactDTO employeeContact = unitOfWork.EmployeeContactsRepository.Get(d => d.Id == id, includeProperties: "ContactType").FirstOrDefault().ToDTO(); return(Ok(employeeContact)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (NullReferenceException nre) { return(NotFound()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PutEmployeeContact(int id, EmployeeContactDTO employeeContact) { if (employeeContact == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeContact.Id) { return(BadRequest()); } try { EmployeeContact contact = employeeContact.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); unitOfWork.EmployeeContactsRepository.Update(contact); unitOfWork.Save(); EmployeeContactDTO dto = unitOfWork.EmployeeContactsRepository.Get(d => d.Id == id, includeProperties: "ContactType").FirstOrDefault().ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (NullReferenceException nre) { return(NotFound()); } catch (Exception e) { return(BadRequest(e.Message)); } }