Ejemplo n.º 1
0
 public HomeViewModel()
 {
     NowPlayingMovies = new MoviesDTO();
     UpcomingMovies   = new MoviesDTO();
     TopRatedMovies   = new MoviesDTO();
     PopularMovies    = new MoviesDTO();
 }
Ejemplo n.º 2
0
        public async Task <string> GetMovieList()
        {
            var    cacheKey = "MovieList";
            string jsonStr;

            if (_memCacheService.CacheHit(cacheKey))
            {
                _logger.LogInformation("*******************cache hit list from service;");
                string resultStr = _memCacheService.GetValue(cacheKey);
                return(resultStr);
            }
            else
            {
                var resultFW = await _cinemaWorldAPIService.AsycGetMovieList();

                var resultCW = await _filmWorldAPIService.AsycGetMovieList();

                var resultCollection = _movieAPIUtilService.MergeAndProcessResults(resultFW, resultCW);
                if (resultCollection.Any())
                {
                    MoviesDTO resultObj = new MoviesDTO
                    {
                        Movies = resultCollection.ToList()
                    };
                    jsonStr = JsonConvert.SerializeObject(resultObj);
                    _memCacheService.SetValueWithExpire(jsonStr, cacheKey, TimeSpan.FromMinutes(30));
                    return(jsonStr);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
 public MoviesVM(MoviesDTO model)
 {
     Id       = model.Id;
     Name     = model.Name;
     Category = model.Category;
     Genre    = model.Genre;
     Year     = model.Year;
     Language = model.Language;
     //  ImagePath = model.ImagePath;
 }
Ejemplo n.º 4
0
 public ActionResult DeleteMovie(int id)
 {
     using (Db db = new Db())
     {
         MoviesDTO dto = db.Movie.Find(id);
         db.Movie.Remove(dto);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 5
0
 public async Task <ActionResult <MoviesDTO> > AddMovie(MoviesDTO movie)
 {
     try
     {
         return(new OkObjectResult(await _movieService.AddMovie(movie)));
     }
     catch (System.Exception ex)
     {
         return(new StatusCodeResult(500));
     }
 }
Ejemplo n.º 6
0
        public void UpdateMovie(int id, MoviesDTO moviesDTO)
        {
            var movieToBeUpdated = _context.Movies.Single(m => m.Id == id);

            if (movieToBeUpdated == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Mapper.Map(moviesDTO, movieToBeUpdated);
            _context.SaveChanges();
        }
Ejemplo n.º 7
0
 public MovieDTO GetMovie(int id)
 {
     try
     {
         return(MoviesDTO.First(mv => mv.Id == id));
     }
     catch (Exception)
     {
         // todo : Log off the error
         return(null);
     }
 }
Ejemplo n.º 8
0
        public IHttpActionResult CreateMovie(MoviesDTO moviesDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var movie = Mapper.Map <MoviesDTO, Movie>(moviesDTO);

            _context.Movies.Add(movie);
            _context.SaveChanges();
            moviesDTO.ID = movie.ID;
            return(Created(new Uri(Request.RequestUri + "/" + moviesDTO.ID), moviesDTO));
        }
Ejemplo n.º 9
0
        public async Task <MoviesDTO> AddMovie(MoviesDTO Movie)
        {
            try
            {
                Movies newMovie = _mapper.Map <Movies>(Movie);
                await _movieRepository.AddMovie(newMovie);

                return(Movie);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 10
0
        public void UpdateMovie(int id, MoviesDTO moviesDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var movieInDb = _context.Movies.SingleOrDefault(c => c.Id == id);

            if (movieInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            Mapper.Map(moviesDto, movieInDb);

            _context.SaveChanges();
        }
Ejemplo n.º 11
0
        public IHttpActionResult EditMovie(int id, MoviesDTO moviesDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var movieInDb = _context.Movies.SingleOrDefault(m => m.Id == id);

            if (movieInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(moviesDTO, movieInDb);

            return(Created(new Uri(Request.RequestUri + "/" + movieInDb.Id), movieInDb));
        }
Ejemplo n.º 12
0
        public IHttpActionResult UpdateMovie(int id, MoviesDTO movieDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var movieInDb = _context.Movies.SingleOrDefault(c => c.Id == id);

            if (movieInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(movieDto, movieInDb);

            _context.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 13
0
        public ActionResult AddMovie(MoviesVM model)
        {
            MoviesDTO dto = new MoviesDTO();



            using (Db db = new Db())
            {
                ViewBag.Category = new SelectList(db.Category, "Id", "Name");

                dto.Name = model.Name;
                if (db.Movie.Any(x => x.Name == model.Name))
                {
                    ModelState.AddModelError("", "The title already taken");
                    return(View(model));
                }
                string yr = model.Year.ToString();
                if (string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrWhiteSpace(model.Language) || string.IsNullOrWhiteSpace(model.Category) || string.IsNullOrWhiteSpace(model.Genre) || string.IsNullOrWhiteSpace(yr))
                {
                    ModelState.AddModelError("", "All fields required");
                    return(View(model));
                }
                dto.Category = model.Category;
                dto.Genre    = model.Genre;
                dto.Year     = model.Year;
                dto.Language = model.Language;
                db.Movie.Add(dto);
                db.SaveChanges();



                //temp data
                TempData["SM"] = "Movie Added!";
            }

            return(RedirectToAction("Index"));
        }