public SummaryLink AddSummaryLink(Guid userId, int postId, string title, string link) { SummaryLinks = SummaryLinks ?? new List <SummaryLink>(); if (SummaryLinks.Count >= 10) { throw new ValidationException("最多关联10篇博文"); } var existLink = SummaryLinks.FirstOrDefault(x => x.PostId == postId); if (existLink != null) { existLink.Update(title, link); return(existLink); } else { var summaryLink = new SummaryLink(userId, postId, title, link); SummaryLinks.Add(summaryLink); return(summaryLink); } }
public void RemoveSummaryLink(Guid userId, long linkId) { var link = SummaryLinks.FirstOrDefault(x => x.UserId == userId && x.Id == linkId); link.Delete(); }