public HttpResponseMessage Post(HttpRequestMessage request, PriceHistoryViewModel priceHistoryVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { PriceHistory newPriceHistory = new PriceHistory(); newPriceHistory.UpdatePriceHistory(priceHistoryVm); var category = _priceHistoryService.Add(newPriceHistory); _priceHistoryService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.Created, category); } return response; })); }