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); }
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); }
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); }
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); } }