Exemple #1
0
        public void CreateSeance_ValidSeance_Successful()
        {
            //  Arrange.
            SeanceViewModel svm = new SeanceViewModel()
            {
                Titre      = "Test Séance",
                HeureDebut = new DateTime(2020, 1, 2, 12, 00, 00),
                HeureFin   = new DateTime(2020, 1, 2, 15, 00, 00),
                SalleID    = 1
            };

            //  Act.
            service.CreateSeance(svm);

            //  Assert.
            Assert.AreEqual(4, service.GetSeancesBySalle(1).ToList().Count);
        }
        public async Task <IActionResult> PostSeances([FromBody] SeancesVM seances)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await Task.Run(() => _seanceService.CreateSeance(seances));

            return(Ok(seances));

            //
        }
 public ActionResult PostSeances([FromForm] Seances seances)
 {
     try {
         if (seances.IdCinema == 0)
         {
             throw new Exception("ex");
         }
         else
         {
             _seanceService.CreateSeance(seances);
             return(RedirectToAction("Index", "Moderator"));
         }
     }catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemple #4
0
        public IActionResult CreateSeance([FromBody] SeanceInfo seance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response(ModelState)));
            }

            if (_seanceService.CheckHallExists(seance.HallId))
            {
                return(BadRequest(new Response(ErrorOfHallNonexistence)));
            }

            if (_seanceService.CheckCorrectSeanceTime(seance))
            {
                return(BadRequest(new Response(ErrorOfSeanceTime)));
            }

            if (_seanceService.CheckSeanceExists(seance))
            {
                return(BadRequest(new Response(ErrorOfSeanceExistence)));
            }

            if (_seanceService.СheckForNonmatchingSeanceTime(seance))
            {
                return(BadRequest(new Response(ErrorOfNonmatchingSeanceTime)));
            }

            if (_seanceService.CheckCorrectMovie(seance))
            {
                return(BadRequest(new Response(ErrorOfMovieNonexistence)));
            }

            int id = _seanceService.CreateSeance(seance);

            var response = new CreateResponse(id);

            return(CreatedAtAction(nameof(GetSeance), new { id = response.Id }, response));
        }
        public ActionResult Create(SeanceViewModel seance)
        {
            if (seance.Multiples)
            {
                int      chiffreFreq         = seance.ChiffreFreq;
                DateTime dateDebutHeureDebut = seance.DateDebutHeureDebut;
                DateTime dateDebutHeureFin   = seance.DateDebutHeureFin;
                DateTime dateFin             = seance.DateFin;
                int      nbSeances           = seance.NbSeances;

                if (seance.TypeFreq == "Jour")
                {
                    for (int i = 0; i < nbSeances; i++)
                    {
                        if (i == 0)
                        {
                            seance.HeureDebut = dateDebutHeureDebut;
                            seance.HeureFin   = dateDebutHeureFin;
                        }
                        else
                        {
                            seance.HeureDebut = seance.HeureDebut.AddDays(chiffreFreq);
                            seance.HeureFin   = seance.HeureFin.AddDays(chiffreFreq);
                        }
                        seanceService.CreateSeance(seance);
                    }
                }
                else if (seance.TypeFreq == "Semaine")
                {
                    if (seance.JoursSem != null)
                    {
                        string[] joursSem = new string[seance.JoursSem.Length];
                        int      numJour  = 0;

                        for (int i = 0; i < joursSem.Length; i++)
                        {
                            joursSem[i] = getJourSemaine(int.Parse(seance.JoursSem[i]));
                        }

                        while (dateDebutHeureDebut <= dateFin)
                        {
                            for (int i = 0; i < joursSem.Length; i++)
                            {
                                if (joursSem[i] == dateDebutHeureDebut.DayOfWeek.ToString())
                                {
                                    numJour           = i;
                                    seance.HeureDebut = dateDebutHeureDebut;
                                    seance.HeureFin   = dateDebutHeureFin;

                                    seanceService.CreateSeance(seance);
                                }
                            }

                            if (seance.ChiffreFreq > 1 && numJour == joursSem.Length - 1)
                            {
                                numJour             = 0;
                                dateDebutHeureDebut = dateDebutHeureDebut.AddDays(7 * (chiffreFreq - 1) + 1);
                                dateDebutHeureFin   = dateDebutHeureFin.AddDays(7 * (chiffreFreq - 1) + 1);
                            }
                            else
                            {
                                dateDebutHeureDebut = dateDebutHeureDebut.AddDays(1);
                                dateDebutHeureFin   = dateDebutHeureFin.AddDays(1);
                            }
                        }
                    }
                }
            }
            else
            {
                seanceService.CreateSeance(seance);
            }

            System.Web.HttpContext.Current.Session[SESSION_UV] = true;

            return(Json(new { success = true }));
        }
 public ActionResult CreateSeance(Seance seance)
 {
     _service.CreateSeance(seance);
     return(Ok());
 }