Esempio n. 1
0
        public void Thumb(string direction)
        {
            var getThumbResponse = SocketHelper.ExecuteRequest("getThumb;" + SelectedMovieReview.Id + ";" + LoggedInUser.UserId + ";" + direction);
            var thumb            = JsonConvert.DeserializeObject <Thumb>(getThumbResponse,
                                                                         new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            if (thumb == null)
            {
                var newThumb = new Thumb()
                {
                    ReviewId  = SelectedMovieReview.Id,
                    UserId    = LoggedInUser.UserId,
                    Direction = direction
                };

                var jsonThumbSerialized = JsonConvert.SerializeObject(newThumb, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                SocketHelper.ExecuteRequest("AddReviewThumb;" + jsonThumbSerialized);
            }
            else
            {
                SocketHelper.ExecuteRequest("DeleteReviewThumb;" + thumb.Id);
            }
        }
        public void Search()
        {
            var getMoviesResponse = SocketHelper.ExecuteRequest("getMovies");

            Movies = JsonConvert.DeserializeObject <List <Movie> >(getMoviesResponse,
                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            switch (SearchCriteria)
            {
            case "Genre":
            {
                if (!string.IsNullOrEmpty(SearchQuery))
                {
                    Movies = Movies.Where(x => x.Genre != null && x.Genre.ToLower().StartsWith(SearchQuery.ToLower())).ToList();
                }
                break;
            }

            case "Title":
            {
                if (!string.IsNullOrEmpty(SearchQuery))
                {
                    Movies = Movies.Where(x => x.Title.ToLower().StartsWith(SearchQuery.ToLower())).ToList();
                }
                break;
            }
            }
        }
Esempio n. 3
0
        public void UpdateUser()
        {
            var jsonUserSerialized = JsonConvert.SerializeObject(SelectedUser, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            SocketHelper.ExecuteRequest("updateUser;" + jsonUserSerialized);
        }
Esempio n. 4
0
        public void EditReview(string reviewContent)
        {
            if (MyReview != null)
            {
                MyReview.Content = reviewContent;

                var jsonReviewSerialized = JsonConvert.SerializeObject(MyReview, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                SocketHelper.ExecuteRequest("editMovieReview;" + jsonReviewSerialized);
            }
        }
        public Score RatingVisibilityTest()
        {
            if (SelectedMovie != null)
            {
                var getScoreResponse = SocketHelper.ExecuteRequest("getScore;" + SelectedMovie.Id + ";" + LoggedInUser.UserId);
                var score            = JsonConvert.DeserializeObject <Score>(getScoreResponse,
                                                                             new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                return(score);
            }
            return(null);
        }
Esempio n. 6
0
        public void AddReview(string reviewContent)
        {
            var newReview = new Review()
            {
                MovieId = _movieId,
                UserId  = LoggedInUser.UserId,
                Content = reviewContent
            };

            var jsonReviewSerialized = JsonConvert.SerializeObject(newReview, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            SocketHelper.ExecuteRequest("addMovieReview;" + jsonReviewSerialized);
        }
Esempio n. 7
0
        public void AddUser(string username, string password, string role)
        {
            User newUser = new User
            {
                Username = username,
                Password = password,
                Role     = role
            };

            var jsonUserSerialized = JsonConvert.SerializeObject(newUser, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            SocketHelper.ExecuteRequest("addUser;" + jsonUserSerialized);
        }
        public string GetLogInUserRole()
        {
            var data = SocketHelper.ExecuteRequest("login;" + UsernameValue + ";" + PasswordValue).Split(';');

            if (data.Length == 2)
            {
                int.TryParse(data[0], out int userId);

                LoggedInUser.UserId = userId;

                return(data[1]);
            }

            return(string.Empty);
        }
Esempio n. 9
0
        public void AddMovie(string title, string genre, string actors, string status)
        {
            Movie newMovie = new Movie
            {
                Title  = title,
                Genre  = genre,
                Actors = actors,
                Status = status
            };

            var jsonMovieSerialized = JsonConvert.SerializeObject(newMovie, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            SocketHelper.ExecuteRequest("addMovie;" + jsonMovieSerialized);
        }
Esempio n. 10
0
        public AdminViewModel()
        {
            var getMoviesResponse = SocketHelper.ExecuteRequest("getMovies");

            Movies = JsonConvert.DeserializeObject <List <Movie> >(getMoviesResponse,
                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            var getUsersResponse = SocketHelper.ExecuteRequest("getUsers");

            Users = JsonConvert.DeserializeObject <List <User> >(getUsersResponse,
                                                                 new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
        }
        public void SaveRating()
        {
            int.TryParse(SelectedRating, out int score);

            var jsonMovieSerialized = JsonConvert.SerializeObject(SelectedMovie, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            SocketHelper.ExecuteRequest("addScoreToMovie;" + jsonMovieSerialized + ";" + LoggedInUser.UserId + ";" + score);

            var getMoviesResponse = SocketHelper.ExecuteRequest("getMovies");

            Movies = JsonConvert.DeserializeObject <List <Movie> >(getMoviesResponse,
                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
        }
Esempio n. 12
0
        public ReviewViewModel(int movieId)
        {
            _movieId = movieId;

            var getReviewsResponse = SocketHelper.ExecuteRequest("getMovieReviews;" + _movieId);

            ReviewsList = JsonConvert.DeserializeObject <List <Review> >(getReviewsResponse,
                                                                         new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            var getMyReviewResponse = SocketHelper.ExecuteRequest("getReviewByMovieIdUserId;" + _movieId + ";" + LoggedInUser.UserId);

            MyReview = JsonConvert.DeserializeObject <Review>(getMyReviewResponse,
                                                              new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
        }
        public void AddFavoriteMovie()
        {
            var favorite = FavoriteMoviesList.FirstOrDefault(f => f.UserId == LoggedInUser.UserId && f.MovieId == SelectedMovie.Id);

            if (favorite == null)
            {
                var newFavorite = new Favorite()
                {
                    UserId     = LoggedInUser.UserId,
                    MovieId    = SelectedMovie.Id,
                    MovieTitle = SelectedMovie.Title
                };

                var jsonFavoriteSerialized = JsonConvert.SerializeObject(newFavorite, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                SocketHelper.ExecuteRequest("addFavoriteMovie;" + jsonFavoriteSerialized);
            }
        }
        public void AddWatchedMovie()
        {
            var watchedMovie = WatchedMoviesList.FirstOrDefault(w => w.UserId == LoggedInUser.UserId && w.MovieId == SelectedMovie.Id);

            if (watchedMovie == null)
            {
                var newWatchedMovie = new WatchedMovie()
                {
                    UserId     = LoggedInUser.UserId,
                    MovieId    = SelectedMovie.Id,
                    MovieTitle = SelectedMovie.Title
                };

                var jsonWatchedSerialized = JsonConvert.SerializeObject(newWatchedMovie, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                SocketHelper.ExecuteRequest("addWatchedMovie;" + jsonWatchedSerialized);
            }
        }
        public UserViewModel()
        {
            var getMoviesResponse = SocketHelper.ExecuteRequest("getMovies");

            Movies = JsonConvert.DeserializeObject <List <Movie> >(getMoviesResponse,
                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            var getFavoriteMoviesResponse = SocketHelper.ExecuteRequest("getFavoriteMovies;" + LoggedInUser.UserId);

            FavoriteMoviesList = JsonConvert.DeserializeObject <List <Favorite> >(getFavoriteMoviesResponse,
                                                                                  new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            var getWatchedMoviesResponse = SocketHelper.ExecuteRequest("getWatchedMovies;" + LoggedInUser.UserId);

            WatchedMoviesList = JsonConvert.DeserializeObject <List <WatchedMovie> >(getWatchedMoviesResponse,
                                                                                     new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
        }
        public string GetPersonalizedMovies()
        {
            var jsonWatchedSerialized = JsonConvert.SerializeObject(WatchedMoviesList, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            var getPersonalizedResponse = SocketHelper.ExecuteRequest("getPersonalizedMovies;" + jsonWatchedSerialized);

            var personalizedMovies = JsonConvert.DeserializeObject <List <Movie> >(getPersonalizedResponse,
                                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            string personalizedMoviesString = "";

            foreach (var movie in personalizedMovies)
            {
                personalizedMoviesString += movie.Title;
                personalizedMoviesString += "\n";
            }

            return(personalizedMoviesString);
        }
 public void RemoveWatchedMovie()
 {
     SocketHelper.ExecuteRequest("removeWatchedMovie;" + SelectedWatchedMovie.Id);
 }
Esempio n. 18
0
 public void DeleteMovie(int movieId)
 {
     SocketHelper.ExecuteRequest("deleteMovie;" + movieId);
 }
Esempio n. 19
0
 public void DeleteUser(int userId)
 {
     SocketHelper.ExecuteRequest("deleteUser;" + userId);
 }
 public void RemoveFavoriteMovie()
 {
     SocketHelper.ExecuteRequest("removeFavoriteMovie;" + SelectedFavoriteMovie.Id);
 }