Ejemplo n.º 1
0
        public ActionResult Rate(int id)
        {
            var pub = PubDAO.Search(id);
            var rating = RatingDAO.SearchByPersonAndPubId(UserSession.ReturnPersonId(null), pub.Id);

            if (rating == null)
            {
                rating = new Rating
                {
                    PersonId = UserSession.ReturnPersonId(null),
                    PubId = pub.Id
                };
                if (RatingDAO.Insert(rating) != null)
                {
                    pub.Rating = pub.Rating + 1;
                    PubDAO.Update(pub);
                }
            }
            else
            {
                if (RatingDAO.Delete(rating) == true)
                {
                    pub.Rating = pub.Rating - 1;
                    PubDAO.Update(pub);
                }
            }
            return RedirectToAction("Pub", new { id });
        }
Ejemplo n.º 2
0
        public ActionResult Pub(int id)
        {
            var pub = PubDAO.Search(id);
            var returnedPerson = PersonDAO.Search(UserSession.ReturnPersonId(null));
            if (returnedPerson == null) return RedirectToAction("Logout", "User");

            ViewBag.ProductList = ProductDAO.ReturnList(pub.Id);
            ViewBag.Categories = new MultiSelectList(CategoryDAO.ReturnList(), "Id", "Name");
            if (RatingDAO.SearchByPersonAndPubId(UserSession.ReturnPersonId(null), id) != null)
            {
                ViewBag.Rate = "Unrate";
            }
            else
            {
                ViewBag.Rate = "Rate";
            }

            ViewBags(returnedPerson);
            return View(pub);
        }