コード例 #1
0
        public async Task <IHttpActionResult> CreateOption(Guid productId, ProductOptionInsertDto option)
        {
            var productOption = Mapper.Map <ProductOption>(option);

            productOption.ProductId = productId;

            var insertedProductOption = await _productOptionRepository.AddAsync(productOption);

            return(Ok(Mapper.Map <ProductOptionDto>(insertedProductOption)));
        }
コード例 #2
0
        public async Task <ProductOptionResponse> SaveProductOptionAsync(Guid productId, ProductOption productOption)
        {
            try
            {
                productOption.ProductId = productId;
                await _productOptionRepository.AddAsync(productOption);

                await _unitOfWork.CompleteAsync();

                return(new ProductOptionResponse(productOption));
            }
            catch (Exception ex)
            {
                return(new ProductOptionResponse($"Error occurred while saving option: {ex.Message}"));
            }
        }
コード例 #3
0
        public async Task <IActionResult> CreateOptionAsync(Guid id, NewProductOption productOption)
        {
            Guard.Against.NullGuid(id, nameof(id));

            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                return(BadRequest(ModelState));
            }

            // Can use AutoMapper normally but ignoring for this
            var productOptionModel = new ProductOption
            {
                ProductId   = id,
                Name        = productOption.Name,
                Description = productOption.Description,
            };
            var savedProductOption = await _productOptionsRepository.AddAsync(productOptionModel);

            return(CreatedAtAction(nameof(GetProductOptionAsync), new { id = savedProductOption.ProductId, optionId = savedProductOption.Id }, savedProductOption));
        }
コード例 #4
0
 public async Task <Guid> AddAsync(ProductOption productOption)
 {
     return(await _productOptionRepository.AddAsync(productOption));
 }