Пример #1
0
        public async Task <ActionResult <UpdateProductOptionItemOutputModel> > Put(Guid aProductId, Guid aOptionId, UpdateProductOptionItemInputModel aModel)
        {
            try
            {
                UpdateProductOptionOutputDto result = await _aProductOptionService.UpdateProductOption(new UpdateProductOptionInputDto()
                {
                    Id          = aOptionId,
                    Description = aModel.Description,
                    Name        = aModel.Name,
                    ProductId   = aProductId
                });

                if (result.ResultSuccess)
                {
                    UpdateProductOptionItemOutputModel output = _aMapper.Map <UpdateProductOptionItemOutputModel>(result);
                    return(output);
                }

                return(StatusCode(StatusCodes.Status500InternalServerError, result.ResultErrors.Messages.First()));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Server Error :" + e.Message));
            }
        }
Пример #2
0
        public void UpdateOption(Guid id, ProductOption option)
        {
            try
            {
                var original = _productOptionService.GetProductOptionById(id);

                if (original != null)
                {
                    original.Name        = option.Name;
                    original.Description = option.Description;
                    original.ProductId   = option.ProductId;
                    _productOptionService.UpdateProductOption(original);
                }
                else
                {
                    //
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
            }
            catch (Exception ex)
            {
                _loggingService.Error(ex);
                throw;
            }
        }
Пример #3
0
        public async Task <IHttpActionResult> UpdateOption(Guid id, ProductOptionRequestDto requestDto)
        {
            var command = new UpdateProductOptionCommand(id, requestDto.Name, requestDto.Description);

            var result = await _productOptionService.UpdateProductOption(command);

            if (!result.IsSuccess)
            {
                return(BadRequest(result.FailureReason));
            }

            return(Ok());
        }
Пример #4
0
        public async Task <ActionResult <ProductSummary> > Put(Guid id, Guid optionId, [FromBody] ProductOption productOption)
        {
            var updatedProductOption = await productOptionService.UpdateProductOption(id, optionId, productOption);

            var productSummary = new ProductSummary()
            {
                Id       = updatedProductOption.Id,
                Name     = updatedProductOption.Name,
                Location = Url.Link("RetrieveProdctOption", new { id, optionId = updatedProductOption.Id })
            };

            return(CreatedAtRoute("RetrieveProdctOption", new { id, optionId = updatedProductOption.Id }, productSummary));
        }
        public void UpdateProductOption_update_specified_ProductOption_via_repository()
        {
            //Arrange
            var productOptionToUpdate = new core.Models.ProductOption {
                Id = new Guid("5c2996ab-54ad-4999-92d2-89245682d534"), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold Test Mock", Description = "Gold Apple iPhone 6S"
            };

            //Act
            _productOptionService.UpdateProductOption(productOptionToUpdate);
            var updatedProductOption = _productOptionService.GetProductOptionById(new Guid("5c2996ab-54ad-4999-92d2-89245682d534"));

            //Assert
            Assert.IsNotNull(updatedProductOption);
            Assert.AreEqual(updatedProductOption.Name, "Rose Gold Test Mock");
            Assert.AreEqual(updatedProductOption.Name, productOptionToUpdate.Name);
        }
Пример #6
0
        public void UpdateOption(Guid productId, Guid id, ProductOption productOption)
        {
            ValidateProductExists(productId);

            var existingProductOption = _productOptionService.GetProductOption(id);

            new ProductOptionValidator().ValidateProductOption(productOption);

            if (existingProductOption == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            existingProductOption.Name        = productOption.Name;
            existingProductOption.Description = productOption.Description;

            _productOptionService.UpdateProductOption(existingProductOption);
        }