Пример #1
0
        // PUT api/Movies/5
        public async Task<IHttpActionResult> PutMovie(int id, Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != movie.Id)
            {
                return BadRequest();
            }

            db.Entry(movie).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        private IEnumerable<Movie> ReadFromFile()
        {
            var map = new string[4] { "title", "openingGross", "date", "cast" };
            List<Movie> movies = new List<Movie>();
            var json = System.IO.File.ReadAllText(FilePath);

            var objects = JArray.Parse(json);

            foreach (JObject root in objects)
            {
                var title = (String)root[MovieMap.title.ToString()];
                var gross = (Int32)root[MovieMap.openingGross.ToString()];
                var date = (DateTime)root[MovieMap.date.ToString()];
                var cast = new List<string>();
                if (root["cast"] != null)
                {
                    var castArr = root["cast"].ToArray() ?? null;

                    foreach (var item in castArr)
                    {
                        cast.Add((string)item);
                    }
                }
                var movie = new Movie()
                {
                    title = title,
                    openingGross = gross,
                    date = date,
                    cast = cast
                };
                movies.Add(movie);
            }

            return movies;
        }
Пример #3
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(movie);
 }
Пример #4
0
 public ActionResult Create(Movie movie)
 {
     if (ModelState.IsValid)
     {
         movie.User = CurrentUser;
         DataContext.Movies.Save(movie);
         return RedirectToAction("Index");
     }
     return View("Index", CurrentUser.Movies);
 }
Пример #5
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(movie);
        }
Пример #6
0
        public async Task<IHttpActionResult> GetMovie(int id)
        {
            //Movie movie = await db.Movies.FindAsync(id);
            var movie = new Movie();
            if (movie == null)
            {
                return NotFound();
            }

            return Ok(movie);
        }
Пример #7
0
        public async Task<IHttpActionResult> PostMovie(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Movies.Add(movie);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = movie.Id }, movie);
        }
Пример #8
0
        private IList<Movie> getMovies()
        {
            var movies = new List<Movie>();

            var movieOne = new Movie {Id = 1, Genre = "Action", Rating = "five", Title = "Action Jacson", Year = 1980};
            movies.Add(movieOne);
            var movieTwo = new Movie {Id = 2, Genre = "Action", Rating = "one", Title = "Muscle man", Year = 1988};
            movies.Add(movieTwo);
            var movieThree = new Movie { Id = 3, Genre = "Fantasy", Rating = "four", Title = "Whatha?", Year = 1988 };
            movies.Add(movieThree);

            return movies;
        }
Пример #9
0
        public ActionResult Create(Movie newMovie, HttpPostedFileBase image)
        {
            var movie = _movieRepository.CreateMovie(newMovie, image);

            if (ModelState.IsValid)
            {
                return RedirectToAction("Index");
            }
            else
            {
                return View(movie);
            }
        }
Пример #10
0
        public Movie EditMovie(Movie movie, HttpPostedFileBase image)
        {
            if (image != null)
            {
                byte[] fileBytes = new byte[image.ContentLength];
                int byteCount = image.InputStream.Read(fileBytes, 0, (int)image.InputStream.Length);
                string fileContent = Convert.ToBase64String(fileBytes);
                movie.Photo = fileContent;
            }

            _movieContext.Entry(movie).State = EntityState.Modified;
            _movieContext.SaveChanges();
            return movie;
        }
Пример #11
0
        public void Update(Movie movie)
        {
            #region Update

            try
            {
                _repository.Update(movie);
                _unitOfWork.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }

            #endregion
        }
Пример #12
0
        public void Add(Movie movie)
        {
            #region Add

            try
            {
                _repository.Create(movie);
                _unitOfWork.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }

            #endregion
        }
Пример #13
0
        public Movie CreateMovie(Movie newMovie, HttpPostedFileBase image)
        {
            if (getAll().Any(m=>m.Title != newMovie.Title))
            {
                if (image != null)
                {
                    byte[] fileBytes = new byte[image.ContentLength];
                    int byteCount = image.InputStream.Read(fileBytes, 0, (int)image.InputStream.Length);
                    string fileContent = Convert.ToBase64String(fileBytes);
                    newMovie.Photo = fileContent;
                }
            }

            _movieContext.Movies.Add(newMovie);
            _movieContext.SaveChanges();
            return newMovie;
        }
        public ActionResult Create(MovieViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newMovie = new Movie()
                {
                    Title = model.Title,
                    Year = model.Year,
                    StudioName = model.StudioName,
                    StudioAddress = model.StudioAddress,
                    LeadingFemaleRole = new Actor() { Name = model.LeadingFemaleRole, Age = model.LeadingFemaleRoleAge },
                    LeadingMaleRole = new Actor() { Name = model.LeadingMaleRole, Age = model.LeadingMaleRoleAge }
                };

                this.movies.Add(newMovie);
                this.movies.SaveChanges();
                return this.RedirectToAction("Index");
            }

            return View(model);
        }
Пример #15
0
 public ActionResult EditPost(Movie movie,HttpPostedFileBase image)
 {
     _movieRepository.EditMovie(movie, image);
     return RedirectToAction("Index");
 }
 private void FormatCast(Movie movie)
 {
     movie.Cast = movie.Cast.Replace("\n", ", ");
 }
 public static MovieDictionaryItem MovieShowingAt(Movie movie)
 {
     var dictionary = new ShowDictionary();
     return dictionary.GetMovieShowingAt(movie);
 }
Пример #18
0
        public ActionResult Edit(Movie movie)
        {
            if (ModelState.IsValid)
            {
                var fromDb = db.Movies
                    .Include(m => m.LeadingMaleRole)
                    .Include(m => m.LeadingFemaleRole)
                    .FirstOrDefault(m => m.Id == movie.Id);

                fromDb.Title = movie.Title;
                fromDb.Year = movie.Year;
                fromDb.StudioName = movie.StudioName;
                fromDb.StudioAddress = movie.StudioAddress;
                fromDb.LeadingMaleRole.Name = movie.LeadingMaleRole.Name;
                fromDb.LeadingMaleRole.Age = movie.LeadingMaleRole.Age;
                fromDb.LeadingFemaleRole.Name = movie.LeadingFemaleRole.Name;
                fromDb.LeadingFemaleRole.Age = movie.LeadingFemaleRole.Age;

                //db.Movies.Attach(movie);
                //db.Actors.Attach(movie.LeadingMaleRole);
                //db.Actors.Attach(movie.LeadingFemaleRole);
                //db.Entry(movie).State = EntityState.Modified;
                //db.Entry(movie.LeadingFemaleRole).State = EntityState.Modified;
                //db.Entry(movie.LeadingFemaleRole).State = EntityState.Modified;
                //db.Entry(fromDb).CurrentValues.SetValues(movie);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(movie);
        }
 private MovieDictionaryItem GetMovieShowingAt(Movie movie)
 {
     List<MovieDictionaryItem> moviesDictionary = GetDictionary();
     return moviesDictionary.First(m => m.MovieNodeId == movie.NodeId);
 }
Пример #20
0
        public async Task<IHttpActionResult> DeleteMovie(int id)
        {
            //Movie movie = await db.Movies.FindAsync(id);
            var movie = new Movie();
            if (movie == null)
            {
                return NotFound();
            }

            db.Movies.Remove(movie);
            await db.SaveChangesAsync();

            return Ok(movie);
        }
Пример #21
0
        public ActionResult Edit(Movie movie)
        {
            if (ModelState.IsValid)
            {
                // EF is not happy about the fact that I am trying to re-attach 
                // and update an object that is already placed in the cache
                // solution is:
                var entry = this.db.Entry(movie);

                if (entry.State == EntityState.Detached)
                {
                    var currentEntry = this.db.Movies.Find(movie.Id);
                    if (currentEntry != null)
                    {
                        var attachedEntry = this.db.Entry(currentEntry);
                        // remap the values from our model to the entry in DB
                        attachedEntry.CurrentValues.SetValues(movie);
                        attachedEntry.Entity.LeadMaleActor = movie.LeadMaleActor;
                        attachedEntry.Entity.LeadFemaleActor = movie.LeadFemaleActor;
                    }
                    else
                    {
                        this.db.Movies.Attach(movie);
                        entry.State = EntityState.Modified;
                    }
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(movie);
        }