Beispiel #1
0
        private static Response HomeResponse(HomeRequest HomeRequest)
        {
            //request SQL DataBase
            DatabaseManager database = new DatabaseManager();

            (MySqlDataReader reader, var Connection) = database.RunQuery("SELECT duration, thumbnail, title, videoid FROM video_details ORDER BY lastupdatedon DESC LIMIT 20");
            if (reader != null)
            {
                Data.HomePageResponse res = new Data.HomePageResponse();
                res.VideoList = new List <VideoMini>();
                while (reader.Read())
                {
                    res.VideoList.Add(new VideoMini()
                    {
                        Duration  = reader.GetString(0),
                        Thumbnail = reader.GetString(1),
                        Title     = reader.GetString(2),
                        VideoId   = reader.GetString(3)
                    });
                }
                Connection.Close();
                return(new Response()
                {
                    Type = ResponseType.Home, Content = res, Status = "OK"
                });
            }
            Connection.Close();
            return(new Response()
            {
                Content = null, Type = ResponseType.Home, Status = "FAIL"
            });
        }
Beispiel #2
0
        private static Response VideoDetailsResponse(VideoDetails videoDetails)
        {
            DatabaseManager database = new DatabaseManager();

            (MySqlDataReader reader, var Connection) = database.RunQuery($"SELECT video_details.videoid, video_details.path, video_details.thumbnail, video_details.title, video_details.description," +
                                                                         $" video_details.width, video_details.height, video_details.duration, video_details.authorid, account_data.fullname, account_data.profileimage, course_details.coursename, video_details.courseid, " +
                                                                         $"video_details.lastupdatedon, video_details.likes, video_details.dislikes, course_details.rating FROM video_details INNER JOIN course_details INNER JOIN account_data WHERE videoid='{videoDetails.VideoID}' " +
                                                                         $"AND account_data.username=video_details.authorid AND course_details.courseid=video_details.courseid;");
            if (reader != null)
            {
                Data.HomePageResponse res = new Data.HomePageResponse();
                res.VideoList = new List <VideoMini>();
                reader.Read();
                Video video = new Video()
                {
                    VideoID       = reader.GetString(0),
                    Path          = reader.GetString(1),
                    Thumbnail     = reader.GetString(2),
                    Title         = reader.GetString(3),
                    Description   = reader.GetString(4),
                    Width         = int.Parse(reader.GetString(5)),
                    Height        = int.Parse(reader.GetString(6)),
                    Duration      = TimeSpan.Parse(reader.GetString(7)),
                    AuthorId      = reader.GetString(8),
                    AuthorName    = reader.GetString(9),
                    AuthorImage   = reader.GetString(10),
                    Course        = reader.GetString(11),
                    CourseID      = reader.GetString(12),
                    LastUpdatedOn = DateTime.Parse(reader.GetString(13)),
                    Likes         = int.Parse(reader.GetString(14)),
                    Dislikes      = int.Parse(reader.GetString(15)),
                    CommentList   = new List <Comment>(),
                    Tags          = new List <string>(),
                    CourseRating  = float.Parse(reader.GetString(16)),
                };
                Connection.Close();
                (reader, Connection) = database.RunQuery($"SELECT * FROM favorites WHERE userid='{videoDetails.UserID}' AND videoid='{videoDetails.VideoID}'");
                if (reader != null && reader.HasRows)
                {
                    video.IsFavorite = true;
                }
                Connection.Close();

                (reader, Connection) = database.RunQuery($"SELECT comments.userid, comments.videoid, account_data.fullname, account_data.profileimage, comments.content, comments.likes, comments.dislikes, comments.date, comments.uid FROM comments INNER JOIN account_data WHERE videoid='{video.VideoID}' AND account_data.username=comments.userid ORDER BY date DESC ");

                if (reader != null)
                {
                    while (reader.Read())
                    {
                        video.CommentList.Add(new Comment()
                        {
                            UserId    = reader.GetString(0),
                            VideoID   = reader.GetString(1),
                            Username  = reader.GetString(2),
                            Thumbnail = reader.GetString(3),
                            Content   = reader.GetString(4),
                            Likes     = int.Parse(reader.GetString(5)),
                            Dislikes  = int.Parse(reader.GetString(6)),
                            Date      = DateTime.Parse(reader.GetString(7)),
                            Uid       = reader.GetString(8)
                        }
                                              );
                    }
                }

                Connection.Close();
                (reader, Connection) = database.RunQuery($"SELECT tag from tag_details WHERE videoid = '{videoDetails.VideoID}'");
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        video.Tags.Add(reader.GetString(0));
                    }
                }

                Connection.Close();
                return(new Response()
                {
                    Type = ResponseType.VideoDetails, Content = video, Status = "OK"
                });
            }
            Connection.Close();
            return(new Response()
            {
                Type = ResponseType.VideoDetails, Content = null, Status = "FAIL"
            });
        }