Ejemplo n.º 1
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     bool isAlreadyExists;
     using (var context = new MyMoviesContext())
     {
         var movie = new Movie
         {
             Title = tbTitle.Text,
             Year = Int32.Parse(tbYear.Text),
             Genre = context.Genres.Find(Int32.Parse(ddlGenre.SelectedItem.Value))
         };
         isAlreadyExists = context.Movies.FirstOrDefault(x => x.Title == movie.Title && x.Year == movie.Year && x.GenreId == movie.Genre.Id) != null;
         if (!isAlreadyExists)
         {
             context.Movies.Add(movie);
             context.SaveChanges();
         }
     }
     if (isAlreadyExists)
     {
         Response.Redirect(Request.Url.AbsoluteUri.Substring(0,
             Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()) + "?movieAction=exist");
     }
     else
     {
         Response.Redirect("~/Default.aspx");
     }
 }
Ejemplo n.º 2
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     bool isAlreadyExists;
     using (var context = new MyMoviesContext())
     {
         var genre = new Genre
         {
             Name = tbName.Text,
         };
         isAlreadyExists = context.Genres.FirstOrDefault(x => x.Name == genre.Name) != null;
         if (!isAlreadyExists)
         {
             context.Genres.Add(genre);
             context.SaveChanges();
         }
     }
     if (isAlreadyExists)
     {
         Response.Redirect(Request.Url.AbsoluteUri.Substring(0,
             Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()) + "?genreAction=exist");
     }
     else
     {
         Response.Redirect("~/Default.aspx");
     }
 }
Ejemplo n.º 3
0
    { public static void Initialize(IServiceProvider serviceProvider)
      {
          using (var context = new MyMoviesContext(
                     serviceProvider.GetRequiredService <
                         DbContextOptions <MyMoviesContext> >()))
          {
              // Look for any movies.
              if (context.Movie.Any())
              {
                  return;     // DB has been seeded
              }

              context.Movie.AddRange(
                  new Movie
                {
                    Title       = "17 Miracles",
                    ReleaseDate = DateTime.Parse("2011-6-3"),
                    Genre       = "Adventure History",
                    Price       = 14.99M,
                    Rating      = "PG"
                },

                  new Movie
                {
                    Title       = "The Book of Mormon Movie, Volume 1: The Journey",
                    ReleaseDate = DateTime.Parse("2004-1-12"),
                    Genre       = "Adventure",
                    Price       = 9.99M,
                    Rating      = "PG-13"
                },

                  new Movie
                {
                    Title       = "Legacy",
                    ReleaseDate = DateTime.Parse("1993-7-3"),
                    Genre       = "Drama History Western",
                    Price       = 11.94M,
                    Rating      = "NA"
                },

                  new Movie
                {
                    Title       = "The Testaments: Of One Fold and One Shepherd",
                    ReleaseDate = DateTime.Parse("2000-3-24"),
                    Genre       = "Drama",
                    Price       = 4.50M,
                    Rating      = "NA"
                }
                  );
              context.SaveChanges();
          }
      }
Ejemplo n.º 4
0
 public DeleteModel(MyMovies.Models.MyMoviesContext context)
 {
     _context = context;
 }
Ejemplo n.º 5
0
 public EditModel(MyMovies.Models.MyMoviesContext context)
 {
     _context = context;
 }
Ejemplo n.º 6
0
 public IndexModel(MyMovies.Models.MyMoviesContext context)
 {
     _context = context;
 }
Ejemplo n.º 7
0
 public CreateModel(MyMovies.Models.MyMoviesContext context)
 {
     _context = context;
 }
Ejemplo n.º 8
0
 public DetailsModel(MyMovies.Models.MyMoviesContext context)
 {
     _context = context;
 }