public ActionResult Rating(int id, Book r) { using (_561EntityModel db = new _561EntityModel()) { if (Session["UserID"] != null) { Book c = db.Books.Where(u => u.BookID == id).First(); int x = c.NumOfRaters + 1;//because when anybody is creating a book he/she is not counted as a rater string userID = Session["UserID"].ToString(); User user = db.Users.Where(u => u.UserID.ToString() == userID).First(); if (!c.UsersWhoRated.Contains(user)) { c.NumOfRaters = x + 1; c.Rating = (c.Rating + r.Rating) / c.NumOfRaters; c.UsersWhoRated.Add(user); db.SaveChanges(); } return(RedirectToAction("BookList")); } else { return(RedirectToAction("LogIn")); } } }
public ActionResult Register(User user) { if (ModelState.IsValid) { using (_561EntityModel db = new _561EntityModel()) { db.Users.Add(user); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = user.UserName + "Success"; } return(RedirectToAction("LogIn")); }
public ActionResult CreateBook(Book book) { if (ModelState.IsValid) { using (_561EntityModel db = new _561EntityModel()) { db.Books.Add(book); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = book.Title + "Saved"; } return(View()); }
public ActionResult DeleteUser(int?id) { using (_561EntityModel db = new _561EntityModel()) { var c = db.Users.Where(u => u.UserID == id).First(); if (Session["Admin"] != null) { bool f = Session["Admin"].Equals(true); if (f) { db.Users.Remove(c); db.SaveChanges(); return(RedirectToAction("UserList")); } } return(RedirectToAction("NotAdmin")); } }
public ActionResult Comments(int id, string comment) { using (_561EntityModel db = new _561EntityModel()) { if (Session["UserID"] != null) { var c = db.Books.Where(u => u.BookID == id).First(); Comment userComment = new Comment(); userComment.BookTitle = c.Title; //userComment.Book = db.Books.Where(a => a.BookID == id).First(); userComment.CommentText = comment; userComment.UserN = Session["Username"].ToString(); c.Comment.Add(userComment); db.SaveChanges(); return(View(c.Comment.ToList())); } else { return(RedirectToAction("LogIn")); } } }
public ActionResult CreateBook(Book book) { if (ModelState.IsValid) { using (_561EntityModel db = new _561EntityModel()) { if (Session["UserID"] != null) { db.Books.Add(book); db.SaveChanges(); ModelState.Clear(); ViewBag.Message = book.Title + "Saved"; return(RedirectToAction("BookList")); } else { RedirectToAction("LogIn"); } } } return(RedirectToAction("BookList")); }