public void UpdateMovieTest() { Movie movie = new Movie(); movie.Name = "Harry Potter and the Philosopher's Stone"; movie.Date = new DateTime(2001, 11, 4); movie.Producer = "Chris Columbus"; movie.Actors = "Daniel Radcliffe, Rupert Grint, Emma Watson"; movie.Genre = "fantasy"; movie.Duration = 152; MovieDAO movieDAO = new MovieDAO(); movieDAO.AddMovie(movie); List <Movie> list = movieDAO.GetMoviesByName(movie.Name); movie = list[list.Count - 1]; movie.Name = "Harry Potter 1"; movieDAO.UpdateMovie(movie); list = movieDAO.GetMoviesByName(movie.Name); string expected = ToStringWithoutId(movie); string actual = ToStringWithoutId(list[list.Count - 1]); Assert.AreEqual(expected, actual); }
void UpdateMovie(string id, string name, string desc, float length, DateTime startDate, DateTime endDate, string productor, string director, int year, byte[] image) { if (MovieDAO.UpdateMovie(id, name, desc, length, startDate, endDate, productor, director, year, image)) { MessageBox.Show("Sửa phim thành công"); } else { MessageBox.Show("Sửa phim thất bại"); } }
public ActionResult UpdateMovie(MoviePO form) { ActionResult response; //Admins and Mods can update movies. if (Session["Role"] != null) { if ((int)Session["Role"] != 1) { if (ModelState.IsValid) { try { MovieDO movieDO = mapper.MapPoToDo(form); movieDataAccess.UpdateMovie(movieDO); response = RedirectToAction("Index", "Movie"); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = View(form); } } else { response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
protected void btnUpdate_Click(object sender, EventArgs e) { string id = txtMovieID.Text.Trim(); //check id null if (id.Equals("")) { SetMessageTextAndColor("MovieID cannot be null", Color.Red); return; } string title = txtMovieTitle.Text.Trim(); if (title.Equals("")) { SetMessageTextAndColor("Movie Title cannot be null", Color.Red); return; } int year = 0, length = 0; float rating = 0; try { length = Convert.ToInt32(txtLength.Text); if (length < 0) { SetMessageTextAndColor("Movie length cannot be negative", Color.Red); return; } } catch { SetMessageTextAndColor("Length must be a number", Color.Red); } try { year = Convert.ToInt32(txtYear.Text); if (year < 0) { SetMessageTextAndColor("Year cannot be negative", Color.Red); return; } } catch { SetMessageTextAndColor("Year must be a number", Color.Red); } try { rating = float.Parse(txtRating.Text); if (rating < 0) { SetMessageTextAndColor("Rating cannot be negative", Color.Red); return; } } catch { SetMessageTextAndColor("Rating must be a number", Color.Red); } string producer = txtProducer.Text.Trim(); string poster = txtPoster.Text.Trim(); string trailer = txtTrailer.Text.Trim(); DateTime startDate = new DateTime(); try { startDate = DateTime.Parse(txtStartDate.Text); } catch { SetMessageTextAndColor("Start Date is wrong format , format must be MM/dd/yyyy", Color.Red); } int genre = ReturnGenreID(dlGenre.SelectedValue); MovieDTO dto = new MovieDTO { MovieID = id, MovieTitle = title, Length = length, Rating = rating, StartDate = startDate, Poster = poster, LinkTrailer = trailer, Producer = producer, Year = year, Genre = genre }; try { if (MovieDao.UpdateMovie(dto)) { List <MovieDTO> list = (List <MovieDTO>)Session["AdminMovieSearch"]; foreach (MovieDTO item in list) { if (item.MovieID.Equals(id)) { item.MovieTitle = dto.MovieTitle; item.Year = dto.Year; item.Length = dto.Length; item.Rating = dto.Rating; item.Producer = dto.Producer; item.Poster = dto.Poster; item.LinkTrailer = dto.LinkTrailer; item.StartDate = dto.StartDate; item.Genre = dto.Genre; } } gvStaffList.DataSource = list; gvStaffList.DataBind(); SetMessageTextAndColor("Successfully updated", Color.Green); } else { SetMessageTextAndColor("Failed to update", Color.Red); } } catch { SetMessageTextAndColor("Server encounter a fatal error please try again later.", Color.Red); } }