public static async Task <Result <bool> > UpdateStartedSeries(InternalStartedMovieUpdateRequest internalEpisode) { var isUpdated = await new WebClientManager().Post <Result <bool> >($"http://localhost:5003/movie/update", internalEpisode); return(isUpdated); }
public async Task <Result <bool> > UpdateStartedMovie([FromBody] InternalStartedMovieUpdateRequest requestModel) { try { if (requestModel.Title.Length == 0) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(new Result <bool> { Data = false, ResultCode = (int)CoreCodes.MalformedRequest, ResultMessage = "The title cannot be empty." }); } var result = await new MovieService().UpdateStartedMovie(requestModel); } catch (InternalException ex) { if (ex.ErrorCode == (int)CoreCodes.MovieNotFound) { Response.StatusCode = (int)CoreCodes.MovieNotFound; return(new Result <bool> { Data = false, ResultCode = ex.ErrorCode, ResultMessage = ex.ErrorMessage }); } if (ex.ErrorCode == (int)CoreCodes.AlreadySeen) { Response.StatusCode = (int)CoreCodes.AlreadySeen; 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.NoError, ResultMessage = "Update was successful." }); }
public async Task <Result <bool> > Post <T>(string url, InternalStartedMovieUpdateRequest body) { var c = new HttpClient(); var json = JsonConvert.SerializeObject(body); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var request = await c.PostAsync(new Uri(url), httpContent); var response = await request.Content.ReadAsStringAsync(); var res = JsonConvert.DeserializeObject <Result <bool> >(response); return(res); //return bool.TryParse(response, out var result); }
public async Task <bool> UpdateStartedMovie(InternalStartedMovieUpdateRequest model) { var updateDef = Builders <StartedMovie> .Update .Set(o => o.HoursElapsed, model.HoursElapsed) .Set(o => o.MinutesElapsed, model.MinutesElapsed) .Set(o => o.SecondsElapsed, model.SecondsElapsed) .Set(o => o.WatchedPercentage, model.WatchedPercentage) .Set(o => o.Date, model.Date); var s = await StartedMovies.UpdateOneAsync( started => started.ImdbId == model.ImdbId || started.TmdbId == model.TmdbId && started.UserId == model.UserId, updateDef); return(s.ModifiedCount == 1); }
public async Task <bool> UpdateStartedMovie(InternalStartedMovieUpdateRequest requestModel) { if (requestModel != null) { var mongoMovie = await _repo.GetMovieByTitle(requestModel.Title); if (mongoMovie != null) { //feltöltjük az üres ID-ket. requestModel.TmdbId = mongoMovie.TmdbId; requestModel.ImdbId = mongoMovie.ImdbId; //Megnézem, hogy láttuk -e már a filmet, mert ha igen akkor figyelmeztetem var isItSeen = await _repo.IsMovieSeen(mongoMovie, requestModel.UserId); if (!isItSeen) { //Létrehozom, hogy tudjuk jelölni mint elkezdett film és törölni is majd onnan. var startedMovie = new StartedMovie { Date = requestModel.Date, HoursElapsed = requestModel.HoursElapsed, ImdbId = requestModel.ImdbId, MinutesElapsed = requestModel.MinutesElapsed, SecondsElapsed = requestModel.SecondsElapsed, TmdbId = requestModel.TmdbId, UserId = requestModel.UserId, WatchedPercentage = requestModel.WatchedPercentage }; if (requestModel.WatchedPercentage < 95) { if (await IsMovieExistInMongoDb(requestModel.Title)) { //check if movie is started var isItStarted = await _repo.IsMovieStarted(requestModel.UserId, mongoMovie); if (isItStarted) { return(await _repo.UpdateStartedMovie(requestModel)); } return(await _repo.MarkAsStartedMovie(startedMovie)); } else { await Import(new InternalMovie { Title = requestModel.Title }); return(await _repo.UpdateStartedMovie(requestModel)); //throw new InternalException(650, "Movie not found in MONGODB."); } } //kitöröljük az elkezdett filmek közül await _repo.RemoveStartedMovie(startedMovie); //bejelöljük látottnak return(await _repo.MarkAsSeenMovie(mongoMovie, requestModel.UserId)); } throw new InternalException(606, "Movie already seen."); } throw new InternalException(650, "Movie not found by title in DB."); } return(false); }
public static async Task SavePosition(string showName, int actualSeenSecondsFromMPC, Times elapsedTimesInMedia) { //string positionPath = "(/html/body/p)[9]"; //string durationPath = "(/html/body/p)[11]"; //using (WebClient client = new WebClient()) //{ // string htmlString = client.DownloadString(mpcVariablesSiteUrl); // HtmlDocument htmlDocument = new HtmlDocument(); // htmlDocument.LoadHtml(htmlString); // HtmlNode position = htmlDocument.DocumentNode.SelectSingleNode(positionPath); // HtmlNode duration = htmlDocument.DocumentNode.SelectSingleNode(durationPath); // var pos = Regex.Split(position.InnerText, ":"); // var dur = Regex.Split(duration.InnerText, ":"); //double seenSeconds = Int32.Parse(pos[0]) * 60 * 60 + Int32.Parse(pos[1]) * 60 + Int32.Parse(pos[2]); //double totalSeconds = Int32.Parse(dur[0]) * 60 * 60 + Int32.Parse(dur[1]) * 60 + Int32.Parse(dur[2]); //double percentage = (100 / totalSeconds) * seenSeconds; var seenSeconds = 0.0; if (elapsedTimesInMedia != null) { seenSeconds = elapsedTimesInMedia.Position; } else { if (Math.Abs(actualSeenSecondsFromMPC - elapsedTimesInMedia.SeenSeconds) < 60) { seenSeconds = actualSeenSecondsFromMPC; } } var percentage = 100.0 / elapsedTimesInMedia.Duration * seenSeconds; InternalStartedMovieUpdateRequest startedMovie = new InternalStartedMovieUpdateRequest { Date = DateTime.Now, HoursElapsed = elapsedTimesInMedia.SeenHours, MinutesElapsed = elapsedTimesInMedia.SeenMinutes, SecondsElapsed = elapsedTimesInMedia.SeenSeconds, WatchedPercentage = percentage, ImdbId = "", Title = showName, TmdbId = null, UserId = 1 //TODO }; //ez megoldja azokat ami alább kivan kommentelve var updateResult = await UpdateStartedSeries(startedMovie); //if (percentage <= 98) //{ // await UpdateStartedSeries(startedMovie); //} //else //{ // await SeriesHelper.MarkRequest(new InternalMarkRequest() // { // //IDE HA LESZ FELHASZNÁLÓ KELL A USERID // //átküldés után lekell kérni a showt névszerint // UserId = 1, // TvMazeId = "", // TmdbId = "", // ShowName = showName, // EpisodeNumber = episodeNum, // SeasonNumber = seasonNum // }); //} //} }