Beispiel #1
0
        public HttpResponseMessage Post(DTO.TaskFilter taskFilter)
        {
            #region Preconditions

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

            if (taskFilter == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            var userTaskFilter = UserTaskFilterMapper.TranslateDTOTaskFilterToModelUserTaskFilter(taskFilter);

            int?newId = userTaskFilterRepository.Add(userTaskFilter);

            if (newId == null)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            taskFilter.FilterId = newId.Value;

            var response = Request.CreateResponse <DTO.TaskFilter>(HttpStatusCode.Created, taskFilter);

            string uri = Url.Link("AddFilter", new { id = taskFilter.FilterId });
            response.Headers.Location = new Uri(uri);
            return(response);
        }
Beispiel #2
0
        public void Put(int id, DTO.TaskFilter taskFilter)
        {
            #region Preconditions

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

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

            if (taskFilter == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            taskFilter.FilterId = id;

            var userTaskFilter = UserTaskFilterMapper.TranslateDTOTaskFilterToModelUserTaskFilter(taskFilter);

            if (!userTaskFilterRepository.Update(userTaskFilter))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }