public HttpResponseMessage Post(DTO.ControlPriority controlPriority) { #region Preconditions if (controlPriorityRepository == null) { throw new InvalidOperationException(); } if (controlPriority == null) { throw new ArgumentNullException(); } #endregion #region Validation if (controlPriority.Id != null) { throw new InvalidOperationException(); } if (string.IsNullOrWhiteSpace(controlPriority.Name)) { throw new InvalidOperationException(); } if (controlPriority.Name.Length > 50) { throw new InvalidOperationException(); } #endregion var modelControlPriority = ControlPriorityMapper.TranslateDTOControlPriorityToModelControlPriority(controlPriority); int?newId = controlPriorityRepository.Add(modelControlPriority); if (newId == null) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } controlPriority.Id = newId.Value; var response = Request.CreateResponse <DTO.ControlPriority>(HttpStatusCode.Created, controlPriority); string uri = Url.Link("AddControlPriority", new { id = controlPriority.Id }); response.Headers.Location = new Uri(uri); return(response); }
public void Put(int id, DTO.ControlPriority controlPriority) { #region Preconditions if (controlPriorityRepository == null) { throw new InvalidOperationException(); } if (id <= 0) { throw new ArgumentOutOfRangeException(); } if (controlPriority == null) { throw new ArgumentNullException(); } #endregion #region Validation if (controlPriority.Id == null) { throw new HttpResponseException(HttpStatusCode.NotAcceptable); } if (string.IsNullOrWhiteSpace(controlPriority.Name)) { throw new HttpResponseException(HttpStatusCode.NotAcceptable); } if (controlPriority.Name.Length > 50) { throw new HttpResponseException(HttpStatusCode.NotAcceptable); } #endregion controlPriority.Id = id; var modelControlPriority = ControlPriorityMapper.TranslateDTOControlPriorityToModelControlPriority(controlPriority); if (!controlPriorityRepository.Update(modelControlPriority)) { throw new HttpResponseException(HttpStatusCode.NotFound); } }