public static Video GetVideo(int id) { using (var db = new YouTubeUMLEntities()) { Video video = db.Videos.FirstOrDefault(el => el.Id == id) ?? new NullVideo(); return(video); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }