//Insere o produto na tabela Products recupera o ID da inserção para poder utilizar na tabela associativa de suppliers_products public Response Insert(Product product) { using (TransactionScope transaction = new TransactionScope()) { Response resultInsertProduct = base.InsertScalar(product); if (!resultInsertProduct.Success) { return(resultInsertProduct); } foreach (var id in product.SuppliersID) { Supplier_Product suppliers_products = new Supplier_Product { ProductID = resultInsertProduct.GeneratedId, SupplierID = id }; Response resultInsertNs = base.Insert(suppliers_products); if (!resultInsertNs.Success) { return(resultInsertNs); } } transaction.Complete(); return(Response.CreateSuccess("Operação efetuada com sucesso!")); } }
public Response InsertSupplierOfProduct(int productID, List <int> suppliersID) { foreach (var id in suppliersID) { Supplier_Product suppliers_products = new Supplier_Product { ProductID = productID, SupplierID = id }; Response resultInsertNs = base.Insert(suppliers_products); if (!resultInsertNs.Success) { return(resultInsertNs); } } return(Response.CreateSuccess()); }