public List<Review> GetMovieCommentary(int id)
 {
     using (var ctx = new DatabaseContext())
     {
         return ctx.Review.Include("USER").Where(x => x.MovieId == id).ToList();
     }
 }
        public List<Movie> GetTopTenWorstMovies()
        {
            using (var ctx = new DatabaseContext())
            {
                var bests = (from r in ctx.Review
                             group r by r.MovieId into groupIds
                             select new { groupIds.Key, Average = groupIds.Sum(x => x.Note) / groupIds.Count() })
                             .OrderByDescending(x => x.Average)
                             .Take(10)
                             .ToList();

                var worst = (from r in ctx.Review
                             group r by r.MovieId into groupIds
                             select new { groupIds.Key, Average = groupIds.Sum(x => x.Note) / groupIds.Count() })
                             .ToList()
                             .Where(r => !bests.Any(y => y.Key == r.Key))
                             .OrderBy(x => x.Average)
                             .Take(10)
                             .ToList();

                var listWorst = new List<Movie>();
                foreach (var movie in worst)
                    listWorst.Add(GetById(movie.Key));

                return listWorst;
            }
        }
 public void InsertMovie(Int32 movieId, User user)
 {
     using (var ctx = new DatabaseContext())
     {
         user = ctx.User.Where(x => x.Email.ToLower().Equals(user.Email.ToLower())).FirstOrDefault();
         ctx.UserCollection.Add(new UserCollection() { User = user, MovieId = movieId });
         ctx.SaveChanges();
     }
 }
 public void InsertMovieCommentary(User user, int movieId, int rate, string comment)
 {
     using (var ctx = new DatabaseContext())
     {
         user = ctx.User.Where(x => x.Email.ToLower().Equals(user.Email.ToLower())).FirstOrDefault();
         ctx.Review.Add(new Review() { User = user, MovieId = movieId, Note = rate, Commentary = comment, ReviewDate = DateTime.Now });
         ctx.SaveChanges();
     }
 }
        public bool Insert(User user)
        {
            using (var ctx = new DatabaseContext())
            {
                ctx.User.Add(user);
                int result = ctx.SaveChanges();

                return result >= 1;
            }
        }
        public User FindByEmail(String login)
        {
            using (var ctx = new DatabaseContext())
            {
                var u = ctx.User
                    .Where(x => x.Email.ToLower().Equals(login.ToLower()))
                    .FirstOrDefault();

                return u;
            }
        }
        public User Find(User user)
        {
            using (var ctx = new DatabaseContext())
            {
                var u = ctx.User
                    .Where(x => x.Email.ToLower().Equals(user.Email.ToLower()) && x.Password.Equals(user.Password))
                    .FirstOrDefault();

                return u;
            }
        }
        public List<Movie> ListFromUser(User user)
        {
            using (var ctx = new DatabaseContext())
            {
                var userMovies = ctx.UserCollection.Where(x => x.User.Id.Equals(user.Id)).ToList();

                if (userMovies == null)
                    throw new Exception("Erro ao consultar sua coleção.");

                var listMovies = new List<Movie>();
                foreach (UserCollection movieUser in userMovies)
                {
                    var movie = MovieServiceFacade.Instance.GetById(movieUser.MovieId);
                    listMovies.Add(movie);
                }

                return listMovies;
            }
        }
        public void RemoveMovieFromUser(int id, User user)
        {
            using (var ctx = new DatabaseContext())
            {
                var item = ctx.UserCollection.Where(x => x.User.Id == user.Id && x.MovieId == id).FirstOrDefault();

                if (item == null)
                    throw new MovieRepositoryException("Filme não encontrado na lista.");

                ctx.UserCollection.Remove(item);
                ctx.SaveChanges();
            }
        }
Exemple #10
0
 protected ManagerBase(string connectionString)
 {
     _database = new DatabaseContext(connectionString);
 }
Exemple #11
0
 public LocalizationManager(DAL.DatabaseContext database, ILogger logger)
 {
     _database = database;
     _logger   = logger;
 }