コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Forename,Surname,DOB")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,date,name,isHoliday,holidayCategory,description")] Calendar calendar)
        {
            if (id != calendar.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(calendar);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CalendarExists(calendar.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(calendar));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie) //notice BindAttribute is applied to a param - here it protects against overposting (another option is to use ViewModels).
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,movieID,Name,Comment")] Review review)
        {
            if (id != review.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Movies", new { id = id }));
            }
            return(View(review));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Reviewer,UserReview,MovieID,MovieTitle")] Review review)
        {
            if (id != review.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction($"Details{"/" + review.MovieID}", "Movies"));
            }
            ViewData["thisMovieID"]    = review.MovieID;
            ViewData["thisMovieTitle"] = review.MovieTitle;
            return(View(review));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Titulo,DataLancamento,Genero,Preco,Avaliacao")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #7
0
ファイル: SubjectsController.cs プロジェクト: Mazhar30/Movies
        public async Task <IActionResult> Edit(int id, [Bind("Id,sub,mark")] Subjects subjects)
        {
            if (id != subjects.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subjects);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubjectsExists(subjects.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subjects));
        }
コード例 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price")] Todo todo)
        {
            if (id != todo.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(todo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TodoExists(todo.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(todo));
        }
コード例 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Title,Genre")] Book book)
        {
            if (id != book.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
コード例 #10
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }

            // 5.1.) The ModelState.IsValid method verifies that the data
            //       submitted in the form can be used to modify (edit or
            //       update) a Movie object.
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(movie));
        }
コード例 #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price")]
                                               Movie movie)
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync().ConfigureAwait(false);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }

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

            return(View(movie));
        }
コード例 #13
0
        public async Task <IActionResult> Edit(int id, [Bind("GenreID,Description")] Genre genre)
        {
            if (id != genre.GenreID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(genre);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GenreExists(genre.GenreID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
コード例 #14
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,GenreId,Price,ImageUrl")] Movie movie)
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Set <Genre>(), "GenreId", "GenreId", movie.GenreId);
            return(View(movie));
        }
コード例 #15
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating,DiretorID")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DiretorID"] = new SelectList(_context.Diretor, "ID", "Name", movie.DiretorID);
            return(View(movie));
        }
コード例 #16
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,IsDone,Priority")] ToDo toDo)
        {
            if (id != toDo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(toDo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ToDoExists(toDo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDo));
        }
コード例 #17
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,DOB,Email")] User user)
        {
            if (id != user.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
コード例 #18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Code")] Language language)
        {
            if (id != language.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(language);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LanguageExists(language.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(language));
        }
コード例 #19
0
        public async Task <IActionResult> Edit(int id, [Bind("ReviewsID,Reviewer,Review,MovieID")] Reviews reviews)
        {
            if (id != reviews.ReviewsID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reviews);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewsExists(reviews.ReviewsID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Movies", new { id = reviews.MovieID }));
            }
            ViewData["MovieID"] = new SelectList(_context.Movie, "ID", "Title", reviews.MovieID);
            return(View(reviews));
        }
コード例 #20
0
        public async Task <IActionResult> Edit(int id, [Bind("Description,University,Id,Name,Lastname,Phone,Genre,Email,Birthdate")] Speaker speaker)
        {
            if (id != speaker.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(speaker);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SpeakerExists(speaker.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(speaker));
        }
コード例 #21
0
        public async Task <IActionResult> Edit(int id, MovieEditViewModel movieEditViewModel)
        {
            if (id != movieEditViewModel.Movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var movie = movieEditViewModel.Movie;
                try
                {
                    movie.Genre = await _context.Genres.FindAsync(movieEditViewModel.GenreIdSelected);

                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieEditViewModel));
        }
コード例 #22
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,BirthDay")] Diretor diretor)
        {
            if (id != diretor.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(diretor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiretorExists(diretor.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(diretor));
        }
コード例 #23
0
        public async Task <IActionResult> Upload(IFormFile file, int id)
        {
            string filePath = "./Images/" + file.FileName;

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(fileStream);
            }

            Movie movie = _context.Movie.Find(id);

            movie.Image = file.FileName;
            _context.Update(movie);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details/" + id));
        }
コード例 #24
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating,DirectorID,NewDirector")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                try
                {
                    var NewDirectorName = Request.Form["textbox"];
                    //add director
                    if (!string.IsNullOrWhiteSpace(NewDirectorName))
                    {
                        Director director = new Director(NewDirectorName);
                        _context.Update(director);
                        await _context.SaveChangesAsync();

                        movie.DirectorID = director.ID;
                    }
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Directors"] = CreateDirectorDropdown();;

            return(View(movie));
        }
コード例 #25
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            List <Rating> ratings = new List <Rating>();
            Rating        ratingItem;
            var           strArr = new string[] { "G", "PG", "PG-13", "R", "NC-17", "NR" };

            for (int index = 0; index < strArr.Length; index++)
            {
                ratingItem       = new Rating();
                ratingItem.Text  = strArr[index];
                ratingItem.Value = (index + 1).ToString();
                ratings.Add(ratingItem);
            }
            ViewData["Ratings"] = ratings;
            if (id != movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #26
0
        public async Task <IActionResult> Edit(int id, string name, [Bind("Id,Name,ImageName,ImageFile,show,type,time")] Movie movie)
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // ถ้า รูปมีการใส่ ค่า ก็ให้ save
                if (movie.ImageFile != null)
                {
                    //Save image to wwwroot/image
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(movie.ImageFile.FileName);
                    string extension   = Path.GetExtension(movie.ImageFile.FileName);
                    movie.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await movie.ImageFile.CopyToAsync(fileStream);
                    }
                }//เครื่องปิด if (movie.ImageFile != null)


                //if (_context.Movie.Any(ac => ac.Name.Equals(movie.Name)))
                //{
                //    ModelState.AddModelError("Name", "Name already exists in database.");
                //} // ชื่อไม่ซำ้
                //else
                //{
                try
                {
                    _context.Update(movie);            // มีการอัป
                    await _context.SaveChangesAsync(); // save
                } // try

                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
                //}
            }
            return(View(movie));
        }
コード例 #27
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price,Rating,Image,ImagePath")] MovieEditModel movie)
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = movie.ImagePath;

                    if (movie.Image != null)
                    {
                        // ;
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "img");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + movie.Image.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        movie.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                    }

                    Movie newMovie = new Movie
                    {
                        Id          = id,
                        Title       = movie.Title,
                        ReleaseDate = movie.ReleaseDate,
                        Genre       = movie.Genre,
                        Price       = movie.Price,
                        Rating      = movie.Rating,
                        Image       = uniqueFileName
                    };
                    _context.Update(newMovie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #28
0
        public async Task <IActionResult> Edit(int id, [Bind("MovieId,Title,ReleaseDate,GenreID,Price,Photo")] MovieEditViewModel movie)
        {
            if (id != movie.MovieId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFilename = null;
                    if (movie.Photo != null)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                        uniqueFilename = Guid.NewGuid().ToString() + "_" + movie.Photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFilename);
                        movie.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                    }

                    Movie m = new Movie
                    {
                        MovieId     = movie.MovieId,
                        Title       = movie.Title,
                        ReleaseDate = movie.ReleaseDate,
                        GenreID     = movie.GenreID,
                        Price       = movie.Price,
                        PhotoPath   = uniqueFilename
                    };

                    _context.Update(m);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.MovieId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreID"] = new SelectList(_context.Genre, "GenreID", "Description", movie.GenreID);
            return(View(movie));
        }
コード例 #29
0
        // public async Task<IActionResult> Edit (int id, [Bind("ID,Title,ReleaseDate,Genre,Price, Rating")] Movie movie)
        public async Task <IActionResult> Edit(int id, [FromBody] Movie movie)
        {
            if (ModelState.IsValid)
            {
                if (id != movie.ID)
                {
                    return(NotFound());
                }

                var movToEdit = _context.Movie.Find(id);

                if (movToEdit == null)
                {
                    return(BadRequest(ModelState));
                }

                try
                {
                    movToEdit.ID          = movie.ID;
                    movToEdit.Title       = movie.Title;
                    movToEdit.Price       = movie.Price;
                    movToEdit.ReleaseDate = movie.ReleaseDate;
                    movToEdit.Genre       = movie.Genre;
                    movToEdit.Rating      = movie.Rating;

                    _context.Update(movToEdit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                // return RedirectToAction(nameof(Index));
            }
            else
            {
                return(BadRequest(ModelState));
            }

            return(View(movie));
        }
コード例 #30
0
        public async Task <IActionResult> Edit(int id, [Bind("ID", "Name")] Genre genre)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(genre);
                await _context.SaveChangesAsync();

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