Exemple #1
0
 public ActionResult BookList(string search)
 {
     using (_561EntityModel db = new _561EntityModel())
     {
         return(View(db.Books.Where(a => a.Title.Contains(search) | a.Author.Contains(search)).ToList()));
     }
 }
Exemple #2
0
 public ActionResult UserList()
 {
     using (_561EntityModel db = new _561EntityModel())
     {
         return(View(db.Users.ToList()));
     }
 }
Exemple #3
0
 public ActionResult BookList()
 {
     using (_561EntityModel db = new _561EntityModel())
     {
         return(View(db.Books.ToList()));
     }
 }
Exemple #4
0
 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"));
         }
     }
 }
Exemple #5
0
 public ActionResult Index(string search)
 {
     using (_561EntityModel db = new _561EntityModel())
     {
         return(View(db.Books.ToList()));
     }
     return(View());
 }
Exemple #6
0
        public ActionResult Rating(int?id)
        {
            using (_561EntityModel db = new _561EntityModel())
            {
                var c = db.Books.Where(u => u.BookID == id).First();

                return(View());
            }
        }
Exemple #7
0
        public ActionResult Comments(int?id)
        {
            using (_561EntityModel db = new _561EntityModel())
            {
                var c = db.Books.Where(u => u.BookID == id).FirstOrDefault();

                return(View(c.Comment));
            }
        }
Exemple #8
0
 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"));
 }
Exemple #9
0
        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());
        }
Exemple #10
0
 public ActionResult LogIn(User user)
 {
     using (_561EntityModel db = new _561EntityModel())
     {
         var usr = db.Users.Single(u => u.UserName == user.UserName && u.Password == user.Password);
         if (usr != null)
         {
             Session["UserID"]   = usr.UserID.ToString();
             Session["Username"] = usr.UserName.ToString();
             return(RedirectToAction("LoggedIn"));
         }
         else
         {
             ModelState.AddModelError("", "Username or Password is not correct");
         }
     }
     return(View());
 }
Exemple #11
0
 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"));
     }
 }
Exemple #12
0
 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"));
         }
     }
 }
Exemple #13
0
        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"));
        }