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

                return(View());
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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"));
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
 }
Ejemplo n.º 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"));
     }
 }
Ejemplo n.º 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"));
         }
     }
 }
Ejemplo n.º 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"));
        }