コード例 #1
0
        public IActionResult CreateRate([FromBody] Entity.Rating rate)
        {
            try
            {
                _ratreRepository.Add(rate);
                _unitOfWork.SaveChanges();
                var result = new RatingResult <Entity.Rating>
                {
                    IsSuccess = true,
                    Message   = "Successfuly rated."
                };

                return(Ok(result));
            }
            catch (Exception ex)
            {
                // log
                var result = new RatingResult <Entity.Rating>
                {
                    IsSuccess = false,
                    Message   = ex.Message
                };

                return(StatusCode(500, result));
            }
        }
コード例 #2
0
        public async Task <IActionResult> AddMovie(AddMovieViewModel addMedia)
        {
            Media        media    = _context.Medias.SingleOrDefault(m => m.TmdbId == addMedia.TmdbId);
            List <Genre> dbGenres = _context.Genres.ToList();

            if (media == null)
            {
                MediaType mediaType = _context.MediaTypes.SingleOrDefault(m => m.Name == SpinningFilmHelper.MovieType);

                string responseBody = await _apiService.GetWithCreditsAsync(addMedia.TmdbId, SpinningFilmHelper.MovieType);

                TmdbMovieResult movieResult = JsonConvert.DeserializeObject <TmdbMovieResult>(responseBody);

                responseBody = await _apiService.GetOmdbResult(movieResult.ImdbId);

                RatingResult ratingResult = JsonConvert.DeserializeObject <RatingResult>(responseBody);

                media = new Media(movieResult, mediaType, ratingResult, movieResult.ImdbId);
                _context.Add(media);

                Movie movie = new Movie(movieResult, media.MediaId);
                _context.Add(movie);

                foreach (var item in movieResult.Genres)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == item.GenreId) ?? _context.Genres.Add(item).Entity;
                    MediaGenre mediaGenre = new MediaGenre(media.MediaId, genre);
                    _context.Add(mediaGenre);
                }

                movieResult.Credits.Cast.ForEach(c => c.MediaId = media.MediaId);
                _context.Casts.AddRange(movieResult.Credits.Cast);

                movieResult.Credits.Crew.ForEach(c => c.MediaId = media.MediaId);
                _context.Crews.AddRange(movieResult.Credits.Crew);

                _context.SaveChanges();
            }

            Guid userId = User.Identity.GetNameIdGuid();

            if (!_context.PhysicalMedias.Any(m => m.AppUserId == userId && m.MediaId == media.MediaId))
            {
                PhysicalMedia physicalMedia = new PhysicalMedia(media.MediaId, userId, (bool)addMedia.DigitalCopy, addMedia.DiscType);
                _context.PhysicalMedias.Add(physicalMedia);

                foreach (var genreId in addMedia.ExtraGenreIds)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == genreId);
                    ExtraGenre extraGenre = new ExtraGenre(physicalMedia.PhysicalMediaId, genre);
                    _context.Add(extraGenre);
                }

                _context.SaveChanges();

                return(View("AddMedia", media));
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #3
0
        public async Task <IActionResult> AddSeries(AddSeriesViewModel addSeries)
        {
            Media media = _context.Medias.SingleOrDefault(m => m.ImdbId == addSeries.ImdbId);

            if (media == null)
            {
                MediaType mediaType = _context.MediaTypes.SingleOrDefault(m => m.Name == SpinningFilmHelper.SeriesType);

                string responseBody = await _apiService.GetWithCreditsAsync(addSeries.TmdbId, SpinningFilmHelper.SeriesType);

                TmdbTVResult tvResult = JsonConvert.DeserializeObject <TmdbTVResult>(responseBody);

                responseBody = await _apiService.GetOmdbResult(addSeries.ImdbId);

                RatingResult ratingResult = JsonConvert.DeserializeObject <RatingResult>(responseBody);

                media = new Media(tvResult, mediaType, ratingResult, addSeries.ImdbId);
                _context.Add(media);

                Series series = new Series(tvResult, media.MediaId);
                _context.Add(series);

                List <Genre> dbGenres = _context.Genres.ToList();
                foreach (var item in tvResult.Genres)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == item.GenreId) ?? _context.Genres.Add(item).Entity;
                    MediaGenre mediaGenre = new MediaGenre(media.MediaId, genre);
                    _context.Add(mediaGenre);
                }

                tvResult.Credits.Cast.ForEach(c => c.MediaId = media.MediaId);
                _context.Casts.AddRange(tvResult.Credits.Cast);

                tvResult.Credits.Crew.ForEach(c => c.MediaId = media.MediaId);
                _context.Crews.AddRange(tvResult.Credits.Crew);

                _context.SaveChanges();
            }

            if (!_context.PhysicalMedias.Any(m => m.AppUserId == User.Identity.GetNameIdGuid() && m.MediaId == media.MediaId))
            {
                foreach (var number in addSeries.SeasonNumbers)
                {
                    var physicalMedia = addSeries.PhysicalMedias[number - 1];
                    physicalMedia.MediaId   = media.MediaId;
                    physicalMedia.AppUserId = User.Identity.GetNameIdGuid();
                    _context.PhysicalMedias.Add(physicalMedia);

                    PhysicalSeason physicalSeason = new PhysicalSeason(physicalMedia.PhysicalMediaId, number);
                    _context.PhysicalSeasons.Add(physicalSeason);
                }

                _context.SaveChanges();

                return(View("AddMedia", media));
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        public void It_should_return_valid_rating_result_from_cache()
        {
            string      rating         = "7.3";
            IFileSystem mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData> {
                { Path.Combine(Raticon.Constants.CommonApplicationDataPath, "Cache", "tt0061811.json"), new MockFileData("{'Rating':'" + rating + "'}") }
            });

            RatingResult result = ratingService.GetRatingWithCache("tt0061811", new MockHttpService(""), mockFileSystem);

            Assert.AreEqual <string>(result.Rating, rating);
        }
コード例 #5
0
ファイル: RatingService.cs プロジェクト: c-sharp-eg/Raticon
        public RatingResult GetRatingWithCache(string imdbId, IHttpService httpService, IFileSystem fileSystem)
        {
            RatingResult result = AttemptReadFromCache(imdbId, fileSystem);

            if (result == null)
            {
                result = base.GetRatingFromApi(imdbId, httpService);
                WriteResultToCache(imdbId, result, fileSystem);
            }
            return(result);
        }
コード例 #6
0
        public void It_should_get_a_rating_result()
        {
            RatingResult expectedResult = new RatingResult
            {
                Rating = "8.0",
                Title  = "In the Heat of the Night",
                Year   = "1967",
                Poster = @"http://ia.media-imdb.com/images/M/MV5BMTk3NjkxMDc1MV5BMl5BanBnXkFtZTcwMDIwMjI0NA@@._V1_SX300.jpg"
            };

            Assert.AreEqual(ratingService.GetRating("tt0061811", new MockHttpService(OmdbapiResult)), expectedResult);
        }
コード例 #7
0
 public Media(TmdbMovieResult media, MediaType mediaType, RatingResult rating, string imdbId)
 {
     MediaId     = Guid.NewGuid();
     MediaTypeId = mediaType.MediaTypeId;
     ImdbId      = imdbId;
     TmdbId      = media.TmdbId;
     Title       = media.Title;
     Poster      = media.Poster;
     ImdbRating  = rating.ImdbRating;
     Rated       = rating.Rated;
     Metascore   = rating.Metascore;
     PlotShort   = rating.Plot;
     PlotLong    = media.Plot;
 }
コード例 #8
0
 public RatingResult Compute(IList<RestaurantReview> reviews)
 {
     var revs = reviews.ToArray();
     var result = new RatingResult();
     var counter = 0;
     var total = 0;
     for (int i = 0; i < revs.Count(); i++)
     {
         if (i < revs.Count() / 2)
         {
             counter += 2;
             total += revs[i].Rating * 2;
         }
         else
         {
             counter += 1;
             total += revs[i].Rating;
         }
     }
     result.Rating = total / counter;
     return result;
 }
コード例 #9
0
        public IActionResult GetRating(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_entityIndex.Exists(ResourceType.Route, id))
            {
                return(NotFound(ErrorMessages.ContentNotFound(ResourceType.Route, id)));
            }

            var result = new RatingResult()
            {
                Id          = id,
                Average     = _ratingIndex.Average(ResourceType.Route, id),
                Count       = _ratingIndex.Count(ResourceType.Route, id),
                RatingTable = _ratingIndex.Table(ResourceType.Route, id)
            };

            return(Ok(result));
        }
コード例 #10
0
 public static RatingResult CreateRatingResult(int quantity, long entityKindId, string currency, double value)
 {
     RatingResult ratingResult = new RatingResult();
     ratingResult.Quantity = quantity;
     ratingResult.EntityKindId = entityKindId;
     ratingResult.Currency = currency;
     ratingResult.Value = value;
     return ratingResult;
 }
コード例 #11
0
 public RatingResult Compute(IList<RestaurantReview> reviews)
 {
     var result = new RatingResult();
     result.Rating = (int)reviews.Average(a => a.Rating);
     return result;
 }
コード例 #12
0
ファイル: RatingService.cs プロジェクト: c-sharp-eg/Raticon
        private void WriteResultToCache(string imdbId, RatingResult result, IFileSystem fileSystem)
        {
            string json = JsonConvert.SerializeObject(result, Formatting.Indented);

            fileSystem.File.WriteAllText(JsonCacheFilePath(imdbId, fileSystem), json);
        }