Example #1
0
        public IHttpActionResult PutConcert([FromUri] int id, [FromBody] PolicyDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var originalPolicy = repository.GetPolicy(id);

            if (originalPolicy == null)
            {
                return(NotFound());
            }

            var etag = new EntityTagHeaderValue($"\"{Hash(originalPolicy.LastUpdated.ToString())}\"");

            if (Request.Headers.IfMatch.ToString() != etag.ToString())
            {
                return(Content <string>(HttpStatusCode.PreconditionFailed, "If-Match value is no longer valid"));
            }

            var policy   = mapper.Map <PolicyDto, Policy>(dto);
            var response = repository.UpdatePolicy(id, policy);

            if (response == null)
            {
                return(NotFound());
            }

            var updatedDto = mapper.Map <Policy, PolicyDto>(response);

            return(new CustomOkResult <PolicyDto>(updatedDto, this)
            {
                ETagValue = Hash(updatedDto.LastUpdated.ToString())
            });
        }