Beispiel #1
0
        public JsonResult SetRating(Rating rating)
        {
            if (Request.Cookies["rating_" + rating.PostId.ToString()] != null)
            {
                double storedrating = Double.Parse(Request.Cookies["rating_" + rating.PostId.ToString()].Value);
                Rating oldrating    = RatingServices.FindAllEntities(r => r.PostId == rating.PostId && r.Value == storedrating, null, null).FirstOrDefault();
                if (oldrating != null)
                {
                    RatingServices.DeleteEntity(oldrating);
                }
                RatingServices.AddEntity(rating);
                Response.Cookies["rating_" + rating.PostId.ToString()].Value   = rating.Value.ToString();
                Response.Cookies["rating_" + rating.PostId.ToString()].Expires = DateTime.Now.AddYears(5);
            }
            else
            {
                HttpCookie cookie = new HttpCookie("rating_" + rating.PostId.ToString(), rating.Value.ToString());
                cookie.Expires = DateTime.Now.AddYears(5);
                Response.Cookies.Add(cookie);
                RatingServices.AddEntity(rating);
            }
            int    totalvotes     = RatingServices.FindAllEntities(r => r.PostId == rating.PostId, null, null).Count();
            double average        = RatingServices.FindAllEntities(r => r.PostId == rating.PostId, null, null).Average(s => s.Value);
            double roundedaverage = Math.Round(average, 1);

            return(Json(new { roundedaverage, totalvotes }));
        }
Beispiel #2
0
 public ActionResult Create(Tag tag)
 {
     if (ModelState.IsValid)
     {
         TagServices.AddEntity(tag);
         return(RedirectToAction("Index"));
     }
     return(View(tag));
 }
Beispiel #3
0
 public ActionResult Create(Album album)
 {
     if (ModelState.IsValid)
     {
         AlbumServices.AddEntity(album);
         return(RedirectToAction("Index"));
     }
     return(View(album));
 }
Beispiel #4
0
 public ActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         CategoryServices.AddEntity(category);
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Beispiel #5
0
        public ActionResult Create(Image image)
        {
            if (ModelState.IsValid)
            {
                ImageServices.AddEntity(image);
                return(RedirectToAction("Index"));
            }

            return(View(image));
        }