Beispiel #1
0
        public async Task <IActionResult> AddProductToProductGroup(string name, string productCode)
        {
            if (!await _productGroupRepository.ProductGroupExists(name))
            {
                return(NotFound());
            }

            var productGroup = await _productGroupRepository.GetProductGroupByName(name);

            var product = await _productGroupRepository.GetProductByCode(productCode);

            if (product == null)
            {
                return(NotFound());
            }

            productGroup.Products.Add(new ProductGroupProduct {
                IDProduct = product.IDProduct
            });
            await _unitOfWork.Commit();

            var updatedProductGroup = await _productGroupRepository.GetById(productGroup.IDProductGroup);

            var groupToReturn = Mapper.Map <ProductGroupDto>(updatedProductGroup);

            return(Ok(groupToReturn));
        }