Пример #1
0
        public IActionResult Edit(int id, [Bind("MemeID,MemeName,MemeImgUrl,MemeCategory,MemeUpvotes")] Meme meme)
        {
            if (id != meme.MemeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(meme);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemeExists(meme.MemeID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(meme));
        }
Пример #2
0
        public IActionResult UpVote(int id)
        {
            var         userId   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            AppUserMeme timThay  = userMemeService.GetByUserIdMemeId(userId, id);
            Meme        chinhSua = memeService.GetById(id);

            if (timThay != null)
            {
                if (timThay.UporDown == "uv")
                {
                    chinhSua.MemeUpvotes--;
                    memeService.Update(chinhSua);
                    userMemeService.Delete(timThay);
                }
                else
                {
                    chinhSua.MemeUpvotes += 2;
                    memeService.Update(chinhSua);
                    timThay.UporDown = "uv";
                    userMemeService.Update(timThay);
                }
            }
            else
            {
                AppUserMeme lichSuUpVoteMoi = new AppUserMeme();
                lichSuUpVoteMoi.MemeId   = id;
                lichSuUpVoteMoi.UserId   = userId;
                lichSuUpVoteMoi.UporDown = "uv";
                chinhSua.MemeUpvotes++;
                memeService.Update(chinhSua);
                userMemeService.Add(lichSuUpVoteMoi);
            }
            return(RedirectToAction("Index", new { id = chinhSua.MemeCategory }));
        }