public static IQueryable <Book> RateBooks(User user, BookRateEnum bookrate) { int rate = BookHelper.BookRateConvert(bookrate); var bs = from ub in JianLiLinq.Default.DB.UserBooks where ub.BookRate == rate && ub.UserID == user.UserID select ub.Book; return(bs.Take(8)); }
private void SetSelectedBookRate(BookRateEnum rate) { List <BookAndUser> ubinfos = GetSelectedUserBookInfos(); if (ubinfos.Count != 1) { return; } if (ubinfos[0].UserBook == null) { ubinfos[0].UserBook = JianLiLinq.Default.CreateUserBook(ubinfos[0].Book); JianLiLinq.Default.DB.SubmitChanges(); } ubinfos[0].UserBook.BookRate = BookHelper.BookRateConvert(rate); JianLiLinq.Default.DB.SubmitChanges(); }
private void SetSelectedBookRate(BookRateEnum rate) { if (this.listView1.SelectedItems.Count != 1) { return; } BookAndUser bu = this.listView1.SelectedItems[0].Tag as BookAndUser; if (bu.UserBook == null) { bu.UserBook = JianLiLinq.Default.GetUserBook(bu.Book); if (bu.UserBook == null) { bu.UserBook = JianLiLinq.Default.CreateUserBook(bu.Book); } } bu.UserBook.BookRate = BookHelper.BookRateConvert(rate); JianLiLinq.Default.DB.SubmitChanges(); }
public static int BookRateConvert(BookRateEnum bookrate) { switch (bookrate) { case BookRateEnum.Love: return(4); case BookRateEnum.Like: return(3); case BookRateEnum.Regular: return(2); case BookRateEnum.NoFeeling: return(1); case BookRateEnum.NotLike: return(0); default: return(3); } }
// when mouse down, populate menu private void listView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // type IsBookMenuItem.Checked = false; IsPaperMenuItem.Checked = false; IsDocMenuItem.Checked = false; IsUncheckMenuItem.Checked = false; // rate LoveMenuItem.Checked = false; LikeMenuItem.Checked = false; regularToolStripMenuItem.Checked = false; noFeelingToolStripMenuItem.Checked = false; HateMenuItem1.Checked = false; notRateToolStripMenuItem.Checked = false; ClipboardCopyMenuItem.Visible = Clipboard.ContainsImage(); if (this.listView1.SelectedItems.Count == 0) { return; } else if (this.listView1.SelectedItems.Count == 1) { BookAndUser ubook = this.listView1.SelectedItems[0].Tag as BookAndUser; if (ubook == null) { return; } Book book = ubook.Book; // book type BookTypeEnum btype = BookHelper.GetBookType(book); switch (btype) { case BookTypeEnum.Book: IsBookMenuItem.Checked = true; break; case BookTypeEnum.Paper: IsPaperMenuItem.Checked = true; break; case BookTypeEnum.Doc: IsDocMenuItem.Checked = true; break; case BookTypeEnum.Uncheck: IsUncheckMenuItem.Checked = true; break; default: IsUncheckMenuItem.Checked = true; break; } UserBooks ubinfo = ubook.UserBook; if (ubinfo == null) { notRateToolStripMenuItem.Checked = true; return; } // book rate BookRateEnum rate = BookHelper.BookRateConvert(ubinfo.BookRate); switch (rate) { case BookRateEnum.Love: LoveMenuItem.Checked = true; break; case BookRateEnum.Like: LikeMenuItem.Checked = true; break; case BookRateEnum.Regular: regularToolStripMenuItem.Checked = true; break; case BookRateEnum.NoFeeling: noFeelingToolStripMenuItem.Checked = true; break; case BookRateEnum.NotLike: HateMenuItem1.Checked = true; break; default: notRateToolStripMenuItem.Checked = true; break; } } else { foreach (ListViewItem item in this.listView1.SelectedItems) { } } } }