public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Content,BookCategoryID,Slug")] BookChappter bookChappter) { if (id != bookChappter.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookChappter); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookChappterExists(bookChappter.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["BookCategoryID"] = new SelectList(_context.BookCategory, "ID", "CategoryName", bookChappter.BookCategoryID); return(View(bookChappter)); }
public async Task <IActionResult> Index(string slugCa, string slugCh) { var user = await GetCurrentUserAsync(); var chappter = _Context.BookChappter.Where(p => p.Slug == slugCh).FirstOrDefault(); int chappterID = chappter.ID; int categoryID = chappter.BookCategoryID; //xac dinh xem co ai doc cuon sach nay chua var IsReaded = _Context.HistoryofRedingBook .Where(p => p.BookChappterID == chappterID).ToList(); //Xac dinh xem user nay da co doc cuon sach nay chua var oldHistory = _Context.HistoryofRedingBook .Where(p => p.BookChappterID == chappterID && p.ApplicationUserID == user.Id).FirstOrDefault(); if (oldHistory == null) { _Context.Add(new HistoryofRedingBook { BookChappterID = chappterID, DateTime = DateTime.Now, ApplicationUserID = user.Id }); // cong diem x2 neu la nguoi doc dau tien if (!IsReaded.Any()) { user.Score += 2; } else { user.Score += 1; } _Context.Update(user); } // tang luot doc sach khi click var applicationDbcontext = _Context.BookChappter.Include(p => p.CategoryID).Where(p => p.Slug == slugCh); BookChappter book = await applicationDbcontext.FirstAsync(); book.View++; _Context.Update(book); //thong bao da doc cuon sach nay _Context.Add(new Notifications { DateTime = DateTime.Now, IsReaded = true, BookChappterID = book.BookCategoryID, ApplicationUserID = user.Id }); await _Context.SaveChangesAsync(); return(View(book)); }
public async Task <IActionResult> Create([Bind("ID,Name,Content,BookCategoryID,Slug")] BookChappter bookChappter) { if (ModelState.IsValid) { bookChappter.View = 0; _context.Add(bookChappter); _context.HistoryOfChappter.AddRange(new HistoryOfChappter { DateTime = DateTime.Now, BookChappterID = bookChappter.ID }); var user = await GetCurrentUserAsync(); _context.Notifications.AddRange(new Notifications { DateTime = DateTime.Now, BookChappterID = bookChappter.ID, ApplicationUserID = user.Id, IsChapter = true }); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["BookCategoryID"] = new SelectList(_context.BookCategory, "ID", "CategoryName", bookChappter.BookCategoryID); return(View(bookChappter)); }