Beispiel #1
0
        // GET: ReservationsController
        public async Task <IActionResult> Index(Reservations res)
        {
            if (ModelState.IsValid)
            {
                _context.Add(res);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
        public async Task <IActionResult> Create([FromForm] MovieViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);
                Movies movie          = new Movies
                {
                    Name        = model.Name,
                    ReleaseDate = model.ReleaseDate,
                    Description = model.Description,
                    Duration    = model.Duration,
                    Rating      = model.Rating,
                    Type        = model.Type,
                    Genre       = model.Genre,
                    Actors      = model.Actors,
                    Directors   = model.Directors,
                    Trailer     = model.Trailer,
                    Image       = uniqueFileName,
                };
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Beispiel #3
0
        public async Task <AppUser> SaveUser(AppUser user)
        {
            db.Add(user);
            await db.SaveChangesAsync();

            return(user);
        }
Beispiel #4
0
        public Movie CreateMovie(Movie movie)
        {
            try
            {
                movie.Added = DateTime.Now;
                _context.Add(movie);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(null);
            }
            catch (DbUpdateException)
            {
                return(null);
            }

            return(movie);
        }
Beispiel #5
0
 protected new void SetUp(CinemaDbContext cinemaDbContext)
 {
     base.SetUp(cinemaDbContext);
     EncrypterMock.Setup(m => m.Compute(User.Password, It.IsAny <string>()))
     .Returns((string pass, string salt) => pass);
     EncrypterMock.Setup(m => m.Compare(User.Password, User.Password)).Returns(true);
     cinemaDbContext.Add(User);
     cinemaDbContext.SaveChanges();
     UserService = new Cinema.Services.UserService(cinemaDbContext, EncrypterMock.Object, TokenProviderMock.Object, Mapper, MemoryCache, EmailSenderMock.Object);
 }
        public async Task <IActionResult> Create([Bind("ClienteId,Nome,Email,DataNascimento,Senha,SenhaCofirmada,Estudante,Ativa")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
        public async Task <IActionResult> Create([Bind("GeneroId,Descricao")] Genero genero)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genero);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genero));
        }
        public async Task <IActionResult> Create([Bind("CinemaId,Nome,Estado,Cidade,Bairro,Rua,Numero,Ativa")] Cinema cinema)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cinema);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cinema));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,PosterUrl,Duration,Language,Technique,Description,ViewIndication,Genre,Year,Cast,Director,Country")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task <IActionResult> Create([Bind("SalaId,Nome,QuantidadeAssentos,Ativa,CinemaId")] Sala sala)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sala);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CinemaId"] = new SelectList(_context.Cinemas, "CinemaId", "Nome", sala.CinemaId);
            return(View(sala));
        }
        public async Task <IActionResult> Create([Bind("Id,SlotStart,SlotEnd,RoomId")] TimeSlot timeSlot)
        {
            if (ModelState.IsValid)
            {
                _context.Add(timeSlot);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomId"] = new SelectList(_context.Rooms, "Id", "Id", timeSlot.RoomId);
            return(View(timeSlot));
        }
Beispiel #12
0
 public Film Add(Film film)
 {
     try
     {
         _cinemaDbContext.Add(film);
         _cinemaDbContext.SaveChanges();
         return(film);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
        public bool Add(Employee employee)
        {
            try
            {
                _cinemaDbContext.Add(employee);
                _cinemaDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
        public async Task <IActionResult> Create([Bind("Id,TimeSlotId,MovieId")] PlayList playList)

        {
            if (ModelState.IsValid)
            {
                _context.Add(playList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieId"]    = new SelectList(_context.Movies, "Id", "Id", playList.MovieId);
            ViewData["TimeSlotId"] = new SelectList(_context.TimeSlots, "Id", "Id", playList.TimeSlotId);
            return(View(playList));
        }
Beispiel #15
0
        public bool Add(Director Director)
        {
            try
            {
                _cinemaDbContext.Add(Director);
                _cinemaDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
        public Actor Add(Actor actor)
        {
            try
            {
                _cinemaDbContext.Add(actor);
                _cinemaDbContext.SaveChanges();
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(actor);
        }
        public bool Add(Snack snack)
        {
            try
            {
                _cinemaDbContext.Add(snack);
                _cinemaDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
        public async Task <IActionResult> Create([Bind("SessaoId,Horario,Preco,Ativa,FilmeId,SalaId,CinemaId")] Sessao sessao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sessao);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CinemaId"] = new SelectList(_context.Cinemas, "CinemaId", "Nome", sessao.CinemaId);
            ViewData["FilmeId"]  = new SelectList(_context.Filmes, "FilmeId", "Titulo", sessao.FilmeId);
            //ViewData["SalaId"] = new SelectList(_context.Salas, "SalaId", "Nome", sessao.SalaId);
            return(View(sessao));
        }
Beispiel #19
0
        private void AddSeances(int minNumberOfSeancesPerDay, int maxNumberOfSeancesPerDay)
        {
            var randomGenerator = new Random();

            foreach (DateTime day in EachDay(DateTime.Now, DateTime.Now.AddYears(1)))
            {
                int numOfSeancesPerDay = randomGenerator.Next(minNumberOfSeancesPerDay, maxNumberOfSeancesPerDay);
                for (int i = 0; i < numOfSeancesPerDay; ++i)
                {
                    var    movie                    = _movies.RandomElement();
                    var    room                     = _rooms.ElementAt(i);
                    double normalTicketPrice        = randomGenerator.Next(15, 30);
                    double concessionaryTicketPrice = normalTicketPrice - 7;
                    var    dateTime                 = day.AddHours(7).AddHours(randomGenerator.Next(0, 12));
                    var    seance                   = new Seance(movie.Id, room.Id, dateTime, movie.Duration.Add(TimeSpan.FromMinutes(15)), concessionaryTicketPrice, normalTicketPrice);
                    _dbContext.Add(seance);
                }
            }
            _dbContext.SaveChanges();
        }
Beispiel #20
0
 public void AddReservedSeat(int seatId, CinemaDbContext context = null)
 {
     if (_reservedSeats != null)
     {
         _reservedSeats.Add(new ReservedSeat(seatId));
     }
     else if (context == null)
     {
         throw new ArgumentNullException(nameof(context),
                                         "You must provide a context if the ReservedSeats collection isn't valid.");
     }
     else if (context.Entry(this).IsKeySet)
     {
         context.Add(new ReservedSeat(seatId, Id));
     }
     else
     {
         throw new InvalidOperationException("Could not add a reservedSeat.");
     }
 }
Beispiel #21
0
        public IActionResult Register([FromBody] User user)
        {
            var userWithSameEmail = _dbContext.Users.Where(u => u.Email == user.Email).SingleOrDefault();

            if (userWithSameEmail != null)
            {
                return(BadRequest("User with same e-mail already exists"));
            }

            var newUser = new User
            {
                Name     = user.Name,
                Email    = user.Email,
                Password = SecurePasswordHasherHelper.Hash(user.Password),
                Role     = "Users"
            };

            _dbContext.Add(newUser);
            _dbContext.SaveChanges();

            return(StatusCode(StatusCodes.Status201Created));
        }
Beispiel #22
0
        public async Task <IActionResult> Create([Bind("FilmeId,Titulo,Classificacao,GeneroId,Ativa")] Filme filme, IFormFile Imagem)
        {
            if (Imagem != null && Imagem.Length > 0)
            {
                using (var stream = new MemoryStream())
                {
                    await Imagem.CopyToAsync(stream);

                    Bitmap img = new Bitmap(stream);
                    var    v   = img.Size;
                    filme.Imagem = stream.ToArray();
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(filme);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GeneroId"] = new SelectList(_context.Generos, "GeneroId", "Descricao", filme.GeneroId);
            return(View(filme));
        }
 public void Add(Reservation reservation)
 {
     reservation.ReservationTime = DateTime.Now;
     _dbContext.Add(reservation);
 }
Beispiel #24
0
 public void Add(TEntity entity)
 {
     cinemaDbContext.Add(entity);
 }