/// <summary>
        /// Christian Lopez
        /// Created:
        /// 2017/03/08
        ///
        /// Creates an agreement for the supplier for the given product
        /// </summary>
        ///
        /// <remarks>
        /// Aaron Usher
        /// Updated:
        /// 2017/04/06
        ///
        /// Modified method to be less redundant and to change default approverId from 0 to null.
        /// approverId was changed to be nullable as well.
        /// </remarks>
        /// <param name="supplier"></param>
        /// <param name="product"></param>
        /// <returns></returns>
        public bool CreateAgreementsForSupplier(Supplier supplier, Product product, int?approverId = null, bool isApproved = true)
        {
            bool success   = false;
            var  agreement = new Agreement()
            {
                ProductId     = product.ProductId,
                SupplierId    = supplier.SupplierID,
                DateSubmitted = DateTime.Now,
                IsApproved    = isApproved,
                ApprovedBy    = approverId
            };

            if (approverId == null)
            {
                agreement.IsApproved = false;
            }
            try
            {
                if (1 == AgreementAccessor.CreateAgreement(agreement))
                {
                    success = true;
                }
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("There was a database error.", ex);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("There was an unknown error.", ex);
            }
            return(success);
        }
Пример #2
0
        /// <summary>
        /// Skyler Hiscock
        /// Created:
        /// 2017/05/11
        ///
        /// Returns a list a supplier's agreements with product name included
        /// </summary>
        ///
        /// <returns></returns>
        public List <AgreementWithProductName> RetrieveAgreementsBySupplierID(int supplierID)
        {
            var suppliersWithAgreements = new List <AgreementWithProductName>();

            try
            {
                suppliersWithAgreements = AgreementAccessor.RetrieveAgreementsWithProductNameBySupplierId(supplierID).GroupBy(s => s.ProductName).Select(s => s.First()).ToList();
            }
            catch
            {
            }
            return(suppliersWithAgreements);
        }
        /// <summary>
        /// Christian Lopez
        /// Created
        /// 2017/03/08
        ///
        /// Retrieves a list of Agreements for a given supplier Id
        /// </summary>
        /// <param name="supplierId"></param>
        /// <returns></returns>
        public List <Agreement> RetrieveAgreementsBySupplierId(int supplierId)
        {
            List <Agreement> agreements = new List <Agreement>();

            try
            {
                agreements = AgreementAccessor.retrieveAgreementsBySupplierId(supplierId);
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("There was a database error.", ex);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("There was an unknown error.", ex);
            }

            return(agreements);
        }
        /// <summary>
        /// Christian Lopez
        ///
        /// Created:
        /// 2017/03/09
        ///
        /// Deactivates a specified agreement.
        /// </summary>
        /// <param name="agreement"></param>
        /// <param name="approverId"></param>
        /// <returns></returns>
        public bool UpdateAgreement(Agreement oldAgreement, Agreement newAgreement)
        {
            bool success = false;

            try
            {
                if (1 == AgreementAccessor.UpdateAgreement(oldAgreement, newAgreement))
                {
                    success = true;
                }
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("There was a database error.", ex);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("There was an unknown error.", ex);
            }
            return(success);
        }