/// <summary> /// <inheritdoc cref="IProductService.NewAsync(InOrder)"/> /// If there is already a Product that has same name and same description, an InvalidEntityException is thrown. /// </summary> /// <param name="product">POCO representing the Product to save</param> /// <returns>POCO representing the output Product</returns> public async Task <Product> NewAsync(InProduct product) { DbProduct newProduct = await unit.ExecuteAsync(async (products, _) => { DbProduct toInsert = mapper.Map <DbProduct>(product); if (await products.IsThereAnyCollisionWith(toInsert)) { throw new InvalidEntityException("A product with same name and description already exists"); } return(await products.NewProduct(toInsert)); }); return(mapper.Map <Product>(newProduct)); }
public async Task <Product> New(InProduct toInsert) { return(await service.NewAsync(toInsert)); }