/// <summary> /// 添加一个点赞记录 /// </summary> protected virtual void AddGiveLike(Guid userId) { // 避免重复点赞 if (GiveLikes.Exists(x => x.UserId == userId)) { return; } var record = new GiveLike(userId, Id); GiveLikes.Add(record); GiveLikeNumber += 1; }
public async Task <GiveLike> CreateAsync(GiveLike giveLike, Comment comment, CancellationToken cancellationToken = default(CancellationToken)) { if (giveLike == null) { throw new ArgumentNullException(nameof(giveLike)); } Context.Add(giveLike); Context.Attach(comment); var entry = Context.Entry(comment); entry.Property(x => x.LikeNum).IsModified = true; await Context.SaveChangesAsync(cancellationToken); return(giveLike); }
public void LogIn_GiveLike() { try { var driver = SetUp(); var loginAccount = new LogIn(driver, new WebDriverWait(driver, TimeSpan.FromSeconds(10))); loginAccount.LoginAccount(driver); var like = new GiveLike(driver, new WebDriverWait(driver, TimeSpan.FromSeconds(10))); like.Like(driver); driver.Quit(); } catch (Exception e) { TestContext.Error.WriteLine($"{e.ToString()}"); } }
/// <summary> /// 点赞 /// </summary> /// <param name="userid">创建者</param> /// <param name="id">评论ID</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public virtual async Task CreateGiveLikeAsync(string userid, string id, CancellationToken cancellationToken = default(CancellationToken)) { var comment = await _icommentStore.GetAsync(a => a.Where(b => b.Id == id), cancellationToken); if (comment == null) { return; } var like = new GiveLike(); like.Id = id; like.CreateTime = DateTime.Now; like.CustomerId = userid; comment.LikeNum++; await _igiveLikeStore.CreateAsync(like, comment, cancellationToken); }
public async Task DeleteAsync(GiveLike giveLike, Comment comment, CancellationToken cancellationToken = default(CancellationToken)) { if (giveLike == null) { throw new ArgumentNullException(nameof(giveLike)); } Context.Remove(giveLike); Context.Attach(comment); var entry = Context.Entry(comment); entry.Property(x => x.LikeNum).IsModified = true; try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { throw; } }