Esempio n. 1
0
        /// <summary>
        /// As soon as the customer hits the buy product button
        /// and pays the item or chooses to pay later the
        /// invoice is created.
        /// Returns the InvoiceID
        /// </summary>
        /// <param name="email"></param>
        /// <param name="shippingID"></param>
        /// <param name="products"></param>
        /// <returns>Int InvoiceID</returns>
        public int CreateInvoice(string email, int shippingID, List <ProductSelectionDTO> products, decimal shippingCost, decimal totalAmount, decimal taxValue, decimal finalCost)
        {
            AccountDTO   customer      = new AccountDTO();
            ShippmentDTO deliverer     = new ShippmentDTO();
            int          result        = 0;
            int          paymentStatus = 0;

            try
            {
                customer = AB.FindBy(email);
                if (customer != null)
                {
                    deliverer = SB.FindBy(shippingID);
                    if (deliverer != null)
                    {
                        //set current time when Invoice is created
                        DateTime orderDate   = DateTime.Now;
                        DateTime paymentDate = DateTime.Now;
                        DateTime arrivalDate = DateTime.Now.AddDays(deliverer.GetDeliveryTime());
                        DateTime postageDate = DateTime.Now;

                        int totalQuantity = CalculateQuantity(products);

                        //calculate all other values for the invoice

                        /*int totalWeight = CalculateWeight(products);
                         * decimal totalShippingCost = deliverer.GetCost() + (decimal)0.1 * totalWeight;
                         * decimal totalShippingCost = ;
                         * decimal totalProductCost = CalculateProductCost(products);
                         * decimal totalTaxes = CalculateTax(totalProductCost);
                         * decimal totalAmount = totalTaxes + totalProductCost + totalShippingCost;*/

                        //UpdateProductInfo(products);

                        //insert into DB
                        result = DB.Insert(customer.GetID(), deliverer.GetID(), totalQuantity, shippingCost, finalCost, taxValue,
                                           totalAmount, orderDate.ToString(), paymentDate.ToString(), arrivalDate.ToString(), postageDate.ToString(), paymentStatus, email);
                    }
                    else
                    {
                        throw new EmptyRowException($"The entry for {shippingID} was not found.");
                    }
                }
                else
                {
                    throw new EmptyRowException($"The entry for {email} was not found.");
                }
            }
            catch (Exception e)
            {
                e.GetBaseException();
                Debug.Write(e.ToString());
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Find a specific invoice of a customer.
        /// Returns List of Invoice but contains 1 element
        /// </summary>
        /// <param name="customerID"></param>
        /// <param name="invoiceID"></param>
        /// <returns>List of Invoice but contains 1 element</returns>
        public List <InvoiceDTO> FindInvoiceByID(int customerID, int invoiceID)
        {
            AccountDTO customer = new AccountDTO();

            customer = AB.FindBy(customerID);
            List <InvoiceDTO> result = new List <InvoiceDTO>();

            if (customer != null)
            {
                result = DB.FindByCustomer(customer.GetID(), invoiceID);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Find all invoices of one Customer.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable <InvoiceDTO> FindInvoices(int id)
        {
            AccountDTO customer = new AccountDTO();

            customer = AB.FindBy(id);
            IEnumerable <InvoiceDTO> result = new List <InvoiceDTO>();

            if (customer != null)
            {
                result = DB.FindByCustomer(customer.GetID());
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Find all unpaied invoices per Customer that are
        /// paymentStatus = 0 (unpaied) OR
        /// paymentStatus = 1 (paied)
        /// </summary>
        /// <param name="email"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public IEnumerable <InvoiceDTO> FindUnPaied(string email)
        {
            AccountDTO customer = new AccountDTO();

            customer = AB.FindBy(email);
            int status = 0;
            IEnumerable <InvoiceDTO> result = new List <InvoiceDTO>();

            if (customer != null)
            {
                result = DB.FindByStatus(customer.GetID(), status);
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Create a new payment and update
        /// the payment status of an invoice.
        /// If successfull return = 1
        /// </summary>
        /// <param name="totalAmount"></param>
        /// <param name="email"></param>
        /// <param name="invoiceID"></param>
        /// <returns></returns>
        public int Create(decimal totalAmount, string email, int invoiceID)
        {
            DateTime   paymentDate   = DateTime.Now;
            AccountDTO customer      = new AccountDTO();
            int        result        = 0;
            int        paymentStatus = 1;

            customer = AB.FindBy(email);
            result   = DB.Insert(totalAmount, paymentDate, customer.GetID(), invoiceID);
            if (result > 0)
            {
                IB.Update(invoiceID, paymentStatus);
            }
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Find single customer in DB
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AccountDTO GetCustomer(int id)
        {
            AccountDTO customer = new AccountDTO();

            try
            {
                customer = DB.FindBy(id);
                Debug.Print("AccountBL / Customer ID: " + customer.GetID());
            }
            catch (Exception e)
            {
                e.GetBaseException();
                Debug.Write(e.ToString());
            }
            return(customer);
        }
Esempio n. 7
0
        /// <summary>
        /// Update all values in user profile.
        /// </summary>
        /// <param name="mail"></param>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="birthDate"></param>
        /// <param name="phoneNo"></param>
        /// <param name="imgPath"></param>
        /// <returns></returns>
        public int Update(string mail, string firstName, string lastName,
                          string birthDate, string phoneNo, string imgPath)
        {
            int        flag;
            AccountDTO customer = new AccountDTO();

            if (IsValidEmail(mail))
            {
                customer = DB.FindBy(mail);
                Debug.Print("AccountBL / Update value returned " + customer.ToString());
            }
            else
            {   //email is not correct => 2
                return(flag = 2);
            }
            //if update was successfull => 1
            flag = DB.Update(customer.GetID(), mail, firstName, lastName, birthDate, phoneNo, imgPath);

            Debug.Print("AccountBL / Update correction: " + flag);
            return(flag);
        }