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))); }
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}")); } }
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)); }
public async Task <Guid> AddAsync(ProductOption productOption) { return(await _productOptionRepository.AddAsync(productOption)); }