public bool Upload(string title, string author, string youtubeId, string description, int userId)
        {
            using (var db = new MeTubeContext())
            {
                var tubeExists = db
                                 .Tubes
                                 .FirstOrDefault(t => t.Title == title);

                if (tubeExists != null)
                {
                    return(false);
                }

                var tube = new Tube
                {
                    Title       = title,
                    Author      = author,
                    Description = description,
                    YoutubeId   = youtubeId,
                    UploaderId  = userId
                };

                db.Tubes.Add(tube);
                db.SaveChanges();

                return(true);
            }
        }
Exemple #2
0
        static void Main()
        {
            var context = new MeTubeContext();
            var server  = new WebServer(8000, new ControllerRouter(), new ResourceRouter());

            MvcEngine.Run(server, context);
        }
        public User Create(string username, string password, string email)
        {
            using (var db = new MeTubeContext())
            {
                var userExists = db
                                 .Users
                                 .AsQueryable()
                                 .FirstOrDefault(u => u.Username == username || u.Email == email);

                if (userExists != null)
                {
                    return(null);
                }

                var user = new User
                {
                    Username = username,
                    Password = PasswordUtilities.GetPasswordHash(password),
                    Email    = email
                };

                db.Users.Add(user);
                db.SaveChanges();

                return(user);
            }
        }
        public static void Main()
        {
            //not finish yet
            var server = new WebServer(8888, new ControllerRouter(), new ResourceRouter());
            var db     = new MeTubeContext();

            MvcEngine.Run(server, db);
        }
Exemple #5
0
        public static void Main()
        {
            var server = new WebServer(
                42420,
                new ControllerRouter(),
                new ResourceRouter());
            var dbContext = new MeTubeContext();

            MvcEngine.Run(server, dbContext);
        }
        public User Find(string username, string password)
        {
            using (var db = new MeTubeContext())
            {
                var user = db
                           .Users
                           .AsQueryable()
                           .FirstOrDefault(u => u.Username == username && u.Password == PasswordUtilities.GetPasswordHash(password));

                return(user);
            }
        }
        public List <TubeHomeViewModel> All()
        {
            using (var db = new MeTubeContext())
            {
                var tubes = db
                            .Tubes
                            .Select(t => new TubeHomeViewModel
                {
                    Title     = t.Title,
                    Author    = t.Author,
                    YouTubeId = t.YoutubeId
                })
                            .ToList();

                return(tubes);
            }
        }
        public List <UserProfileViewModel> UserTubes(int id)
        {
            using (var db = new MeTubeContext())
            {
                var tubes = db
                            .Tubes
                            .Where(t => t.UploaderId == id)
                            .Select(t => new UserProfileViewModel
                {
                    Id     = t.Id,
                    Title  = t.Title,
                    Author = t.Author
                })
                            .ToList();

                return(tubes);
            }
        }
Exemple #9
0
 public TubeService(MeTubeContext context)
     : base(context)
 {
 }
Exemple #10
0
 public DatabaseInitializerService(MeTubeContext context) => this.context = context;
 protected BaseService(MeTubeContext context)
 {
     this.context = context;
 }
 public UserService(MeTubeContext context)
     : base(context)
 {
 }
Exemple #13
0
 public TubeService(MeTubeContext context)
 {
     this.context = context;
 }