Пример #1
0
        public IActionResult DownVote(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 == "dv")
                {
                    chinhSua.MemeUpvotes++;
                    memeService.Update(chinhSua);
                    userMemeService.Delete(timThay);
                }
                else
                {
                    chinhSua.MemeUpvotes -= 2;
                    memeService.Update(chinhSua);
                    timThay.UporDown = "dv";
                    userMemeService.Update(timThay);
                }
            }
            else
            {
                AppUserMeme lichSuUpVoteMoi = new AppUserMeme();
                lichSuUpVoteMoi.MemeId   = id;
                lichSuUpVoteMoi.UserId   = userId;
                lichSuUpVoteMoi.UporDown = "dv";
                chinhSua.MemeUpvotes--;
                memeService.Update(chinhSua);
                userMemeService.Add(lichSuUpVoteMoi);
            }
            return(RedirectToAction("Index", new { id = chinhSua.MemeCategory }));
        }
        public IActionResult Create([Bind("AppUserMemeId,MemeId,UserId")] AppUserMeme appUserMeme)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appUserMeme);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(appUserMeme));
        }
 public IActionResult Edit(int id, [Bind("AppUserMemeId,MemeId,UserId")] AppUserMeme appUserMeme)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(appUserMeme);
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!AppUserMemeExists(appUserMeme.AppUserMemeId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(appUserMeme));
 }
Пример #4
0
 public void Delete(AppUserMeme deleteAppUserMeme)
 {
     context.TAppUserMeme.Remove(deleteAppUserMeme);
     context.SaveChanges();
 }
Пример #5
0
 public void Update(AppUserMeme updateAppUserMeme)
 {
     context.TAppUserMeme.Update(updateAppUserMeme);
     context.SaveChanges();
 }
Пример #6
0
 public void Add(AppUserMeme newAppUserMeme)
 {
     context.TAppUserMeme.Add(newAppUserMeme);
     context.SaveChanges();
 }