예제 #1
0
        /// <summary>
        /// Method AddCar
        /// Adds a new car to the catalog or if it exists in
        /// the catalog complements the information.
        /// </summary>
        /// <param name="CallingClass">The object needed to check the correct call.</param>
        public void AddCar(object CallingClass, string brand, string model, int numberOfCars, double price)
        {
            if (!(CallingClass is ICatalogCommand))
            {
                throw new Exception("Attempting to access the catalog of cars without using the CatalogCommand.");
            }

            // Capacity check (if Capacity = -1, this means that capacity is unlimited).
            if ((Capacity < Counter + 1) && (Capacity != -1))
            {
                throw new Exception("Catalog overflow.");
            }

            var existingCar = CatalogOfCar.Any(x => (x.Brand == brand) && (x.Model == model));

            if (!existingCar)
            {
                var AddedCar = new Car(this, brand, model, numberOfCars, price);
                CatalogOfCar.Add(AddedCar);
                Counter++;
                CallEvent(new CatalogEventArgs(numberOfCars, price, brand, model, Counter), Added);
            }
            else
            {
                var numberOfExistingCar = CatalogOfCar.First(x => (x.Brand == brand) && (x.Model == model));
                if (numberOfExistingCar.Price != price)
                {
                    throw new Exception("Incorrect input of an existing car.");
                }
                numberOfExistingCar.AddCars(numberOfCars);
            }
        }
예제 #2
0
 public void Add(User user)
 {
     using (CatalogOfCar catalog = new CatalogOfCar())
     {
         catalog.User.AddAsync(user);
         catalog.SaveChanges();
     }
 }
예제 #3
0
        /// <summary>
        /// Method AveragePrice
        /// Considers the average cost of the car.
        /// </summary>
        /// <param name="CallingClass">The object needed to check the correct call.</param>
        public void AveragePrice(object CallingClass)
        {
            if (!(CallingClass is ICatalogCommand))
            {
                throw new Exception("Attempting to access the catalog of cars without using the CatalogCommand.");
            }

            var price = CatalogOfCar.Select(x => x.Price).Average(y => y);

            CallEvent(new CatalogEventArgs(price), Calculated);
        }
예제 #4
0
        /// <summary>
        /// Method CountCars
        /// Counts the number of cars.
        /// </summary>
        /// <param name="CallingClass">The object needed to check the correct call.</param>
        public void CountCars(object CallingClass)
        {
            if (!(CallingClass is ICatalogCommand))
            {
                throw new Exception("Attempting to access the catalog of cars without using the CatalogCommand.");
            }

            var Count = CatalogOfCar.Select(x => x.NumberOfCars).Sum(y => y);

            CallEvent(new CatalogEventArgs(Count), CountedBrands);
        }
예제 #5
0
        /// <summary>
        /// Method CountBrand
        /// Counts the number of car brands.
        /// </summary>
        /// <param name="CallingClass">The object needed to check the correct call.</param>
        public void CountBrand(object CallingClass)
        {
            if (!(CallingClass is ICatalogCommand))
            {
                throw new Exception("Attempting to access the catalog of cars without using the CatalogCommand.");
            }

            var Count = CatalogOfCar.GroupBy(x => x.Brand).Count();

            CallEvent(new CatalogEventArgs(Count), CountedCars);
        }
예제 #6
0
        public bool IsSet(string email)
        {
            using (CatalogOfCar catalog = new CatalogOfCar())
            {
                try
                {
                    var user = catalog.User
                               .Single(u => u.email == email);

                    return(true);
                }catch (Exception err)
                {
                    return(false);
                }
            }
        }
예제 #7
0
        public User GetUser(LoginForm loginForm)
        {
            using (CatalogOfCar catalog = new CatalogOfCar())
            {
                try
                {
                    var user = catalog.User
                               .Single(u => u.email == loginForm.email && u.password == loginForm.password);

                    return(user);
                }
                catch (Exception err)
                {
                    return(null);
                }
            }
        }
예제 #8
0
        public bool IsSet(LoginForm loginForm)
        {
            using (CatalogOfCar catalog = new CatalogOfCar())
            {
                try
                {
                    var user = catalog.User
                               .Single(u => u.email == loginForm.email && u.password == loginForm.password);

                    return(true);
                }
                catch (Exception err)
                {
                    return(false);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Method AveragePrice
        /// Considers the average cost of a car of a certain brand.
        /// </summary>
        /// <param name="CallingClass">The object needed to check the correct call.</param>
        /// <param name="brand">required brand</param>
        public void AveragePrice(object CallingClass, string brand)
        {
            if (!(CallingClass is ICatalogCommand))
            {
                throw new Exception("Attempting to access the catalog of cars without using the CatalogCommand.");
            }

            var validBrand = CatalogOfCar.Select(x => x.Brand).Contains(brand);

            if (validBrand)
            {
                var price = CatalogOfCar.Where(x => x.Brand == brand).Select(x => x.Price).Average(y => y);
                CallEvent(new CatalogEventArgs(price, brand), Calculated);
            }
            else
            {
                CallEvent(null, Calculated);
            }
        }