Пример #1
0
        public User LogUser(User user)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.UserSet
                   .Where(u => u.Login == user.Login && user.Password == u.Password)
                   .Select(u => u).FirstOrDefault());
        }
Пример #2
0
        public bool DeleteMovie(Movie movie)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();
            Movie toDelete         = ctx.MovieSet.Where(m => m.Id == movie.Id).FirstOrDefault();

            ctx.MovieSet.Remove(toDelete);
            ctx.SaveChanges();
            return(true);
        }
Пример #3
0
        public bool DeleteUser(User user)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();
            User toDelete          = ctx.UserSet.Where(u => u.Id == user.Id).FirstOrDefault();

            ctx.UserSet.Remove(toDelete);
            ctx.SaveChanges();
            return(true);
        }
Пример #4
0
        public User CreateUser(User user)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            Console.WriteLine("user in create: " + user.Login);
            ctx.UserSet.Add(user);
            ctx.SaveChanges();
            return(user);
        }
Пример #5
0
        public bool DeleteComment(Comment comment)
        {
            DataModelContainer ctx      = DataModelContainer.GetDb();
            Comment            toDelete = ctx.CommentSet.Where(c => c.Id == comment.Id).FirstOrDefault();

            ctx.CommentSet.Remove(toDelete);
            ctx.SaveChanges();
            return(true);
        }
Пример #6
0
        public Movie CreateMovie(Movie movie)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            Console.WriteLine("movie in create: " + movie.Title);
            ctx.MovieSet.Add(movie);
            ctx.SaveChanges();
            return(movie);
        }
Пример #7
0
        public Comment CreateComment(Comment comment)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            Console.WriteLine("comment in create: " + comment.ToString());
            ctx.MovieSet.Attach(comment.Movie);
            ctx.UserSet.Attach(comment.User);
            ctx.CommentSet.Add(comment);
            ctx.SaveChanges();
            return(comment);
        }
Пример #8
0
        public User UpdateUser(User user)
        {
            Console.WriteLine("User passed to update: " + user.ToString());
            DataModelContainer ctx = DataModelContainer.GetDb();
            User toUpdate          = ctx.UserSet.Where(u => u.Id == user.Id).FirstOrDefault();

            Console.WriteLine("In UpdateUser, return of update method: " + toUpdate.ToString());
            toUpdate.Firstname = user.Firstname;
            toUpdate.Lastname  = user.Lastname;
            toUpdate.Login     = user.Login;
            toUpdate.Password  = user.Password;
            if (toUpdate.Equals(user))
            {
                Console.WriteLine("Update ok");
                ctx.SaveChanges();
                return(toUpdate);
            }
            else
            {
                throw new Exception("Update failed");
            }
        }
Пример #9
0
        public Comment UpdateComment(Comment comment)
        {
            Console.WriteLine("Comment passed to update: " + comment.ToString());
            DataModelContainer ctx      = DataModelContainer.GetDb();
            Comment            toUpdate = ctx.CommentSet.Where(c => c.Id == comment.Id).FirstOrDefault();

            Console.WriteLine("In UpdateComment, return of update method: " + toUpdate.ToString());
            toUpdate.Message = comment.Message;
            toUpdate.Movie   = comment.Movie;
            toUpdate.Note    = comment.Note;
            toUpdate.User    = comment.User;
            if (toUpdate.Equals(comment))
            {
                Console.WriteLine("Update ok");
                ctx.SaveChanges();
                return(toUpdate);
            }
            else
            {
                throw new Exception("Update comment failed");
            }
        }
Пример #10
0
        public Movie UpdateMovie(Movie movie)
        {
            Console.WriteLine("Movie passed to update: " + movie.ToString());
            DataModelContainer ctx = DataModelContainer.GetDb();
            Movie toUpdate         = ctx.MovieSet.Where(m => m.Id == movie.Id).FirstOrDefault();

            Console.WriteLine("In UpdateMovie, return of update method: " + toUpdate.ToString());
            toUpdate.Title    = movie.Title;
            toUpdate.Type     = movie.Type;
            toUpdate.Abstract = movie.Abstract;
            toUpdate.Comments = movie.Comments;
            if (toUpdate.Equals(movie))
            {
                Console.WriteLine("Update ok");
                ctx.SaveChanges();
                return(toUpdate);
            }
            else
            {
                throw new Exception("Update movie failed");
            }
        }
Пример #11
0
        public User GetUser(int uid)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.UserSet.Where(u => u.Id == uid).FirstOrDefault());
        }
Пример #12
0
        public List <User> getAllUsers()
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.UserSet.ToList());
        }
Пример #13
0
        public Comment GetComment(int cid)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.CommentSet.Where(c => c.Id == cid).FirstOrDefault());
        }
Пример #14
0
        public List <Comment> getAllComments()
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.CommentSet.ToList());
        }
Пример #15
0
        public Movie GetMovie(int mid)
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.MovieSet.Where(m => m.Id == mid).FirstOrDefault());
        }
Пример #16
0
        public List <Movie> getAllMovies()
        {
            DataModelContainer ctx = DataModelContainer.GetDb();

            return(ctx.MovieSet.ToList());
        }