public virtual HttpResponseMessage EditOption(HttpRequestMessage request, SpecificationAttributeOptionVM model) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No specification attribute option found with the specified id"); if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var sao = _specificationAttributeService.GetSpecificationAttributeOptionById(model.Id); if (sao != null) { sao = model.ToEntity(sao); //clear "Color" values if it's disabled if (!model.EnableColorSquaresRgb) { sao.ColorSquaresRgb = null; } _specificationAttributeService.UpdateSpecificationAttributeOption(sao); _baseService.Commit(); response = request.CreateResponse <SpecificationAttributeOptionVM>(HttpStatusCode.OK, model); } } return response; })); }
public HttpResponseMessage CreateOption(HttpRequestMessage request, SpecificationAttributeOptionVM model) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid specification attribute id."); if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var specificationAttribute = _specificationAttributeService.GetSpecificationAttributeById(model.SpecificationAttributeId); if (specificationAttribute != null) { var sao = model.ToEntity(); //clear "Color" values if it's disabled if (!model.EnableColorSquaresRgb) { sao.ColorSquaresRgb = null; } _specificationAttributeService.InsertSpecificationAttributeOption(sao); _baseService.Commit(); response = request.CreateResponse <SpecificationAttributeOption>(HttpStatusCode.Created, sao); } } return response; })); }