Exemplo n.º 1
0
        /// <summary>
        /// Robert Forbes
        /// 2017/02/02
        ///
        /// Gets a list of all packages with the provided orderID
        /// </summary>
        /// <param name="orderID">The order ID that the packages should be associated with</param>
        /// <returns>A list of packages</returns>
        public List <Package> RetrievePackagesInOrder(int orderID)
        {
            List <Package> packages = new List <Package>();

            try
            {
                packages = PackageAccessor.RetrieveAllPackagesByOrder(orderID);

                foreach (Package p in packages)
                {
                    try{
                        p.PackageLineList = PackageLineAccessor.RetrievePackageLinesInPackage(p.PackageId);
                    }
                    catch
                    {
                        // If we cant get the package lines from the db set it to an empty list
                        p.PackageLineList = new List <PackageLine>();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(packages);
        }
        /// <summary>
        /// Robert Forbes
        /// 2017/02/07
        ///
        /// Attempts to run the data access method CreatePackageLine(PackageLine proposed) to create a new package line
        /// </summary>
        /// <param name="line">The line to be added to the database</param>
        /// <returns>bool representing if the package line was successfully added</returns>
        public bool CreatePackageLine(PackageLine line)
        {
            bool result = false;

            try
            {
                ProductLot lot = ProductLotAccessor.RetrieveProductLot(line.ProductLotId);

                int?newAvailableQuantity = lot.AvailableQuantity - line.Quantity;

                //Trying to take the quantity in the package line out of the product lot table to update stock levels
                if (ProductLotAccessor.UpdateProductLotAvailableQuantity(line.ProductLotId, lot.AvailableQuantity, newAvailableQuantity) > 0)
                {
                    //if the product lot quantity could be updated then create the package line
                    if (PackageLineAccessor.CreatePackageLine(line) > 0)
                    {
                        result = true;
                    }
                    else //Trying to add the quantity back to the product lot since the package line couldn't be created
                    {
                        ProductLotAccessor.UpdateProductLotAvailableQuantity(line.ProductLotId, newAvailableQuantity, lot.AvailableQuantity);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Robert Forbes
        /// 2017/04/13
        ///
        /// Retrieves all routes with assigned dates for today or after
        /// </summary>
        /// <param name="driverId"></param>
        /// <returns></returns>
        public List <Route> RetrieveFutureRoutesForDriver(int?driverId)
        {
            List <Route> routes = new List <Route>();

            try
            {
                List <Route> routesToRemove = new List <Route>();
                //Getting all the routes
                routes = RouteAccessor.RetrieveFutureRoutesForDriver(driverId);
                foreach (Route r in routes)
                {
                    //Getting all the deliveries for each route
                    List <Delivery> deliveriesToRemove = new List <Delivery>();
                    r.Deliveries = DeliveryAccessor.RetrieveDeliveriesForRoute(r.RouteId);
                    foreach (Delivery d in r.Deliveries)
                    {
                        if (d.StatusId == "Delivered")
                        {
                            deliveriesToRemove.Add(d);
                        }
                        //Getting the address for each delivery
                        d.Address = DeliveryAccessor.RetrieveUserAddressForDelivery(d.DeliveryId);
                        //Getting the packages for each delivery
                        d.PackageList = PackageAccessor.RetrieveAllPackagesInDelivery(d.DeliveryId);
                        foreach (Package p in d.PackageList)
                        {
                            //Getting all the lines for each package
                            p.PackageLineList = PackageLineAccessor.RetrievePackageLinesInPackage(p.PackageId);
                            foreach (PackageLine line in p.PackageLineList)
                            {
                                //Getting the name of each product for each package line
                                line.ProductName = ProductAccessor.RetrieveProductNameFromProductLotId(line.ProductLotId);
                            }
                        }
                    }
                    foreach (Delivery d in deliveriesToRemove)
                    {
                        r.Deliveries.Remove(d);
                    }
                    if (r.Deliveries.Count == 0)
                    {
                        routesToRemove.Add(r);
                    }
                }

                foreach (Route r in routesToRemove)
                {
                    routes.Remove(r);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(routes);
        }
        /// <summary>
        /// Robert Forbes
        /// 2017/02/07
        ///
        /// Attempts to run the data access method RetrievePackageLinesInPackage(int packageID) to get all package lines for a package
        /// </summary>
        /// <param name="packageID">The packageD that the package lines should relate to</param>
        /// <returns>A list of package lines</returns>
        public List <PackageLine> RetrievePackageLinesInPackage(int packageID)
        {
            List <PackageLine> lines = new List <PackageLine>();

            try
            {
                lines = PackageLineAccessor.RetrievePackageLinesInPackage(packageID);
            }
            catch (Exception)
            {
                throw;
            }

            return(lines);
        }