Esempio n. 1
0
        public static async Task <bool> IsItStarted(int userid, string title)
        {
            var requestbody = new InternalMovieSeenRequest {
                UserId = userid, Title = title
            };
            var showExist =
                await new WebClientManager().SeenMovie <bool>($"http://localhost:5003/movie/started", requestbody);

            return(showExist);
        }
Esempio n. 2
0
        public async Task <bool> SeenMovie <T>(string url, InternalMovieSeenRequest 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.Data);
            //return bool.TryParse(response, out var result);
        }
Esempio n. 3
0
        public async Task <bool> IsMovieSeen(InternalMovieSeenRequest model)
        {
            var movieIfExist = await _repo.GetMovieByTitle(model.Title);

            if (movieIfExist != null)
            {
                var movie = new MongoMovie
                {
                    TmdbId = movieIfExist.TmdbId,
                    ImdbId = movieIfExist.ImdbId
                };
                var result = await _repo.IsMovieSeen(movie, model.UserId);

                return(result);
            }
            throw new InternalException(650, "Movie not found");
        }
Esempio n. 4
0
        public async Task <Result <bool> > MarkMovieSeen([FromBody] InternalMovieSeenRequest requestModel)
        {
            try
            {
                if (requestModel.Title == "" || requestModel.UserId == 0)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = (int)CoreCodes.MalformedRequest,
                        ResultMessage = "Bad input requests."
                    });
                }

                await new MovieService().MarkAsSeenMovie(requestModel.Title, requestModel.UserId);
            }
            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
                    });
                }
            }


            return(new Result <bool>
            {
                Data = true,
                ResultCode = (int)CoreCodes.NoError,
                ResultMessage = "Movie is marked."
            });
        }
Esempio n. 5
0
        public async Task <Result <bool> > IsMovieStarted([FromBody] InternalMovieSeenRequest requestModel)
        {
            try
            {
                if (requestModel.UserId == 0 || requestModel.Title == "")
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(new Result <bool>
                    {
                        Data = false,
                        ResultCode = (int)CoreCodes.MalformedRequest,
                        ResultMessage = "Wrong input."
                    });
                }

                var result = await new MovieService().IsMovieStarted(requestModel);
                if (result)
                {
                    return new Result <bool>
                           {
                               Data          = true,
                               ResultCode    = (int)CoreCodes.NoError,
                               ResultMessage = "Movie is started."
                           }
                }
                ;
            }
            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.AlreadyStarted)
                {
                    Response.StatusCode = (int)CoreCodes.AlreadyStarted;

                    return(new Result <bool>
                    {
                        Data = true,
                        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 = false,
                ResultCode = (int)CoreCodes.MovieNotStarted,
                ResultMessage = "Movie is not started."
            });
        }