public IHttpActionResult Get(int id, int?DefinitionSourceId = null, int?ControlPriorityClassificationId = null)
        {
            #region Preconditions

            if (controlPriorityRepository == null)
            {
                throw new InvalidOperationException();
            }

            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            #endregion

            try
            {
                var controlPriority = controlPriorityRepository.GetItem(id);

                var dtoControlPriority = ControlPriorityMapper.TranslateModelControlPriorityToDTOControlPriority(controlPriority);

                return(Ok(dtoControlPriority));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
        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);
            }
        }
        public IHttpActionResult Get()
        {
            #region Preconditions

            if (controlPriorityRepository == null)
            {
                throw new InvalidOperationException();
            }

            #endregion

            try
            {
                var controlPriorities = controlPriorityRepository.GetItems();

                var dtoControlPriorities = controlPriorities.Select(cs => ControlPriorityMapper.TranslateModelControlPriorityToDTOControlPriority(cs));

                return(Ok(dtoControlPriorities));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }