Esempio n. 1
0
        /// <summary>
        /// add rental in the database, return true if it is added, otherwise
        /// return false.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool AddRental(Rental r)
        {
            List <Rental> r1 = DBController.GetAllRecords <Rental>().Where(rental =>
                                                                           rental.CustomerID == r.CustomerID).ToList();
            bool noneActive = true;

            foreach (Rental item in r1)
            {
                if (item.Active)
                {
                    noneActive = false;
                }
            }
            if (r1 == null || noneActive)
            {
                r.Active = true;
                Vehicle v = DBController.GetAllRecords <Vehicle>().Where(vehicle =>
                                                                         vehicle.VehicleID == r.VehicleID).FirstOrDefault();
                v.IsRented = true;
                DBController.Save(r, DBObject.SaveTypes.Insert);
                VehicleControl.ModifyVehicle(v);
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// The Deny method will remove the issue if the issue is deemed
        /// invalid, and return the cars state to not damaged
        /// </summary>
        /// <param name="vi"></param>
        public static void Deny(VehicleIssue vi)
        {
            Vehicle v1 = VehicleControl.FindVehicle(vi.VehicleID.ToString());

            v1.IsDamaged = false;
            DBController.Delete(vi);
            DBController.Save(v1, DBObject.SaveTypes.Update);
        }
Esempio n. 3
0
        /// <summary>
        /// add purchase and determine the cost of each vehicle
        /// </summary>
        /// <param name="p"></param>
        public static void DeterminePurchaseCost(Purchase p)
        {
            int     vehicleId = p.VehicleID;
            Vehicle v         = DBController.GetAllRecords <Vehicle>().Where(vehicle =>
                                                                             vehicle.VehicleID == vehicleId).FirstOrDefault();
            int totalCost = VehicleControl.DeterminePrice(v);

            p.Cost = totalCost;
        }
        /// <summary>
        /// The Fix method will update the vehicle in questions isDamaged
        /// to represent the car is fixed, and update the issue as being
        /// fixed.
        /// </summary>
        /// <param name="vi"></param>
        public static void Fix(VehicleIssue vi)
        {
            Vehicle v1 = VehicleControl.FindVehicle(vi.VehicleID.ToString());

            v1.IsDamaged = false;
            vi.IsFixed   = true;
            DBController.Save(vi, DBObject.SaveTypes.Update);
            DBController.Save(v1, DBObject.SaveTypes.Update);
        }
Esempio n. 5
0
        /// <summary>
        /// add purchase in the database.
        /// </summary>
        /// <param name="p"></param>
        public static void AddPurchase(Purchase p)
        {
            Vehicle v = DBController.GetAllRecords <Vehicle>().Where(vehicle =>
                                                                     vehicle.VehicleID == p.VehicleID).FirstOrDefault();

            v.IsRented = true;
            DeterminePurchaseCost(p);
            DBController.Save(p, DBObject.SaveTypes.Insert);
            VehicleControl.ModifyVehicle(v);
        }
 /// <summary>
 /// The method will use the VehicleIssue Object, and insert the
 /// VehicleIssue into the table, as well as update the vehicle
 /// attribute, isDamaged to signify the car is in need of repair
 /// </summary>
 /// <param name="vI"></param>
 /// <returns></returns>
 public static bool AddIssue(VehicleIssue vI)
 {
     try
     {
         Vehicle v1 = VehicleControl.FindVehicle(vI.VehicleID.ToString());
         v1.IsDamaged = true;
         DBController.Save(vI, DBObject.SaveTypes.Insert);
         DBController.Save(v1, DBObject.SaveTypes.Update);
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }