public async Task <bool> DeleteByIdAsync(Guid id) { var entityToDelete = await _productOptionRepository.GetAsync(x => x.Id == id); if (entityToDelete == null) { return(false); } _productOptionRepository.Delete(entityToDelete); await UoW.CommitAsync(); return(true); }
public async Task <ProductDto> CreateAsync(ProductDto product) { if (product.Id == Guid.Empty) { product.Id = Guid.NewGuid(); } var efProduct = AutoMapper.Mapper.Map <Product>(product); _productRepository.Add(efProduct); await UoW.CommitAsync(); return(AutoMapper.Mapper.Map <ProductDto>(efProduct)); }
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)); }
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)); }
public async Task <ProductDto> UpdateAsync(ProductDto product) { var efProduct = AutoMapper.Mapper.Map <Product>(product); if (!await _productRepository.ExistsAsync(x => x.Id == efProduct.Id)) { throw new EntityNotFoundException($"The Product with Id:{efProduct.Id} could not be found in order to update it"); } _productRepository.Update(efProduct); await UoW.CommitAsync(); // get the new values of the timestamp var t = _productRepository.GetById(efProduct.Id); return(AutoMapper.Mapper.Map <ProductDto>(t)); }