Ejemplo n.º 1
0
 public static Video GetVideo(int id)
 {
     using (var db = new YouTubeUMLEntities())
     {
         Video video = db.Videos.FirstOrDefault(el => el.Id == id) ?? new NullVideo();
         return(video);
     }
 }
Ejemplo n.º 2
0
        public static bool DislikeVideo(int id)
        {
            using (var db = new YouTubeUMLEntities())
            {
                Video video = db.Videos.FirstOrDefault(el => el.Id == id);
                video.Dislikes = ++video.Dislikes;
                db.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static int GetVideoDislikes(int id)
        {
            using (var db = new YouTubeUMLEntities())
            {
                Video video = db.Videos.FirstOrDefault(el => el.Id == id);
                if (video != null)
                {
                    return((int)video.Dislikes);
                }
            }

            return(0);
        }
Ejemplo n.º 4
0
        public static bool AddLog(string action, int uid)
        {
            using (var db = new YouTubeUMLEntities())
            {
                var log = new Log();
                db.Logs.Add(log);
                log.Action = action;
                log.UserId = uid;
                log.Type   = 1;

                db.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 5
0
        public static bool CreateUser(string username, string password, int type)
        {
            using (var db = new YouTubeUMLEntities())
            {
                var user = new User();
                db.Users.Add(user);
                user.UserName = username;
                user.Password = password;
                user.Type     = type;

                db.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static bool DeleteVideo(int id)
        {
            using (var db = new YouTubeUMLEntities())
            {
                Video video = db.Videos.FirstOrDefault(el => el.Id == id);
                if (video != null)
                {
                    db.Videos.Remove(video);
                    db.SaveChanges();
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        public static string GetComments(int vid)
        {
            var    list = new List <Comment>();
            string result;

            using (var db = new YouTubeUMLEntities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                list   = db.Comments.Where(el => el.VideoId == vid).OrderByDescending(x => x.Id).ToList();
                result = JsonConvert.SerializeObject(list, Formatting.Indented);
            }

            return(result);
        }
Ejemplo n.º 8
0
        public static bool UploadVideo(string name, int userId, string URL)
        {
            using (var db = new YouTubeUMLEntities())
            {
                var video = new Video();
                db.Videos.Add(video);
                video.Title      = name;
                video.URL        = URL;
                video.UploaderId = userId;

                db.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 9
0
        public static bool LoginUser(string username, string password)
        {
            using (var db = new YouTubeUMLEntities())
            {
                User user = db.Users.FirstOrDefault(el => el.UserName.Equals(username) && el.Password.Equals(password));
                if (user == null)
                {
                    return(false);
                }

                LogedUser = user;
            }

            return(true);
        }
Ejemplo n.º 10
0
        public static bool CommentVideo(int vid, string msg, int uid)
        {
            using (var db = new YouTubeUMLEntities())
            {
                if (db.Videos.FirstOrDefault(el => el.Id == vid) != null)
                {
                    Comment comment = new Comment();

                    comment.Message = msg;
                    comment.UserId  = uid;
                    comment.VideoId = vid;

                    db.Comments.Add(comment);
                    db.SaveChanges();
                }
            }

            return(true);
        }