public IActionResult UpdateVote(string UserIdToVote, int EventId)
 {
     if (ModelState.IsValid)
     {
         EventUserPhotos tobeVoted = _context.EventUserPhotos.FirstOrDefault(e => e.EventId == EventId && e.UserId == UserIdToVote);
         if (tobeVoted != null)
         {
             if (tobeVoted.VoteScore == null)
             {
                 tobeVoted.VoteScore = 0;
             }
             tobeVoted.VoteScore += 1;
             EventUserPhotos voter = _context.EventUserPhotos.FirstOrDefault(e => e.EventId == EventId && e.UserId == User.Identity.Name);
             if (voter != null)
             {
                 voter.UserIdToVote = UserIdToVote;
                 _context.SaveChanges();
                 return(RedirectToAction("CurrentEvent"));
             }
             else
             {
                 return(RedirectToAction("CurrentEvent"));
             }
         }
         else
         {
             return(RedirectToAction("CurrentEvent"));
         }
     }
     else
     {
         return(RedirectToAction("CurrentEvent"));
     }
 }
        public IActionResult ImageUpload(IFormFile files, EventUserPhotos euPhotos)
        {
            if (files == null || files.Length == 0)
            {
                ModelState.AddModelError("", "No file was selected.");
                return(RedirectToAction("CurrentEvent"));
            }

            Byte[] bytes = null;
            System.Drawing.Image tmpImg = null;

            using (MemoryStream fs = new MemoryStream())
            {
                files.CopyTo(fs);
                bytes  = fs.ToArray();
                tmpImg = System.Drawing.Image.FromStream(fs);
            }

            // makes thumbnail photo set to height of 50
            int    width    = tmpImg.Width;
            int    height   = tmpImg.Height;
            string calWidth = ((int)((float)width / (float)height * 50)).ToString();

            System.Drawing.Image thumImg = tmpImg.GetThumbnailImage((int)((float)width / (float)height * 50), 50, null, IntPtr.Zero);
            Byte[] thumBytes             = null;

            using (MemoryStream ms = new MemoryStream())
            {
                thumImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                thumBytes = ms.ToArray();
            }
            var eventUserPhoto = _context.EventUserPhotos.SingleOrDefault(e => e.EventId == euPhotos.EventId && e.UserId == User.Identity.Name);

            if (eventUserPhoto != null)
            {
                eventUserPhoto.Photo          = bytes;
                eventUserPhoto.ThumbnailPhoto = thumBytes;
            }
            else
            {
                euPhotos.Photo          = bytes;
                euPhotos.ThumbnailPhoto = thumBytes;
                _context.EventUserPhotos.Add(euPhotos);
            }
            _context.SaveChanges();
            return(RedirectToAction("CurrentEvent"));
        }