public bool DeleteSalles(int id)
 {
     try
     {
         if (db.salles.Find(id) != null)
         {
             salle salle = db.salles.Find(id);
             if (!ValidatorSalle.IsSalleActive(salle) && !ValidatorSalle.IsSalleContainSeance(salle))
             {
                 db.salles.Remove(salle);
                 db.SaveChanges();
                 return(true);
             }
             else if (ValidatorSalle.IsSalleActive(salle))
             {
                 throw new SalleActiveException();
             }
             else
             {
                 throw new SalleHaveSeanceException();
             }
         }
         else
         {
             throw new InvalidItemException("salle");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public bool PostSalle(salle salle)
 {
     try
     {
         if (salle.commentaire == null)
         {
             salle.commentaire = "";
         }
         if (ValidatorSalle.IsValide(salle) &&
             !ValidatorSalle.IsSalleExist(salle, GetAllSalleFromCinema(salle.cinema_id)) &&
             !ValidatorSalle.IsSalleConflict(salle, GetAllSalleFromCinema(salle.cinema_id)))
         {
             db.salles.Add(salle);
             db.SaveChanges();
             return(true);
         }
         else if (ValidatorSalle.IsSalleExist(salle, GetAllSalleFromCinema(salle.cinema_id)))
         {
             throw new ExistingItemException("salle");
         }
         else
         {
             throw new InvalidItemException("salle");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #3
0
        public void IsSalleContainSeance_FalsParam()
        {
            //Arrange
            ManagerSalle manager    = new ManagerSalle(_context);
            salle        ValidSalle = manager.GetSalle(6, null, null);

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleContainSeance(ValidSalle);
                //Assert
                Assert.IsFalse(testResult, "La Salle ne Contien pas de Seance mais la fonction dit que oui");
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }
Exemple #4
0
        public void IsSalleContainSeance_TrueParam()
        {
            //Arrange
            ManagerSalle manager    = new ManagerSalle(_context);
            salle        ValidSalle = manager.GetSalle(1, new DateTime(1900, 01, 01), new DateTime(2500, 01, 01));

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleContainSeance(ValidSalle);
                //Assert
                Assert.IsTrue(testResult, "La Salle Contien des Seance mais la fonction dit que non");
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }
Exemple #5
0
        public void IsSalleActive_FalsParam()
        {
            //Arrange
            ManagerSalle manager       = new ManagerSalle(_context);
            salle        InactiveSalle = manager.GetSalle(6, null, null);

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleActive(InactiveSalle);
                //Assert
                Assert.IsFalse(testResult, "La Salle n'est pas Active mais la fonction dit que OUI");
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }
Exemple #6
0
        public void IsSalleActive_WithNullParam()
        {
            //Arrange
            ManagerSalle manager   = new ManagerSalle(_context);
            salle        NullSalle = null;

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleActive(NullSalle);
                //Assert
                Assert.Fail("A exception should have been throw");
            }
            catch (NullIdExecption NIE)
            {
                Assert.AreEqual("aucune Salle avec cette ID existe", NIE.Message);
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }
 public bool PutSalle(salle salle)
 {
     try
     {
         var salles = GetAllSalleFromCinema(salle.cinema_id);
         var state  = db.Entry(salle).State;
         if (salle.commentaire == null)
         {
             salle.commentaire = "";
         }
         if (ValidatorSalle.IsSalleExist(salle, salles) &&
             ValidatorSalle.IsValide(salle) &&
             !ValidatorSalle.IsSalleContainSeance(salle) &&
             !ValidatorSalle.IsSalleConflict(salle, GetAllSalleFromCinema(salle.cinema_id)))
         {
             db.Set <salle>().AddOrUpdate(salle);
             //db.Entry(salle).State = EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
         else if (ValidatorSalle.IsSalleContainSeance(salle))
         {
             throw new SalleHaveSeanceException();
         }
         else if (!ValidatorSalle.IsSalleExist(salle, GetAllSalleFromCinema(salle.cinema_id)))
         {
             throw new ItemNotExistException("salle");
         }
         else
         {
             throw new InvalidItemException("salle");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }