Example #1
0
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "MarkAsWatchedOrUnwatched")
            {
                if (IsGameRunning())
                {
                    var userId  = User.Identity.Name;
                    int movieId = int.Parse((e.CommandArgument).ToString());


                    var watchedMovieService = GetBuisnessService <IWatchedMovieService>();
                    var movieService        = GetBuisnessService <IMovieService>();
                    if (watchedMovieService.GetUserWatchedEntity(userId) == null)
                    {
                        var watchedEntity = new Watched()
                        {
                            UserId = userId, Movies = new List <Movie>()
                        };
                        watchedEntity = watchedMovieService.AddWatchedEntity(watchedEntity);
                    }

                    movieService.ChangeMovieStatus(userId, movieId);
                    Repeater1.DataBind();
                    System.Threading.Thread.Sleep(500);
                }
                else
                {
                    Response.Redirect("ShowAllDBMovies.aspx");
                }
            }
        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "MarkAsWatchedOrUnwatched")
            {
                if (CanEdit())
                {
                    int movieId = int.Parse((e.CommandArgument).ToString());

                    if (WatchedMovieService.GetUserWatchedEntity(CurrentUsereId) == null)
                    {
                        var watchedEntity = new Watched()
                        {
                            UserId = CurrentUsereId, Movies = new List <Movie>()
                        };
                        WatchedMovieService.AddWatchedEntity(watchedEntity);
                    }

                    MovieService.ChangeMovieStatus(CurrentUsereId, movieId);
                    Repeater1.DataBind();
                    System.Threading.Thread.Sleep(500);
                }
                else
                {
                    Response.Redirect("ShowAllDBMovies.aspx");
                }
            }
        }
Example #3
0
 public void UnWatchVariable(ConfigurationItemModel item)
 {
     if (Watched.Any(x => x.Parent == item.Parent && x.Connector == item.Connector))
     {
         Watched.Remove(item);
     }
     OnPropertyChanged("Watched");
 }
Example #4
0
        public Watched AddWatchedEntity(Watched watchedEntity)
        {
            using (var ctx = new MovieContext())
            {
                watchedEntity = ctx.Watched.Add(watchedEntity);
                ctx.SaveChanges();
            }

            return(watchedEntity);
        }
Example #5
0
        public void EndTransmission()
        {
            var watched = new Watched<string>();

            var onCompletedCalled = false;

            watched.OnCompleted += (sender, e) => onCompletedCalled = true;

            watched.EndTransmission();

            Assert.IsTrue(onCompletedCalled);
        }
Example #6
0
        public void Send_Errors_When_String_Is_Null()
        {
            var watched = new Watched<string>();

            var wasErrorCalled = false;

            watched.OnError += (sender, e) => wasErrorCalled = true;

            watched.Send(null);

            Assert.IsTrue(wasErrorCalled);
        }
Example #7
0
        public void Send()
        {
            var watched = new Watched<string>();

            var onNextCalled = false;

            watched.OnNext += (sender, e) => onNextCalled = true;

            watched.Send("something");

            Assert.IsTrue(onNextCalled);
        }
Example #8
0
        public void Send_Multiple_Messages()
        {
            var watched = new Watched<string>();

            var callCount = 0;

            watched.OnNext += (sender, e) => callCount ++;

            watched.Send("something");
            watched.Send("something else");

            Assert.AreEqual(2, callCount);
        }
Example #9
0
        public void EndTransmission()
        {
            var mockery = new MockRepository();
            var subscriber = mockery.StrictMock<IObserver<string>>();

            var watched = new Watched();

            using (mockery.Record()) {
                subscriber.OnCompleted();
            }

            using (mockery.Playback())
            using (var unsubscriber = watched.Subscribe(subscriber)) {
                watched.EndTransmission();
            }
        }
Example #10
0
        public void Send()
        {
            var mockery = new MockRepository();
            var subscriber = mockery.StrictMock<IObserver<string>>();

            var message = "test message";

            var watched = new Watched();

            using (mockery.Record()) {
                subscriber.OnNext(message);
            }

            using (mockery.Playback())
            using (var unsubscriber = watched.Subscribe(subscriber)) {
                watched.Send(message);
            }
        }
Example #11
0
        public void AddWatchedEntity_ShouldCallWatchedMovieRepositoryMockOnce_WhenTheCorrectRepositoryIsPassed()
        {
            var watchedMovieRepositoryMock = MockRepository.GenerateMock <IWatchedMovieRepository>();
            var watched = new Watched {
                UserId = "test", Movies = new List <Movie>()
            };

            //Arrange
            watchedMovieRepositoryMock.Expect(dao => dao.AddWatchedEntity(Arg <Watched> .Is.Anything)).Return(Arg <Watched> .Is.Anything).Repeat.Once();
            var date = DateTime.Now;

            var watchedMovieService = new WatchedMovieService(watchedMovieRepositoryMock);

            //Act
            watchedMovieService.AddWatchedEntity(watched);

            //Assert
            watchedMovieRepositoryMock.VerifyAllExpectations();
        }
        //save a movie to watchedlist an if exist in the watchList remove it from there
        public async Task <ActionResult> SaveToWatchedList(int id)
        {
            MovieDetailViewModel movie = new MovieDetailViewModel();
            var baseAddress            = new Uri("https://api.themoviedb.org/3/");

            using (var httpClient = new HttpClient {
                BaseAddress = baseAddress
            })
            {
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
                using (var response = await httpClient.GetAsync($"movie/{id}?api_key=0ac277c3f170caa0df815398709d9bb2&language=hu-BR"))
                {
                    string jsonFile = await response.Content.ReadAsStringAsync();

                    movie = JsonConvert.DeserializeObject <MovieDetailViewModel>(jsonFile);
                }
            }
            int       actualUser     = (int)Session["userId"];
            Watched   myWatchedMovie = new Watched();
            Watchlist myOldMovie     = new Watchlist();
            var       myMovieList    = db.Watched.Where(m => m.UserId == actualUser).Select(m => m.MovieId).ToList();
            var       myOldMovieList = db.Watchlist.Where(m => m.UserID == actualUser).Select(m => m.MovieId).ToList();

            if (!myMovieList.Contains(movie.Id))
            {
                myWatchedMovie.MovieId     = movie.Id;
                myWatchedMovie.ImgPath     = movie.Poster_path;
                myWatchedMovie.UserId      = actualUser;
                myWatchedMovie.Title       = movie.Title;
                myWatchedMovie.ReleaseDate = movie.Release_date;
                myWatchedMovie.Runtime     = movie.Runtime;
                db.Watched.Add(myWatchedMovie);
                db.SaveChanges();
            }
            if (myOldMovieList.Contains(movie.Id))
            {
                myOldMovie = db.Watchlist.Where(m => m.MovieId == movie.Id).FirstOrDefault();
                db.Watchlist.Remove(myOldMovie);
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Watchlist", new { search = movie.Id }));
        }
Example #13
0
        public void Send_Errors_When_String_Is_Null()
        {
            var mockery = new MockRepository();
            var subscriber = mockery.StrictMock<IObserver<string>>();

            string message = null;

            var watched = new Watched();

            using (mockery.Record()) {
                subscriber.OnError(new Exception());
                LastCall.Constraints(Is.TypeOf(typeof(ArgumentNullException))
                    && Property.Value("Message", "Unable to process null strings" + Environment.NewLine +"Parameter name: message"));
            }

            using (mockery.Playback())
            using (var unsubscriber = watched.Subscribe(subscriber)) {
                watched.Send(message);
            }
        }
Example #14
0
        public async Task <WatchedViewModel> AddWatched(PhysicalMedia physicalMedia, DateTime dateWatched)
        {
            physicalMedia.Watched = true;
            await _physicalMediaRepository.UpdateAsync(physicalMedia);

            Watched watched = new Watched
            {
                WatchedId       = Guid.NewGuid(),
                PhysicalMediaId = physicalMedia.PhysicalMediaId,
                Date            = dateWatched
            };

            await _watchedRepository.AddAsync(watched);

            var watchedList = await _watchedRepository.ListAsync(new WatchedSpecification(physicalMedia.PhysicalMediaId));

            return(new WatchedViewModel {
                Count = watchedList.Count, LastWatched = watchedList.Max(w => w.Date).ToString("MM/dd/yyyy")
            });
        }
Example #15
0
        public static Movie ToMovie(MoviePostModel movie)
        {   // action, comedy, horror, thriller }
            Genre genre = Model.Genre.action;

            if (movie.Genre == "comedy")
            {
                genre = Model.Genre.comedy;
            }
            else if (movie.Genre == "horror")
            {
                genre = Model.Genre.horror;
            }
            else if (movie.Genre == "thriller")
            {
                genre = Model.Genre.thriller;
            }

            Watched watched = Model.Watched.no;

            if (movie.watched == "yes")
            {
                watched = Model.Watched.yes;
            }

            return(new Movie
            {
                Title = movie.Title,
                Description = movie.Description,

                Genre = genre,
                Duration = movie.Duration,
                YearRelease = movie.YearRelease,
                Director = movie.Director,
                DateAdded = movie.DateAdded,
                Rating = movie.Rating,
                watched = watched,
                Comments = movie.Comments
            });
        }
Example #16
0
        public bool InsertWatched(Watched w)
        {
            using (SqlConnection con = new SqlConnection(DbHelper.ConnectionString))
            {
                SqlCommand com = new SqlCommand("Logic.usp_Watched_Insert", con);
                com.CommandType = System.Data.CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@UserId", w.UserId);
                com.Parameters.AddWithValue("@MovieId", w.MovieId);

                try
                {
                    con.Open();
                    com.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception e)
                {
                    Error.AppErrorRepo.InsertError(e, w.UserId);
                    return(false);
                }
            }
        }
Example #17
0
        public static Movie ToMovie(MoviePostModel movie)
        {
            Genre movieGenre = Genre.Action;

            if (movie.MovieGenre == "Comedy")
            {
                movieGenre = Genre.Comedy;
            }
            else if (movie.MovieGenre == "Horror")
            {
                movieGenre = Genre.Horror;
            }
            else if (movie.MovieGenre == "Crime")
            {
                movieGenre = Genre.Crime;
            }

            Watched watched = Watched.No;

            if (movie.WasWatched == "YES")
            {
                watched = Watched.Yes;
            }

            return(new Movie
            {
                Title = movie.Title,
                Description = movie.Description,
                MovieGenre = movieGenre,
                DurationInMinutes = movie.DurationInMinutes,
                ReleaseYear = movie.ReleaseYear,
                Director = movie.Director,
                DateAdded = movie.DateAdded,
                Rating = movie.Rating,
                WasWatched = watched,
                Comment = movie.Comments
            });
        }
Example #18
0
        public MovieModel GetMovieById(string movieId, int userId)
        {
            MovieModel momvie = new MovieModel();

            try
            {
                HttpClient httpClient = new HttpClient();
                string     body       = httpClient.GetStringAsync(APIQueries.SearchByMovieId_Query(movieId)).Result;
                momvie = JsonConvert.DeserializeObject <MovieModel>(body);

                Watched w = _movSrv.GetMovie(momvie.id.ToString(), userId);
                if (w != null)
                {
                    momvie.IsWatchedByUser = true;
                    momvie.DateWatched     = w.DateCreated;
                }
            }
            catch (Exception ex)
            {
                AppErrorRepo.InsertError(ex);
            }

            return(momvie);
        }
Example #19
0
 public bool InsertWatched(Watched w)
 {
     return(_r.InsertWatched(w));
 }
Example #20
0
 public bool RemoveWatched(Watched w)
 {
     return(_r.RemoveWatched(w));
 }
 public Watched AddWatchedEntity(Watched watchedEntity)
 {
     return(_unitOfWork.WatchedMovieRepository.AddWatchedEntity(watchedEntity));
 }
Example #22
0
 public bool RemoveWatched([FromBody] Watched watched)
 {
     return(_watched.RemoveWatched(watched));
 }
Example #23
0
 public bool InsertWatched([FromBody] Watched watched)
 {
     return(_watched.InsertWatched(watched));
 }
Example #24
0
        public IEnumerator <T> GetEnumerator()
        {
            Watcher.Notify(Name + " enumeration");

            return(Watched.GetEnumerator());
        }
Example #25
0
        public void ToggleWatched(string target = null)
        {
            if (target != null)
            {
                Watched = (target == "watched" ? "true" : "false");
            }
            else
            {
                Watched = (Watched == "true" ? "false" : "true");
            }

            // load nfo file
            XmlDocument nfo = new XmlDocument();

            try
            {
                nfo.Load(File_nfo);
            }
            catch (Exception)
            {
                return;
            }

            // create iswatched node if it doesn't exist; save new watched status
            XmlNode nfoIsWatched = nfo.SelectSingleNode("//movie/iswatched");

            if (nfoIsWatched == null)
            {
                nfoIsWatched = nfo.SelectSingleNode("//movie").AppendChild(nfo.CreateElement("iswatched"));
            }
            nfoIsWatched.InnerText = Watched.ToString().ToLower();

            // if watched == true: create, set, and add lastwatched node; else remove node
            LastWatched = DateTime.Now;
            XmlNode nfoLastWatched = nfo.SelectSingleNode("//movie/lastwatched");

            if (Watched == "true")
            {
                if (nfoLastWatched == null)
                {
                    nfoLastWatched = nfo.SelectSingleNode("//movie").AppendChild(nfo.CreateElement("lastwatched"));
                }
                LastWatchedString        = LastWatched.Value.ToString("d");
                nfoLastWatched.InnerText = LastWatchedString;
            }
            else
            {
                if (nfoLastWatched != null)
                {
                    nfo.SelectSingleNode("//movie").RemoveChild(nfoLastWatched);
                }
                LastWatched       = null;
                LastWatchedString = null;
            }

            nfo.Save(File_nfo);

            NotifyPropertyChanged("Watched");
            NotifyPropertyChanged("LastWatched");
            NotifyPropertyChanged("LastWatchedString");
            NotifyPropertyChanged("WatchedToggleText");
            NotifyPropertyChanged("WatchedIcon");
            NotifyPropertyChanged("WatchedButton");
            NotifyPropertyChanged("WatchedContextIcon");
        }