Ejemplo n.º 1
0
        public static List <Dictionary <string, object> > list(int commentId)
        {
            MovieEntities movieEntities = new MovieEntities();
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            var feedbacks = movieEntities.Feedback.Where(f => f.comment_id == commentId).Where(f => f.reply_id == 0);

            foreach (var fb in feedbacks)
            {
                User user = new MovieEntities().User.Where(u => u.id == fb.user_id).FirstOrDefault();
                User at   = fb.at_id == 0 ? null : new MovieEntities().User.Where(u => u.id == fb.at_id).FirstOrDefault();
                var  f    = ClassToDictionary.classToDictionary(fb);
                f.Add("username", user.name);
                f.Add("at_username", at == null ? null : at.name);
                LinkedList <Dictionary <string, object> > replies = new LinkedList <Dictionary <string, object> >();
                foreach (var subfb in new MovieEntities().Feedback.Where(sf => sf.reply_id == fb.id))
                {
                    var subf = ClassToDictionary.classToDictionary(subfb);
                    subf.Add("username", new MovieEntities().User.Where(u => u.id == subfb.user_id).FirstOrDefault().name);
                    subf.Add("at_username", new MovieEntities().User.Where(u => u.id == subfb.at_id).FirstOrDefault().name);
                    replies.AddLast(subf);
                }
                f.Add("replies", replies);
                result.AddLast(f);
            }
            return(result.Reverse().ToList());
        }
Ejemplo n.º 2
0
        public static Dictionary <string, object> getUserInfo(int id)
        {
            MovieEntities movieEntities = new MovieEntities();
            User          user          = movieEntities.User.Where(u => u.id == id).FirstOrDefault();

            return(ClassToDictionary.classToDictionary(user));
        }
Ejemplo n.º 3
0
        public static LinkedList <Dictionary <string, object> > fuzzySearch(string param)
        {
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            var movies = new MovieEntities().Movie.Where(m => m.name.Contains(param) || m.genres.Contains(param) || m.regions.Contains(param) || m.directors.Contains(param) || m.stars.Contains(param));

            foreach (var movie in movies)
            {
                result.AddLast(ClassToDictionary.movieToDictionary(movie));
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static LinkedList <Dictionary <string, object> > exactSearch(string name, string genre, string region, string director, string star)
        {
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            var movies = new MovieEntities().Movie.Where(m => m.name.Contains(name) && m.genres.Contains(genre) && m.regions.Contains(region) && m.stars.Contains(director) && m.directors.Contains(star));

            foreach (var movie in movies)
            {
                result.AddLast(ClassToDictionary.movieToDictionary(movie));
            }
            return(result);
        }
Ejemplo n.º 5
0
        public static LinkedList <Dictionary <string, object> > list(int movieId)
        {
            MovieEntities movieEntities = new MovieEntities();
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            var records = movieEntities.Record.Where(r => r.movie_id == movieId);

            foreach (var r in records)
            {
                Dictionary <string, object> temp = ClassToDictionary.classToDictionary(r);
                temp.Add("username", new MovieEntities().User.Where(u => u.id == r.user_id).FirstOrDefault().name);
                result.AddLast(temp);
            }
            return(result);
        }
Ejemplo n.º 6
0
        public static Dictionary <string, object> reply(int commentId, int atId, string content, int replyId)
        {
            MovieEntities movieEntities = new MovieEntities();
            int           userId        = SessionService.getSession();
            Feedback      feedback      = new Feedback();

            feedback.comment_id = commentId;
            feedback.user_id    = userId;
            feedback.at_id      = atId;
            feedback.reply_id   = replyId;
            feedback.content    = content;
            feedback.time       = DateTime.Now;
            movieEntities.Feedback.Add(feedback);
            movieEntities.SaveChanges();
            return(ClassToDictionary.classToDictionary(feedback));
        }
Ejemplo n.º 7
0
        public static LinkedList <Dictionary <string, object> > list(int movieId)
        {
            MovieEntities movieEntities = new MovieEntities();
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            var comments  = movieEntities.Comment.Where(c => c.movie_id == movieId);
            var movieName = new MovieEntities().Movie.Where(m => m.id == movieId).FirstOrDefault().name;

            foreach (var c in comments)
            {
                User user = new MovieEntities().User.Where(u => u.id == c.user_id).FirstOrDefault();
                Dictionary <string, object> comment = ClassToDictionary.classToDictionary(c);
                comment.Add("username", user.name);
                comment.Add("email", user.email);
                comment.Add("movieName", movieName);
                result.AddLast(comment);
            }
            return(result);
        }
Ejemplo n.º 8
0
        public static Dictionary <string, object> upload(int movieId, string title, string intro, string cover, string content)
        {
            int           userId        = SessionService.getSession();
            MovieEntities movieEntities = new MovieEntities();
            Comment       comment       = new Comment();

            comment.movie_id = movieId;
            comment.user_id  = userId;
            comment.title    = title;
            comment.intro    = intro;
            comment.cover    = cover;
            comment.content  = content;
            comment.likes    = 0;
            comment.comments = 0;
            comment.time     = DateTime.Now;
            movieEntities.Comment.Add(comment);
            movieEntities.SaveChanges();
            return(ClassToDictionary.classToDictionary(comment));
        }
Ejemplo n.º 9
0
        public static LinkedList <Dictionary <string, object> > listByPage(int page)
        {
            MovieEntities movieEntities = new MovieEntities();
            LinkedList <Dictionary <string, object> > result = new LinkedList <Dictionary <string, object> >();
            Array comments = movieEntities.Comment.ToArray();
            int   size     = comments.Length;
            //foreach (var comment in comments)
            //    size++;
            int start = page * 6;
            int end   = (page + 1) * 6;

            if (size < start)
            {
                return(null);
            }
            else if (size >= start && size < end)
            {
                for (int i = start; i < size; i++)
                {
                    Comment comment = (Comment)comments.GetValue(index: i);
                    User    user    = new MovieEntities().User.Where(u => u.id == comment.user_id).FirstOrDefault();
                    Movie   movie   = new MovieEntities().Movie.Where(m => m.id == comment.movie_id).FirstOrDefault();
                    var     temp    = ClassToDictionary.classToDictionary(comment);
                    temp.Add("username", user.name);
                    temp.Add("email", user.email);
                    temp.Add("movieName", movie.name);
                    result.AddLast(temp);
                }
                return(result);
            }
            else
            {
                for (int i = start; i < end; i++)
                {
                    result.AddLast(ClassToDictionary.classToDictionary(comments.GetValue(i)));
                }
                return(result);
            }
        }