Exemplo n.º 1
0
 public Task <Films> AddMovie(Films film)
 {
     _CinemaDbContext.Entry(film).State = EntityState.Added;
     _CinemaDbContext.Films.Add(film);
     _CinemaDbContext.SaveChanges();
     return(Task.FromResult(film));
 }
Exemplo n.º 2
0
        // Add to Database
        #region

        public Task <Reserveringen> AddReservering(Reserveringen res, ReserveringenVertoningen rVert)
        {
            _CinemaDbContext.Entry(res).State = EntityState.Added;
            _CinemaDbContext.Reserveringen.Add(res);
            _CinemaDbContext.SaveChanges();

            _CinemaDbContext.Entry(rVert).State = EntityState.Added;
            _CinemaDbContext.ReserveringenVertoningen.Add(rVert);
            _CinemaDbContext.SaveChanges();

            return(Task.FromResult(res));
        }
Exemplo n.º 3
0
 public User Update(User user)
 {
     _context.Users.Attach(user);
     _context.Entry(user).State = EntityState.Modified;
     _context.SaveChanges();
     return(user);
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("FilmeId,Titulo,Classificacao,GeneroId,Ativa")] Filme filme, IFormFile Imagem)
        {
            if (id != filme.FilmeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (Imagem != null && Imagem.Length > 0)
                    {
                        using (var stream = new MemoryStream())
                        {
                            await Imagem.CopyToAsync(stream);

                            filme.Imagem = stream.ToArray();
                        }
                        _context.Update(filme);
                    }
                    else
                    {
                        _context.Entry(filme).State = EntityState.Unchanged;
                        _context.Entry(filme).Property("Titulo").IsModified        = true;
                        _context.Entry(filme).Property("Classificacao").IsModified = true;
                        _context.Entry(filme).Property("GeneroId").IsModified      = true;
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FilmeExists(filme.FilmeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GeneroId"] = new SelectList(_context.Generos, "GeneroId", "Descricao", filme.GeneroId);
            return(View(filme));
        }
Exemplo n.º 5
0
 public void Update(object obj)
 {
     db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     if (db.SaveChanges() > 0)
     {
         NotifyObservers(obj.GetType()); // OBSERVER NOTIFICATION
     }
 }
Exemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Hall hall)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hall).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hall));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Updates information about a ticket
        /// </summary>
        /// <param name="ticket">Updated ticket object</param>
        public async Task UpdateAsync(ProjectionTicket ticket)
        {
            var ticketDataInContext = await context.ProjectionTickets.FindAsync(ticket.Id);

            if (ticketDataInContext != null)
            {
                context.Entry(ticketDataInContext).CurrentValues.SetValues(ticket);
                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 8
0
 public ActionResult Edit(Pelicula pelicula)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pelicula).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pelicula));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Update the selected review if exists
        /// </summary>
        /// <param name="filmReview">An updated review of the film</param>
        public async Task UpdateAsync(FilmReview filmReview)
        {
            var filmInContext = await context.FilmReviews.FindAsync(filmReview.Id);

            if (filmInContext != null)
            {
                context.Entry(filmInContext).CurrentValues.SetValues(filmReview);
                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "Extra_id,Descripcion,Precio,Activo")] Extra extra)
 {
     if (ModelState.IsValid)
     {
         db.Entry(extra).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(extra));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the data about a selected film
        /// </summary>
        /// <param name="filmData">The updated data of the film</param>
        public async Task UpdateAsync(FilmData filmData)
        {
            var filmDataInContext = await context.FilmDatas.FindAsync(filmData.FilmId);

            if (filmDataInContext != null)
            {
                context.Entry(filmDataInContext).CurrentValues.SetValues(filmData);
                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 12
0
        public ActionResult Edit(UserEditViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            int userId = HttpContext.User.Identity.GetUserId <int>();

            var entity = db.Users.FirstOrDefault(UserViewEdit => UserViewEdit.Id == userId);

            if (entity != null)
            {
                entity.Name    = user.Name;
                entity.Surname = user.Surname;
                //entity.Password = user.Password;
                entity.BirthDate = user.BirthDate;
                if (entity.BirthDate > DateTime.Now.AddYears(-5))
                {
                    ModelState.AddModelError("", "Data urodzenia jest nieprawidłowa.");
                    return(View(user));
                }
                entity.Address = user.Address;
                entity.Phone   = user.Phone;

                var city = db.Cities.FirstOrDefault(c => c.Name == user.City);

                if (city == null)
                {
                    city        = new City();
                    city.Name   = user.City;
                    entity.City = city;
                    db.Cities.Add(city);
                }

                entity.City  = city;
                entity.Email = user.Email;

                db.Users.Attach(entity);
                var entry = db.Entry(entity);

                entry.Property(e => e.Name).IsModified      = true;
                entry.Property(e => e.Surname).IsModified   = true;
                entry.Property(e => e.Password).IsModified  = true;
                entry.Property(e => e.BirthDate).IsModified = true;
                entry.Property(e => e.Address).IsModified   = true;
                entry.Property(e => e.Phone).IsModified     = true;
                entry.Property(e => e.Email).IsModified     = true;

                db.SaveChanges();
            }
            ViewBag.Message = "Twoje konto zostało edytowane";

            return(View(user));
        }
Exemplo n.º 13
0
        public ActionResult Edit(UserEditViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            CinemaDbContext db = new CinemaDbContext();

            var sessionId = Session["LoggedUserID"];

            if (sessionId == null)
            {
                return(View(""));
            }
            int userId = (int)sessionId;

            var entity = db.Users.FirstOrDefault(UserViewEdit => UserViewEdit.Id == userId);

            if (entity != null)
            {
                entity.Name      = user.Name;
                entity.Surname   = user.Surname;
                entity.Password  = user.Password;
                entity.BirthDate = user.BirthDate;
                entity.Address   = user.Address;
                entity.Phone     = user.Phone;
                var city = db.Cities.FirstOrDefault(c => c.Name == user.City);
                if (city == null)
                {
                    city        = new City();
                    city.Name   = user.City;
                    entity.City = city;
                    db.Cities.Add(city);
                }

                entity.Email = user.Email;

                db.Users.Attach(entity);
                var entry = db.Entry(entity);

                entry.Property(e => e.Name).IsModified      = true;
                entry.Property(e => e.Surname).IsModified   = true;
                entry.Property(e => e.Password).IsModified  = true;
                entry.Property(e => e.BirthDate).IsModified = true;
                entry.Property(e => e.Address).IsModified   = true;
                entry.Property(e => e.Phone).IsModified     = true;
                entry.Property(e => e.Email).IsModified     = true;

                db.SaveChanges();
            }
            ViewBag.Message = "Twoje konto zostało edytowane";

            return(View(user));
        }
        public ActionResult Edit([Bind(Include = "Id,Row,Number,HallId,ShowId,IsAvaliable")] Seat seat)
        {
            if (ModelState.IsValid)
            {
                db.Entry(seat).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.HallId = new SelectList(db.Halls, "Id", "Name", seat.HallId);

            return(View(seat));
        }
 public ActionResult Edit([Bind(Include = "Id,ShowId,SeatId,CustomerId")] Ticket ticket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", ticket.CustomerId);
     ViewBag.SeatId     = new SelectList(db.Seats, "Id", "Row", ticket.SeatId);
     ViewBag.ShowId     = new SelectList(db.Shows, "Id", "Id", ticket.ShowId);
     return(View(ticket));
 }
Exemplo n.º 16
0
        public ITicket BuyTicket(TicketBuyingModel ticketBuyingModel)
        {
            var ticket = new Ticket();

            ticket.ColumnNumber = ticketBuyingModel.ColumnNumber;
            ticket.RowNumber    = ticketBuyingModel.RowNumber;
            ticket.ProjectionId = ticketBuyingModel.ProjectionId;
            this.dbContext.Tickets.Add(ticket);
            dbContext.SaveChanges();
            dbContext.Entry(ticket).Reference(a => a.Projection).Load();
            dbContext.Entry(ticket.Projection).Reference(a => a.Movie).Load();
            dbContext.Entry(ticket.Projection).Reference(a => a.Room).Load();
            dbContext.Entry(ticket.Projection.Room).Reference(a => a.Cinema).Load();

            return(ticket);
        }
Exemplo n.º 17
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.");
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Update a cinema in the database
        /// and send email to people who had reserved tickets to inform about the changes.
        /// </summary>
        /// <param name="id">The id of the cinema</param>
        /// <param name="id">The URL of the projection</param>
        public async Task UpdateAsync(Cinema cinema, string ticketUrlPattern)
        {
            var cinemaInContext = await context.Cinemas.FindAsync(cinema.Id);

            if (cinemaInContext != null)
            {
                var projections = context.FilmProjections.Where(x => x.CinemaId == cinemaInContext.Id).ToList();
                foreach (var projection in projections)
                {
                    var projectionTickets = projection.ProjectionTickets.ToList();
                    foreach (var ticket in projectionTickets)
                    {
                        await emailSender.SendTicketUpdateEmailAsync(ticket.Holder.Email,
                                                                     ticket.Projection,
                                                                     ticketUrlPattern);
                    }
                }
                context.Entry(cinemaInContext).CurrentValues.SetValues(cinema);
                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 19
0
        public ActionResult Update(Film films, int[] countryIds, int[] janreIds)
        {
            if (films.Name != null &&
                films.PublicationDate != null &&
                films.Link != null &&
                janreIds != null &&
                countryIds != null &&
                films.Duration != 0)
            {
                User user = Session["User"] as User;
                films.UserId          = user.Id;
                db.Entry(films).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                DeleteRelations(films.Id);
                foreach (int item in countryIds)
                {
                    FilmCountry filmCountry = new FilmCountry()
                    {
                        FilmId    = films.Id,
                        CountryId = item
                    };
                    db.FilmCountries.Add(filmCountry);
                    db.SaveChanges();
                }

                foreach (int item in janreIds)
                {
                    FilmJanre filmGenre = new FilmJanre()
                    {
                        FilmId  = films.Id,
                        JanreId = item
                    };
                    db.FilmJanres.Add(filmGenre);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(Content("Xanalai doldurun"));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Updates information for a selected projection
        /// and send email to infrom about the update
        /// </summary>
        /// <param name="projection">New projection object</param>
        /// <param name="projectionsUrlPattern">Projection page reference url</param>
        /// <param name="ticketsUrlPattern">Tickets page reference url</param>
        public async Task UpdateAsync(FilmProjection projection, string projectionsUrlPattern, string ticketsUrlPattern)
        {
            var projectionInContext = await context.FilmProjections.FindAsync(projection.Id);

            if (projectionInContext != null)
            {
                foreach (var ticket in context.ProjectionTickets.Where(x => x.ProjectionId == projection.Id).ToList())
                {
                    if (ticket.Seat > projection.TotalTickets)
                    {
                        await emailSender.SendTicketCancelationEmailAsync(ticket.Holder.Email,
                                                                          projectionInContext,
                                                                          projectionsUrlPattern);

                        context.ProjectionTickets.Remove(ticket);
                    }
                    else
                    {
                        switch (ticket.Type)
                        {
                        case TicketType.Adult: ticket.Price = projection.TicketPrices.AdultPrice; break;

                        case TicketType.Children: ticket.Price = projection.TicketPrices.ChildrenPrice; break;

                        case TicketType.Student: ticket.Price = projection.TicketPrices.StudentPrice; break;
                        }

                        await emailSender.SendTicketUpdateEmailAsync(ticket.Holder.Email,
                                                                     projectionInContext,
                                                                     ticketsUrlPattern);
                    }
                }
                context.Entry(projectionInContext).CurrentValues.SetValues(projection);
                projectionInContext.TicketPrices.AdultPrice    = projection.TicketPrices.AdultPrice;
                projectionInContext.TicketPrices.StudentPrice  = projection.TicketPrices.StudentPrice;
                projectionInContext.TicketPrices.ChildrenPrice = projection.TicketPrices.ChildrenPrice;
                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 21
0
 public void Update(TEntity entityToBeUpdated)
 {
     dbSet.Attach(entityToBeUpdated);
     cinemaDbContext.Entry(entityToBeUpdated).State = EntityState.Modified;
 }
Exemplo n.º 22
0
 public bool SeatIsReserved(int row, int col, Projection projection)
 {
     db.Entry(projection).Collection(a => a.Reservations).Load();
     return(projection.Reservations.Any(a => (a.ColumnNumber == col && a.RowNumber == row && a.IsActive)));
 }
        public ActionResult EditFilm(AddFilmViewModel model)
        {
            //var film = db.Films.Find(id);
            var film = db.Films.FirstOrDefault(x => x.Id == model.Id);

            if (!ModelState.IsValid)
            {
                model.FilmGenres = db.FilmGenres.Select(x =>
                                                        new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Creators = db.Creators.Select(x =>
                                                    new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Image = film.Image;

                return(View(model));
            }

            if (db.Films.Any(x => x.Title == model.Title))
            {
                model.FilmGenres = db.FilmGenres.Select(x =>
                                                        new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Creators = db.Creators.Select(x =>
                                                    new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Image = film.Image;

                ModelState.AddModelError(String.Empty, "Ten tytuł jest już w bazie.");

                return(View(model));
            }

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var    fileName  = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
                    string extension = Path.GetExtension(model.ImageFile.FileName);
                    fileName    = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    model.Image = "~/Content/img/" + fileName;
                    fileName    = Path.Combine(Server.MapPath("~/Content/img/"), fileName);
                    model.ImageFile.SaveAs(fileName);

                    film.Image = model.Image;
                }
            }

            film.Deleted     = model.Deleted;
            film.Duration    = model.Duration;
            film.Title       = model.Title;
            film.Description = model.Description;
            var filmGenre = db.FilmGenres.FirstOrDefault(c => c.Id == model.FilmGenre);

            film.FilmGenre = filmGenre;
            var creator = db.Creators.FirstOrDefault(c => c.Id == model.Creator);

            film.Creator = creator;

            db.Entry(film).State = EntityState.Modified;
            db.SaveChanges();
            ModelState.Clear();

            return(RedirectToAction("FilmList"));
        }