Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new notebook in the databse
 /// </summary>
 /// <param name="product">the product id</param>
 /// <param name="graphic">the notebook id</param>
 /// <param name="cpu">the cpu id</param>
 /// <param name="hardDrive">the graphic id</param>
 /// <param name="ramMemoryInGB">the ram</param>
 /// <param name="avgBatteryTimeInMinutes">the battery time</param>
 /// <param name="os">the os</param>
 public Notebook(Product product, Graphic graphic, CPU cpu, HardDrive hardDrive, int ramMemoryInGB, int avgBatteryTimeInMinutes, OS os)
     : base(product.Name, product.Price)
 {
     Graphic   = graphic;
     Cpu       = cpu;
     HardDrive = hardDrive;
     RamInGB   = ramMemoryInGB;
     AverageBatteryTimeInMinutes = avgBatteryTimeInMinutes;
     Os = os;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Delets a HardDrive from The Database
        /// </summary>
        /// <param name="hardDrive">The id from the product which sould be removed</param>
        public void DeleteHardDrive(HardDrive hardDrive)
        {
            int hardDriveId = GetHardDriveId(hardDrive);

            if (CheckIfHardDriveIsUsedInTWONotebook(hardDriveId))
            {
                throw new InvalidOperationException("The HardDrive is used in two or more notebooks and could not be deleted");
            }
            using (var delete = _db.CreateNonQueryCommand(CommandDeleteHardDrive))
            {
                delete.AddParameter("$id", hardDriveId);
                delete.Execute();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a new hard drive to the database.
 /// </summary>
 public void AddNewHardDriveToDatabase(HardDrive hardDrive)
 {
     if (DoesHardDriveAlreadyExist(hardDrive.Type, hardDrive.MemoryInGB))
     {
         throw new ProductAlreadyExistsException("the HardDrive already exists in the Database");
     }
     using (var createHardDrive = _db.CreateNonQueryCommand(CommandAddHardDrive))
     {
         createHardDrive.AddParameter("$id", null);
         createHardDrive.AddParameter("$type", hardDrive.Type);
         createHardDrive.AddParameter("$memory", hardDrive.MemoryInGB);
         createHardDrive.Execute();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the ID from the HardDrive
        /// </summary>
        public int GetHardDriveId(HardDrive hardDrive)
        {
            using (var getID = _db.CreateQueryCommand(CommandSelectIHardDriveID))
            {
                getID.AddParameter("$memory", hardDrive.MemoryInGB);
                getID.AddParameter("$type", hardDrive.Type);
                IReader reader = getID.ExecuteReader();

                while (reader.TryReadNextRow(out var row))
                {
                    return(int.Parse(row[0].ToString()));
                }
                throw new ProductNotFoundException("The Given hard drive could not be found");
            }
        }