//订阅事件 public async Task <IActionResult> Subscribe([Bind("ID,UserA_id,UserB_id")] mb_relationship relationship, string userid, string blogid) { _context.Add(relationship); await _context.SaveChangesAsync(); //被订阅者粉丝数量加1 var mb_user = await _context.mb_user.SingleOrDefaultAsync(m => m.User_id == userid); mb_user.Fans_num++; try { _context.Update(relationship); await _context.SaveChangesAsync(); } catch { } return(RedirectToAction("Details", "blog", new { id = blogid, createid = userid })); }
public async Task <IActionResult> Create([Bind("ID,User_publish,User_accept,Create_time,content,blog_id,comment_id")] mb_comment mb_comment, string bid, string createid) { if (ModelState.IsValid) { mb_comment.User_publish = User.Identity.Name; mb_comment.Create_time = DateTime.Now; _context.Add(mb_comment); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Blog", new { id = bid, createid = createid })); } return(View(mb_comment)); }
public void AddVote(int userId, int pageId, bool vote) { var userVote = _db.PageVotes.FirstOrDefault(c => c.UserId == userId && c.PageID == pageId); if (userVote != null) { userVote.Vote = vote; } else { userVote = new PageVote() { PageID = pageId, UserId = userId, Vote = vote }; _db.Add(userVote); } _db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("ID,User_id,User_name,Fans_num,Blog_num,Comment_num,User_pwd,Avatar")] mb_user mb_user) { if (ModelState.IsValid) { mb_user.Avatar = "../../userhead/1.png"; _context.Add(mb_user); await _context.SaveChangesAsync(); //用户标识 var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, mb_user.User_id)); identity.AddClaim(new Claim(ClaimTypes.Role, "User")); //用户签到 await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); return(RedirectToAction("Index", "Home")); } return(View(mb_user)); }