public void UpdateVegetablesUnitCost(IDbConnection connection, DecreaseVegetablesUnitCost decreaseVegetablesUnitCost, IDbTransaction transaction = null) { IEnumerable <Product> products = this.productRepository.SelectAllVegetables(connection); foreach (Product product in products) { product.UnitCost.Value = decreaseVegetablesUnitCost.Percent.Content * product.UnitCost.Value; this.productRepository.Update(connection, product, transaction); } }
public void DecreaseUnitcostVegetables(DecreaseVegetablesUnitCostDto decreaseVegetablesUnitCostDto) { using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { DecreaseVegetablesUnitCost decreaseVegetablesUnitCost = this.dtoToEntityMapper.Map <DecreaseVegetablesUnitCostDto, DecreaseVegetablesUnitCost>(decreaseVegetablesUnitCostDto); this.productService.UpdateVegetablesUnitCost(connection, decreaseVegetablesUnitCost, transaction); } catch (Exception ex) { transaction.Rollback(); Console.Write(ex.Message); } } } }