Exemple #1
0
        public async Task <bool> UpdateStartedEpisode(EpisodeStartedDto episodeStarted, string showName)
        {
            var internalEpisode = _episodeStartedMapper.Map(episodeStarted);

            if (internalEpisode.WatchedPercentage < 98)
            {
                var showExist = await IsMediaExistInMongoDb(showName);

                if (showExist)
                {
                    //check if episode is started
                    var show = GetSeriesByTitle(showName);
                    internalEpisode.TmdbId   = int.Parse(show.Result[0].TmdbId);
                    internalEpisode.TvMazeId = int.Parse(show.Result[0].TvMazeId);
                    var isEpisodeStarted = await IsEpisodeStarted(internalEpisode);

                    if (isEpisodeStarted)
                    {
                        return(await _seriesRepository.UpdateStartedEpisode(internalEpisode));
                    }

                    //hozzáadjuk mint markepisode started
                    await MarkEpisodeStarted(internalEpisode, showName);

                    return(true);
                }
                //import sorozat
                await ImportSeries(showName);
                await MarkEpisodeStarted(internalEpisode, showName);

                return(true);
            }
            if (internalEpisode.TvMazeId != 0 && internalEpisode.TmdbId != 0)
            {
                await MarkAsSeen(1, internalEpisode.TvMazeId.ToString(), internalEpisode.TmdbId.ToString(),
                                 internalEpisode.SeasonNumber, internalEpisode.EpisodeNumber, showName);
            }
            return(false);
        }
Exemple #2
0
        public async Task <Result <bool> > UpdateStartedEpisode([FromBody] EpisodeStartedDto internalEpisode,
                                                                string showName)
        {
            try
            {
                //internalEpisode.TvMazeId == 0 && internalEpisode.TmdbId == 0 ||
                if (showName.Length == 0)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = (int)CoreCodes.MalformedRequest,
                        ResultMessage = "All of the fields must be filled up."
                    });
                }

                var update = await _seriesService.UpdateStartedEpisode(internalEpisode, showName);

                if (update)
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = (int)CoreCodes.EpisodeStartedUpdated,
                        ResultMessage = "Update was successful."
                    });
                }
            }
            catch (InternalException ex)
            {
                if (ex.ErrorCode == (int)CoreCodes.UpToDate)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotModified;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = ex.ErrorCode,
                        ResultMessage = ex.ErrorMessage
                    });
                }
                if (ex.ErrorCode == (int)CoreCodes.SeriesNotFound)
                {
                    Response.StatusCode = (int)CoreCodes.SeriesNotFound;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = ex.ErrorCode,
                        ResultMessage = ex.ErrorMessage
                    });
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(new Result <bool>
                {
                    Data = false,
                    ResultCode = (int)CoreCodes.CommonGenericError,
                    ResultMessage = "Common Generic Error -- " + ex.Message
                });
            }

            return(new Result <bool>
            {
                Data = true,
                ResultCode = (int)CoreCodes.EpisodeStartedNotUpdated,
                ResultMessage = "Update failed."
            });
        }
Exemple #3
0
 public async Task <bool> GetShow(EpisodeStartedDto episodeStarted, string title)
 {
     return(await _seriesRepository.GetShow(_episodeStartedMapper.Map(episodeStarted), title));
 }