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 }); }
public ActionResult Rate(int rank, string comment, long product) { var user = User.Identity.Name; var account = AccountDAO.SelectItemByLogin(user).Id; var rating = RatingDAO.SelectItemByAccount(account.Value); if (rating == null) { RatingDAO.Insert(new Rating { Message = comment, Rate = rank, Account = account, Product = product, Created = DateTime.Now, Updated = DateTime.Now }); } else { RatingDAO.UpdateById(rating.Id.Value, new Rating { Message = comment, Rate = rank, Updated = DateTime.Now }); } return(RedirectToAction("Product", new { Id = product })); }
public int addRating() { RatingDAO dao = new RatingDAO(); return(dao.Insert(this)); }