Beispiel #1
0
        public void CreateOption(Guid productId, ProductOptionData option)
        {
            var newProductOption = new ProductOption(option.Id, productId);

            newProductOption.Update(option);
            _productOptions.Add(newProductOption);
        }
        public async Task <IActionResult> UpdateOptionAsync(Guid id, [FromBody] ProductOption option)
        {
            try
            {
                var searchResult = await this._productOptionsRepository.GetByIdAsync(id);

                if (null == searchResult)
                {
                    return(NotFound());
                }
                else
                {
                    await this._productOptionsRepository.UpdateAsync(option.Update(searchResult));

                    return(new CreatedResult(nameof(UpdateOptionAsync), ProductOption.FromProductOption(searchResult)));
                }
            }
            catch (Exception ex)
            {
                var errorResponse = ResponseManager.FormErrorResponse(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errorResponse));
            }
        }
        public HttpResponseMessage update(ProductOption post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (ProductOptionType.MasterPostExists(post.product_option_type_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The product option type does not exist"));
            }
            else if (Option.MasterPostExists(post.option_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The option does not exist"));
            }

            // Make sure that the data is valid
            post.mpn_suffix       = AnnytabDataValidation.TruncateString(post.mpn_suffix, 10);
            post.price_addition   = AnnytabDataValidation.TruncateDecimal(post.price_addition, 0, 9999999999.99M);
            post.freight_addition = AnnytabDataValidation.TruncateDecimal(post.freight_addition, 0, 9999999999.99M);

            // Get the saved post
            ProductOption savedPost = ProductOption.GetOneById(post.product_option_type_id, post.option_id);

            // Check if the post exists
            if (savedPost == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist"));
            }

            // Update the post
            ProductOption.Update(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful"));
        } // End of the update method
Beispiel #4
0
 public StatusCode UpdateOption(Guid id, ProductOption option)
 {
     return(Helpers.ResponseMaker(option.Update(id)));
 }