示例#1
0
        /// <summary>
        /// Returns all the cars in the database.
        /// </summary>
        /// <returns>All cars that are in the database.</returns>
        public static Car[] GetAllCars()
        {
            List <Car> cars = CarPersistence.GetAllCars();

            if (cars != null)
            {
                return(CarPersistence.GetAllCars().ToArray());
            }
            else
            {
                return(new Car[0]);
            }
        }
示例#2
0
        /// <summary>
        /// Calculates the statistics and puts them into the array.
        /// </summary>
        /// <returns>An integer of length 5 which contains the count of count of the number of users (total, active, and inactive), records,
        ///and comments, in this order.
        ///</returns>
        public static int[] GetStatistics()
        {
            int[] stats = new int[5];
            for (int i = 0; i < 5; i++)
            {
                stats[i] = 0;
            }
            User[]     users = UserPersistence.GetAllUsers();
            List <Car> cars  = CarPersistence.GetAllCars();

            for (int i = 0; i < users.Length; i++) // Counts for the users that are active, inactive and total.
            {
                if (users[i].status == "A")
                {
                    stats[1]++;
                }
                else
                {
                    stats[2]++;
                }
                stats[0]++;
            }

            for (int i = 0; i < cars.Count; i++) // Counts the cars in the database.
            {
                stats[3]++;
            }

            List <Comment> comments = CommentPersistence.GetAllComments();

            for (int i = 0; i < comments.Count; i++) // Counts the comments in the system.
            {
                stats[4]++;
            }
            return(stats);
        }