예제 #1
0
        public async Task <ProductOptionDto> CreateAsync(ProductOptionDto productOption)
        {
            if (productOption.Id == Guid.Empty)
            {
                productOption.Id = Guid.NewGuid();
            }
            var efentity = AutoMapper.Mapper.Map <ProductOption>(productOption);

            _productOptionRepository.Add(efentity);
            await UoW.CommitAsync();

            return(AutoMapper.Mapper.Map <ProductOptionDto>(efentity));
        }
예제 #2
0
        public async Task <ProductOptionDto> UpdateAsync(ProductOptionDto productOption)
        {
            var entityToUpdate = AutoMapper.Mapper.Map <ProductOption>(productOption);

            //Check if the entity exists
            if (!await _productOptionRepository.ExistsAsync(x => x.Id == productOption.Id))
            {
                throw new EntityNotFoundException($"The ProductOption with Id:{productOption.Id} could not be found in order to update it");
            }
            _productOptionRepository.Update(entityToUpdate);
            await UoW.CommitAsync();

            return(AutoMapper.Mapper.Map <ProductOptionDto>(entityToUpdate));
        }