示例#1
0
 public ActionResult Register(Review review)
 {
     try
     {
         ReviewDAO dao  = new ReviewDAO();
         UserDAO   udao = new UserDAO();
         review.Date = DateTime.Now;
         User u = udao.SearchById(int.Parse(Session["Id"].ToString()));
         review.UserId = u.Id;
         Review rev = dao.SearchByUserApp(review.UserId, review.ApplicationId);
         if (rev != null)
         {
             dao.Remove(rev);
         }
         dao.Add(review);
         IList <Review> revs      = dao.SearchByAppId(review.ApplicationId);
         double         totalrate = 0;
         foreach (var r in revs)
         {
             totalrate += r.Value;
         }
         totalrate = Math.Round(totalrate / revs.Count);
         ApplicationDAO appdao = new ApplicationDAO();
         Application    a      = appdao.SearchById(review.ApplicationId);
         a.Value = int.Parse(totalrate.ToString());
         appdao.Update();
         return(RedirectToAction("Product", "Application", new { id = review.ApplicationId }));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }