Exemplo n.º 1
0
        public bool DeleteBookmark(string username, string id, bool movie)
        {
            var    ctx = new ImdbContext();
            string type;

            if (movie)
            {
                var bookmark = ctx.Bookmarks.Where(x => x.Username == username).Where(x => x.Tconst == id).ToList();

                if (bookmark.Count != 0)
                {
                    type = "movie";
                    ctx.Database.ExecuteSqlInterpolated($"select delete_bookmark({username},{id}, {type})");
                    ctx.SaveChanges();
                    return(true);
                }
            }
            else
            {
                var bookmark = ctx.Bookmarks.Where(x => x.Username == username).Where(x => x.Nconst == id).ToList();

                if (bookmark.Count != 0)
                {
                    type = "";
                    ctx.Database.ExecuteSqlInterpolated($"select delete_bookmark({username},{id}, {type})");
                    ctx.SaveChanges();
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 public Titlebasics GetTitle(string tconst)
 {
     //definere vores imdbcontext
     using var ctx = new ImdbContext();
     //finder tconst for vores entity titlbasics.
     return(ctx.Titlebasicses.Find(tconst));
 }
Exemplo n.º 3
0
        public Person GetPerson(string nconst)
        {
            //get person
            using var ctx = new ImdbContext();

            return(ctx.Persons.Find(nconst));
        }
Exemplo n.º 4
0
        public IList <Bookmark> GetBookmarked(string username, int page = 0, int pagesize = 50)
        {
            var ctx    = new ImdbContext();
            var result = ctx.Bookmarks
                         .Where(x => x.Username == username)
                         .Skip(page * pagesize)
                         .Take(pagesize)
                         .ToList();

            return(result);
        }
Exemplo n.º 5
0
        public IList <Ratinghistory> GetRatingHistory(string username, int page = 0, int pagesize = 50)
        {
            using var ctx = new ImdbContext();
            var result = ctx.Ratinghistories
                         .Where(x => x.Username == username)
                         .Skip(page * pagesize)
                         .Take(pagesize)
                         .ToList();

            return(result);
        }
Exemplo n.º 6
0
        public bool DeleteRating(string username, string id)
        {
            using var ctx = new ImdbContext();

            var rating = ctx.Ratinghistories.Where(x => x.Username == username).Where(x => x.Tconst == id).ToList();

            if (rating.Count != 0)
            {
                ctx.Database.ExecuteSqlInterpolated($"select delete_rating({username},{id})");
                ctx.SaveChanges();
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public bool Login(string username, string password)
        {
            //DB login command
            using var ctx = new ImdbContext();

            var data = ctx.Users.Find(username);

            if (data != null)
            {
                if (username == data.Username && password == data.Password)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        public bool Rate(string username, string tconst, int rating)
        {
            var ctx = new ImdbContext();

            var ratings = ctx.Ratinghistories
                          .Where(x => x.Username == username)
                          .Where(x => x.Tconst == tconst)
                          .ToList();

            if (ratings.Count == 0)
            {
                var result = ctx.Database.ExecuteSqlInterpolated($"select rate({username}, {tconst},{rating})");
                ctx.SaveChanges();
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public bool CreateUser(string username, string password)
        {
            using var ctx = new ImdbContext();
            //tjekker om der findes et username i databasen
            var user = ctx.Users.Find(username);

            //hvis user ikke findes, laves der en user ved at kalde en sql query
            if (user == null)
            {
                ctx.Database.ExecuteSqlInterpolated($"select create_user({username}, {password})");
                //Gemmer ændringer, så de kommer ind i databasen.
                ctx.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        public Object GetSpecificMovie(string tconst)
        {
            using var ctx = new ImdbContext();

            return(ctx.Titlebasicses
                   .Where(x => x.Tconst == tconst)
                   //.Include(x => x.Titleprincipal)
                   .FirstOrDefault(x => x.Tconst == tconst));



            // from p in ctx.Titlebasicses
            // select new { Tconst = p.Tconst, Primaryname = p.Primarytitle, p.Titleprincipal.Characters, };

            var dataa = ctx.Titlebasicses.Find(tconst);

            //.Where(x => x.Tconst == tconst)
            // .Include(ctx.Titleprincipals.Tconst);

            // ctx.Entry(dataa).Collection("Titleprincipals").Load();

            /*dataa.titleprincipal = ctx.Titleprincipals
             *  .Where(x => x.Tconst == tconst)
             *  .First<Titleprincipal>();
             *
             *
             * /*Join(
             *  ctx.Titleprincipals,
             * titlebasics => titlebasics.Tconst,
             * titleprincipal => titleprincipal.Titlebasics.Tconst,
             * (titlebasics, titleprincipal) => new
             * {
             *  Tconst = titleprincipal.Tconst,
             *  Primarytitle = titlebasics.Primarytitle,
             *  Nconst = titleprincipal.Nconst,
             *
             *  //BookTitle = book.Title
             * }
             * );   */

            return(dataa);
        }
Exemplo n.º 11
0
        public (IList <SimpleSearch>, int amount) SimpleSearch(string username, string searchstring, int page = 0, int pagesize = 50)
        {
            //get results from DB function. Take amount equal to page*pagesize -> tolist
            var mylist = new List <SimpleSearch>();
            // use string search
            var ctx    = new ImdbContext();
            var result = ctx.SimpleSearches.FromSqlInterpolated($"select * from string_search({username},{searchstring})");

            foreach (var searchResult in result)
            {
                mylist.Add(searchResult);
            }

            var amount    = mylist.Count();
            var pagedlist = mylist
                            .Skip(page * pagesize)
                            .Take(pagesize)
                            .ToList();

            return(pagedlist, amount);
        }
Exemplo n.º 12
0
        public (IList <Person>, int amount) FindActors(string username, string searchstring, int page = 0, int pagesize = 50)
        {
            //get results from DB name search function
            var mylist = new List <Person>();

            using var ctx = new ImdbContext();

            var result = ctx.Persons.FromSqlInterpolated($"select * from name_search({username},{searchstring})");


            foreach (var searchResult in result)
            {
                mylist.Add(searchResult);
            }
            var amount    = mylist.Count();
            var pagedlist = mylist
                            .Skip(page * pagesize)
                            .Take(pagesize)
                            .ToList();

            return(pagedlist, amount);
        }
Exemplo n.º 13
0
 public int numberOfBookmarks(string username)
 {
     using var ctx = new ImdbContext();
     return(ctx.Bookmarks
            .Count(x => x.Username == username));
 }
Exemplo n.º 14
0
 public int numberOfRatingHistories(string username)
 {
     using var ctx = new ImdbContext();
     return(ctx.Ratinghistories
            .Count(x => x.Username == username));
 }