protected virtual Content CreateContent(Content content) { using (var dbContext = GetDbContext()) { var savedContent = new Content { ID = GetNextContentId(dbContext) }; dbContext.ContentsSet.Add(savedContent); savedContent.CopyPropertiesFrom(content); return savedContent; } }
public void CopyPropertiesFrom(Content entity) { this.ContentText = entity.ContentText; this.AuthorID = entity.AuthorID; this.CampaignID = entity.CampaignID; }
protected virtual Content UpdateContent(Content content) { using (var dbContext = GetDbContext()) { var savedContent = dbContext.ContentsSet.Single(cnt => cnt.ID == content.ID); savedContent.CopyPropertiesFrom(content); return savedContent; } }
public Content CreateOrUpdateContent(Content content) { return content.IsNewEntity ? CreateContent(content) : UpdateContent(content); }