public static bool ChangePassword(string email, string oldpassword, string newpassword) { BRDataContext dc = new BRDataContext(); StreamWriter sw = new StreamWriter("E:\\log.txt"); dc.Log = sw; var user = (from u in dc.Users where u.UserId == 1 && u.Password == oldpassword select u).SingleOrDefault(); if (user == null) { return(false); } user.Password = newpassword; try { dc.SubmitChanges(); return(true); } catch (Exception ex) { return(false); } finally { sw.Close(); } }
public static Book GetBook(int bookid) { BRDataContext dc = new BRDataContext(); var book = (from b in dc.Books where b.BookId == bookid select b).SingleOrDefault(); // get reviess for the book book.Reviews = from r in dc.Reviews where r.BookId == bookid select r; if (book.Reviews.Count() > 0) { int total = 0; foreach (var r in book.Reviews) { total += r.Rating; } int rating = total / book.Reviews.Count(); book.RatingString = GetRatingString(rating); } else { book.RatingString = "None"; } return(book); }
public static User Login(string email, string password) { BRDataContext dc = new BRDataContext(); var user = (from u in dc.Users where u.Email == email && u.Password == password select u).SingleOrDefault(); return(user); }
public static User GetUser(string email) { BRDataContext dc = new BRDataContext(); var user = (from u in dc.Users where u.Email == email select u).SingleOrDefault(); return(user); }
public static IEnumerable <Book> Search(string pattern) { BRDataContext dc = new BRDataContext(); var books = from b in dc.Books where b.Title.Contains(pattern) select b; return(books); }
public static IQueryable <Book> GetBooksBySubject(string subcode) { BRDataContext dc = new BRDataContext(); var books = from b in dc.Books where b.Subcode == subcode select b; return(books); }
public static bool RegisterUser(string email, string password) { BRDataContext dc = new BRDataContext(); try { int returnvalue = dc.RegisterUser(email, password); return(returnvalue == 1); } catch (Exception ex) { HttpContext.Current.Trace.Write("Error in RegisterUser : " + ex.Message); return(false); } }
public static IEnumerable <Book> GetTopRatedBooks() { BRDataContext dc = new BRDataContext(); var booksrating = (from r in dc.Reviews group r by new { r.BookId } into grp select new { BookId = grp.Key.BookId, Rating = grp.Sum(rec => rec.Rating) / grp.Count() }) .OrderByDescending(v => v.Rating).Take(5); List <Book> topbooks = new List <Book>(); foreach (var bk in booksrating) { Book book = dc.Books.Where(b => b.BookId == bk.BookId).First(); // get book book.RatingString = GetRatingString(bk.Rating); // set rating based on ratings topbooks.Add(book); } return(topbooks); }
public static bool AddReview(int bookid, int userid, int rating, string review) { try { BRDataContext dc = new BRDataContext(); Review r = new Review { BookId = bookid, UserId = userid, Rating = rating, ReviewText = review, ReviewDate = DateTime.Now }; dc.Reviews.InsertOnSubmit(r); dc.SubmitChanges(); return(true); } catch (Exception ex) { HttpContext.Current.Trace.Write("Error in AddReview : " + ex.Message); return(false); } }
public static IQueryable <Subject> GetSubjects() { BRDataContext dc = new BRDataContext(); return(dc.Subjects); }