public bool PostSeance(seance seance)
 {
     try
     {
         List <seance> ConflictingSeances = ValidatorSeance.IsSeanceConflict(seance, this.GetAllSeanceFromSalle(seance.salle_id, null));
         if (ValidatorSeance.IsValide(seance) && ConflictingSeances.Count == 0 && !ValidatorSeance.IsSeanceExiste(seance, this.GetAllSeanceFromSalle(seance.salle_id, null)))
         {
             db.seances.Add(seance);
             db.SaveChanges();
             return(true);
         }
         else if (ConflictingSeances.Count != 0)
         {
             throw new ConflictiongSeanceException(ConflictingSeances);
         }
         else if (ValidatorSeance.IsSeanceExiste(seance, this.GetAllSeanceFromSalle(seance.salle_id, null)))
         {
             throw new ExistingItemException("seance");
         }
         else
         {
             throw new InvalidItemException("seance");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public bool PutSeance(seance seance)
 {
     try
     {
         int           cinemaId           = new ManagerSalle().GetSalle(seance.salle_id, null, null).cinema_id;
         List <seance> ConflictingSeances = ValidatorSeance.IsSeanceConflict(seance, this.GetAllSeanceFromSalle(seance.salle_id, null));
         if (ValidatorSeance.IsSeanceExiste(seance, this.GetAllSeanceFromCinema(cinemaId)) && ValidatorSeance.IsValide(seance) && ConflictingSeances.Count == 0)
         {
             db.Set <seance>().AddOrUpdate(seance);
             db.SaveChanges();
             return(true);
         }
         else if (ConflictingSeances.Count != 0)
         {
             throw new ConflictiongSeanceException(ConflictingSeances);
         }
         else if (!ValidatorSeance.IsSeanceExiste(seance, this.GetAllSeanceFromCinema(cinemaId)))
         {
             throw new ItemNotExistException("seance");
         }
         else
         {
             throw new InvalidItemException("seance");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #3
0
        public bool PostProgrammation(programmation programmation)
        {
            try
            {
                var seance = new ManagerSeance().GetSeance(programmation.id_seance);
                if (ValidatorSeance.IsSeanceLongEnought(seance, new ManagerProgrammation().GetAllprogramtionFromSeance(programmation.id_seance), new ManagerFilm().GetFilm(programmation.id_film).duree))
                {
                    ManagerSeance        manager        = new ManagerSeance();
                    List <programmation> programmations = manager.GetSeance(programmation.id_seance).programmations.ToList();
                    film f = new ManagerFilm().GetFilm(programmation.id_film);

                    if (programmations.Count() == 0 && (f.type_film.typage.ToUpper() == "STANDART" || f.type_film.typage.ToUpper() == "COURT METRAGE"))
                    {
                        programmation.is_primary = true;
                    }

                    else if (programmations.Where(p => p.is_primary).ToList().Count() != 1 &&
                             (f.type_film.typage.ToUpper() == "STANDART" || f.type_film.typage.ToUpper() == "COURT METRAGE"))
                    {
                        programmation.is_primary = true;
                    }
                    db.programmations.Add(programmation);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    throw new SeanceToShortException();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #4
0
        public void NonConflictingSeance()
        {
            //Arrange
            ManagerSeance manager = new ManagerSeance(_context);
            seance        s       = new seance()
            {
                id = 999, salle_id = 1, titre_seance = "non conflicting seance", date_debut = new DateTime(2021, 1, 1, 8, 0, 0), date_fin = new DateTime(2021, 1, 1, 10, 0, 0)
            };
            DateTime dateToLoad = new DateTime(2021, 1, 1);

            //Act
            var testResult3 = ValidatorSeance.IsSeanceConflict(s, manager.GetAllSeanceFromSalle(s.salle_id, dateToLoad)).Count != 0;

            //Assert
            Assert.IsFalse(testResult3, "a seance with the same start time was accepted ");
        }
Exemple #5
0
        public void ConflictingSeance_seanceEndToLate()
        {
            //Arrange
            ManagerSeance manager = new ManagerSeance(_context);
            seance        s2      = new seance()
            {
                id = 999, salle_id = 1, titre_seance = "conflicting seance", date_debut = new DateTime(2021, 1, 1, 9, 0, 0), date_fin = new DateTime(2021, 1, 1, 11, 0, 0)
            };
            DateTime dateToLoad = new DateTime(2021, 1, 1);

            //Act
            var testResult2 = ValidatorSeance.IsSeanceConflict(s2, manager.GetAllSeanceFromSalle(s2.salle_id, dateToLoad)).Count != 0;

            //Assert
            Assert.IsTrue(testResult2, "a seance endind after an other started was accepted");
        }
Exemple #6
0
        public void ConflictingSeance_seanceStartToEarly()
        {
            //Arrange
            ManagerSeance manager = new ManagerSeance(_context);
            seance        s1      = new seance()
            {
                id = 999, salle_id = 1, titre_seance = "conflicting seance", date_debut = new DateTime(2021, 1, 1, 11, 0, 0), date_fin = new DateTime(2021, 1, 1, 12, 0, 0)
            };
            DateTime dateToLoad = new DateTime(2021, 1, 1);

            //Act
            var testResult1 = ValidatorSeance.IsSeanceConflict(s1, manager.GetAllSeanceFromSalle(s1.salle_id, dateToLoad)).Count != 0;

            //Assert
            Assert.IsTrue(testResult1, "a seance starting before an other ended was accepted");
        }
        private Dictionary <seance, List <seance> > PostManySeance(List <seance> seances, List <programmation> progs, ref List <int> ids)
        {
            //cinema_dbEntities localdb = new cinema_dbEntities();
            Dictionary <seance, List <seance> > conflict = new Dictionary <seance, List <seance> >();

            using (cinema_dbEntities localdb = new cinema_dbEntities())
            {
                foreach (var item in seances)
                {
                    try
                    {
                        List <seance> ConflictingSeances = ValidatorSeance.IsSeanceConflict(item, this.GetAllSeanceFromSalle(item.salle_id, null));
                        if (ValidatorSeance.IsValide(item) && ConflictingSeances.Count == 0 && !ValidatorSeance.IsSeanceExiste(item, this.GetAllSeanceFromSalle(item.salle_id, null)))
                        {
                            localdb.seances.Add(item);
                        }
                        else if (ConflictingSeances.Count != 0)
                        {
                            throw new ConflictiongSeanceException(ConflictingSeances);
                        }
                        else if (ValidatorSeance.IsSeanceExiste(item, this.GetAllSeanceFromSalle(item.salle_id, null)))
                        {
                            throw new ExistingItemException("seance");
                        }
                        else
                        {
                            throw new InvalidItemException("seance");
                        }
                    }
                    catch (ConflictiongSeanceException e)
                    {
                        conflict[item] = (List <seance>)e.Data[0];
                    }
                }
                localdb.SaveChanges();
            }

            foreach (var item in seances)
            {
                ids.Add(db.seances.Where(s => s.date_debut == item.date_debut && s.date_fin == item.date_fin && s.salle_id == item.salle_id).ToList()[0].id);
            }
            return(conflict);
        }