Exemple #1
0
        static void InsertMovies()
        {
            using (var db = new MovieContext()) {
                Movie m1 = new Movie {
                    Title   = "Mission Impossible 1",
                    Release = new DateTime(1993, 1, 19),
                    Actors  = new List <Actor> {
                        new Actor {
                            Name = "Tom Cruise", Birth = new DateTime(1966, 1, 1), Gender = "Male"
                        },
                        new Actor {
                            Name = "Jean Reno", Birth = new DateTime(1960, 2, 1), Gender = "Male"
                        },
                        new Actor {
                            Name = "Emmanuelle Beart", Birth = new DateTime(1970, 1, 1), Gender = "Female"
                        }
                    }
                };

                Movie m2 = new Movie {
                    Title   = "No Country for old men",
                    Release = new DateTime(2014, 5, 1),
                    Actors  = new List <Actor> {
                        new Actor {
                            Name = "Xavier Bardem", Birth = new DateTime(1972, 3, 11), Gender = "Male"
                        },
                        new Actor {
                            Name = "Josh Brolin", Birth = new DateTime(1966, 10, 2), Gender = "Male"
                        },
                        new Actor {
                            Name = "Kelly Macdonald", Birth = new DateTime(1975, 2, 3), Gender = "Female"
                        }
                    }
                };

                Movie m3 = new Movie {
                    Title   = "War for the Planet of the Apes",
                    Release = new DateTime(2017, 8, 1),
                    Actors  = new List <Actor> {
                        new Actor {
                            Name = "Woody Harrelson", Birth = new DateTime(1962, 9, 20), Gender = "Male"
                        },
                        new Actor {
                            Name = "Andy Serkis", Birth = new DateTime(1980, 2, 1), Gender = "Male"
                        },
                    }
                };

                db.Add(m1);
                db.Add(m2);
                db.Add(m3);
                int count = db.SaveChanges();
                Console.WriteLine("{0} movies has been inserted", count);
            }
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task <IActionResult> Create(ProductionCompany pc, IFormFile Logo)
        {
            if (Logo == null)
            {
                ModelState.AddModelError(nameof(pc.Logo), "Please select logo file");
            }

            if (ModelState.IsValid)
            {
                string path = "Images/Production/" + Logo.FileName;
                using (var stream = new FileStream(Path.Combine(hostingEnvironment.WebRootPath, path), FileMode.Create))
                {
                    await Logo.CopyToAsync(stream);
                }

                var productionCompany = new ProductionCompany()
                {
                    Name              = pc.Name,
                    Logo              = "~/" + path,
                    AnnualRevenue     = pc.AnnualRevenue,
                    EstablishmentDate = pc.EstablishmentDate
                };

                context.Add(productionCompany);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
Exemple #4
0
        public async Task <IActionResult> CreateMovie([FromBody] Movie movie)
        {
            _context.Add(movie);
            await _context.SaveChangesAsync();

            return(Ok(movie));
        }
Exemple #5
0
        public async Task <Movie> Create(Movie movie)
        {
            _context.Add(movie);
            await _context.SaveChangesAsync();

            return(movie);
        }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price,IsWatched,QualityId,ImageUrl")] Movie movie, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                // full path to file in temp location
                var    filePath = Path.GetTempFileName();
                string unique   = DateTime.UtcNow.Ticks.ToString();
                var    uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", file.FileName);

                //  var upload2 = "E:/Mateen Dev/Github/Crud-with-asp.net-core/DotNetCore/uploads";
                if (file.Length > 0)
                {
                    using (var stream = new FileStream(uploads, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }

                movie.ImageUrl = "/uploads/" + file.FileName;
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task <IActionResult> Create([Bind("Id,UserId,MovieId,RentDate,EndDate,Duration,TotalPrice")] MovieRental movieRental)
        {
            // xử lý logic đầu vào


            if (movieRental.Duration != TimeSpan.Zero)                              // Từ Duration tính EndDate
            {
                movieRental.EndDate = movieRental.RentDate + movieRental.Duration;
            }
            else if (movieRental.EndDate != default(DateTime) && movieRental.EndDate != null)                      // Từ EndDate tính Duration
            {
                movieRental.Duration = (TimeSpan)(movieRental.EndDate - movieRental.RentDate);
            }
            var tMovie = _context.Movies.Where(m => m.Id == movieRental.MovieId).First();

            movieRental.TotalPrice = tMovie.Price * movieRental.Duration.Days; // Duration.Days : chuyển Duration về dạng int số ngày


            if (ModelState.IsValid && (movieRental.Duration != TimeSpan.Zero || (movieRental.EndDate != default(DateTime) && movieRental.EndDate != null)))
            {
                _context.Add(movieRental);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieId"] = new SelectList(_context.Movies, "Id", "Title", movieRental.MovieId);
            ViewData["UserId"]  = new SelectList(_context.Users, "Id", "FullName", movieRental.UserId);
            return(View(movieRental));
        }
        public async Task <IActionResult> Create(Instructor instructor, string[] selectedCourses)
        {
            if (selectedCourses != null)
            {
                //instructor.CourseAssignments = new List<CourseAssignment>();
                foreach (var course in selectedCourses)
                {
                    var courseToAdd = new CourseAssignment {
                        InstructorId = instructor.Id, CourseId = int.Parse(course)
                    };
                    instructor.CourseAssignments.Add(courseToAdd);
                }
            }

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

                return(RedirectToAction(nameof(Index)));
            }

            PopulateAssignedCourseData(instructor);
            return(View(instructor));
        }
 //[ValidateAntiForgeryToken]
 public bool Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         _context.Add(movie);
         return(true);
     }
     return(false);
 }
Exemple #10
0
 public IActionResult Create([Bind("RatingID,Code,Name")] Rating rating)
 {
     if (ModelState.IsValid)
     {
         _context.Add(rating);
         _context.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View(rating));
 }
 public IActionResult Post([FromBody] NewMovie movie)
 {
     if (ModelState.IsValid)
     {
         _context.Add(movie);
         _context.SaveChanges();
         return(Ok(movie));
     }
     return(BadRequest());
 }
Exemple #12
0
        public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);                             // add the new object to the database...
                await _context.SaveChangesAsync();               // ...and save all changes

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task <IActionResult> Create([Bind("id,Name")] Director director)
        {
            if (ModelState.IsValid)
            {
                _DB.Add(director);
                await _DB.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(director));
        }
        public async Task <IActionResult> Create([Bind("Id,Maker,Image,Url,Title,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("RMID,MovieIDFK,CustIDFK,DateRented,DateReturned")] RentedMovies rentedMovies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedMovies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rentedMovies));
        }
        public async Task <IActionResult> Create([Bind("ActorId,Name,DateBirth")] Actor actor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(actor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(actor));
        }
Exemple #17
0
        public async Task <IActionResult> Create([Bind("GenreId,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
Exemple #18
0
        public async Task <IActionResult> Create([Bind("Id,Title,Year,Director")] MovieModel movieModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieModel));
        }
Exemple #19
0
        public async Task <IActionResult> Create([Bind("Id,Nb,Priority,IsSlideShow,DownloadStatus,EnTitle,ArTitle,OtherTitle,Stars,EnTranslationFile,ArTranslationFile,FileFile,ArContent,EnContent,MDate,Year,Kind,Season,Img,ImgThumb,ImgMediumThumb,ImgObjUrl,ImgMediumThumbObjUrl,FilmRating,SeriesRating,EpisodeNummer,Rate,IsSpecial,ItemDate,Duration,ImdbUrlRef,ImgBanner,RootSeries,UseParentImg,SpTranslationFile,ShowComments,EpisodeFlag,Trailer,AudioStreamNumber,ParentSkipping,CollectionId,IsDeleted,CacheShort,ImgThumbObjUrl,ArTranslationFilePath,EnTranslationFilePath,HasIntroSkipping,VideoLikesNumber,VideoDisLikesNumber,VideoCommentsNumber,VideoViewsNumber,Castable,StartDownloadAt,FinishDownloadAt,DownloadRetry,DownloadId")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Exemple #20
0
        public async Task <IActionResult> Create([Bind("MovieID,Title,Year,Plot,Genre,Copies")] Movies movies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movies));
        }
Exemple #21
0
        public async Task <IActionResult> Create([Bind("Id,UserName,FullName")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemple #22
0
        public async Task <IActionResult> Create([Bind("ID,Category,Title,Year,Director,Rating,Edited,Lent,Notes")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task <IActionResult> Create([Bind("CustID,FirstName,LastName,Address,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemple #24
0
        public async Task <IActionResult> Create([Bind("MovieStudioID,Name,Founded")] MovieStudio movieStudio)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieStudio);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieStudio));
        }
Exemple #25
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,ReleaseDate,Price,CategoryId")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", movie.CategoryId);
            return(View(movie));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,ReleaseDate,Director,ContactEmailAddress,CategoryID")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "ID", movie.CategoryID);
            return(View(movie));
        }
Exemple #27
0
        public async Task <IActionResult> Create([Bind("MovieId,Title,Director,ReleaseDate,Gross,Rating,GenreID")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreID"] = new SelectList(_context.Genres, "GenreId", "GenreId", movie.GenreID);
            return(View(movie));
        }
Exemple #28
0
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits,DepartmentId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateDepartmentsDropDownList(course.DepartmentId);
            return(View(course));
        }
        public async Task <IActionResult> Create([Bind("MovieID,Title,ReleaseDate,Genre,Price,MovieStudioID")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieStudioID"] = new SelectList(_context.MovieStudio, "MovieStudioID", "MovieStudioID", movie.MovieStudioID);
            return(View(movie));
        }
Exemple #30
0
        public async Task <IActionResult> Create([Bind("DepartmentId,Name,Budget,StartDate,InstructorId,RowVersion")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InstructorId"] = new SelectList(_context.Instructors, "Id", "FirstMidName", department.InstructorId);
            return(View(department));
        }