public ActionResult Image(int id)
 {
     ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
     ImageViewModel model = new ImageViewModel();
     UserManager userManager = new UserManager(Properties.Settings.Default.ConStr);
     manager.AddView(id);
     model.Image = manager.GetImage(id);
     model.LikesCount = manager.GetLikesCount(id);
     if(User.Identity.IsAuthenticated)
     {
         model.User = userManager.GetUser(User.Identity.Name);
         model.Liked = manager.CheckIfUserLikedImage(model.User.Id, id);
     }
     return View(model);
 }
        public ActionResult Index()
        {
            ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
            IndexViewModel model = new IndexViewModel();
            UserManager userManager = new UserManager(Properties.Settings.Default.ConStr);
            if(User.Identity.IsAuthenticated)
            {
                model.User = userManager.GetUser(User.Identity.Name);
            }
            model.MostRecent = manager.GetRecentImages();
            model.MostViewed = manager.GetMostViewedImages();
            model.MostLiked = manager.TopMostLiked();

            if (TempData["url"] != null)
            {
                model.Url = (string)TempData["url"];
            }
            return View(model);
        }
 public ActionResult MyLiked(int id)
 {
     ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
     MyLikedViewModel model = new MyLikedViewModel();
     model.MyLikedImages = manager.GetUsersLikedImages(id);
     return View(model);
 }
 public ActionResult Like(int userId, int imageId)
 {
     ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
     manager.AddLike(userId, imageId);
     return Json(new { LikesCount = manager.GetLikesCount(imageId) }, JsonRequestBehavior.AllowGet);
 }
 public ActionResult Views()
 {
     ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
     return Json(new { Views = manager.GetViews() }, JsonRequestBehavior.AllowGet);
 }
 public ActionResult Upload(HttpPostedFileBase image, string description)
 {
     if (image == null)
     {
         return Redirect("index");
     }
     string fileName = Guid.NewGuid() + Path.GetExtension(image.FileName);
     ImageManager manager = new ImageManager(Properties.Settings.Default.ConStr);
     image.SaveAs(Server.MapPath("~/Images/") + fileName);
     int imageId = manager.AddImage(fileName, description);
     string url = "http://localhost:60216//home/image?id=" + imageId;
     TempData["url"] = url;
     return Redirect("index");
 }