Exemple #1
0
        /// <summary>
        ///     Add a new supplier and return if successful
        /// </summary>
        /// <param name="supplier"></param>
        public void AddNewSupplier(Supplier supplier)
        {
            using (var scope = new TransactionScope())
            {
                using (var connection = Connector.GetConnection())
                {
                    var supplierDal = new SupplierDal(connection);
                    supplierDal.Insert(supplier.Name, supplier.Contact);
                    supplier.Id = supplierDal.GetLastInsertId();

                    // Exception handling
                    if (supplier.Id == null)
                    {
                        throw new ArgumentNullException(nameof(supplier.Id), "Supplier Id null after insert");
                    }
                }
                scope.Complete();
            }
        }