public async Task UpdateArticleSection(ArticleSectionModel articleSection) { articleSection.UpdateTimestamps(false); using (var ct = GetConnection(DatabaseType.PEngine, true)) { await ct.DbConnection.ExecuteAsync(ReadQuery("UpdateArticleSection", ct.ProviderName), articleSection, transaction : ct.DbTransaction); } }
public async Task InsertArticleSection(ArticleSectionModel articleSection, bool importFlag = false) { articleSection.UpdateGuid(); articleSection.UpdateTimestamps(true, importFlag); using (var ct = GetConnection(DatabaseType.PEngine, true)) { await ct.DbConnection.ExecuteAsync(ReadQuery("InsertArticleSection", ct.ProviderName), articleSection, transaction : ct.DbTransaction); } }
private async Task <OpResult> ImportArticles(string articlePath, string articleSectionPath) { var retvalue = new OpResult(); XDocument articleDoc = XDocument.Parse(System.IO.File.ReadAllText(articlePath)); var articleRecords = articleDoc.Descendants().Where(d => d.Name.LocalName.Equals("data")); var newArticleRecords = new Dictionary <Guid, ArticleModel>(); if (articleRecords.Any()) { newArticleRecords = articleRecords.Select(articleRecord => new ArticleModel() { Guid = Guid.Parse(articleRecord.GetChildElementValue("Guid")), LegacyID = ParseNInt(articleRecord.GetChildElementValue("LegacyID")), Name = articleRecord.GetChildElementValue("Name"), Description = articleRecord.GetChildElementValue("Description"), Category = articleRecord.GetChildElementValue("Category"), ContentURL = articleRecord.GetChildElementValue("ContentURL"), DefaultSection = articleRecord.GetChildElementValue("DefaultSection"), VisibleFlag = bool.Parse(articleRecord.GetChildElementValue("VisibleFlag")), UniqueName = articleRecord.GetChildElementValue("UniqueName"), HideButtonsFlag = bool.Parse(articleRecord.GetChildElementValue("HideButtonsFlag")), HideDropDownFlag = bool.Parse(articleRecord.GetChildElementValue("HideDropDownFlag")), CreatedUTC = ParseNDateTime(articleRecord.GetChildElementValue("CreatedUTC")), ModifiedUTC = ParseNDateTime(articleRecord.GetChildElementValue("ModifiedUTC")) }) .ToDictionary(a => a.Guid, a => a); XDocument sectionDoc = XDocument.Parse(System.IO.File.ReadAllText(articleSectionPath)); var sectionRecords = sectionDoc.Descendants().Where(d => d.Name.LocalName.Equals("data")); foreach (var sectionRecord in sectionRecords) { var newSection = new ArticleSectionModel() { Guid = Guid.Parse(sectionRecord.GetChildElementValue("Guid")), ArticleGuid = Guid.Parse(sectionRecord.GetChildElementValue("ArticleGuid")), Name = sectionRecord.GetChildElementValue("Name"), Data = ConvertDataToMarkDown(sectionRecord.GetChildElementValue("Data"), false), SortOrder = int.Parse(sectionRecord.GetChildElementValue("SortOrder")), UniqueName = sectionRecord.GetChildElementValue("UniqueName"), CreatedUTC = ParseNDateTime(sectionRecord.GetChildElementValue("CreatedUTC")), ModifiedUTC = ParseNDateTime(sectionRecord.GetChildElementValue("ModifiedUTC")) }; if (newArticleRecords.ContainsKey(newSection.ArticleGuid)) { newArticleRecords[newSection.ArticleGuid].Sections.Add(newSection); } else { retvalue.LogError($"Article Section {newSection.Guid} refers to a non-existent article: {newSection.ArticleGuid}"); } } } if (retvalue.Successful) { var dal = _serviceProvider.GetRequiredService <IArticleDal>(); await dal.DeleteAllArticles(); var service = _serviceProvider.GetRequiredService <IArticleService>(); retvalue.Inhale(await ProcessUpserts <ArticleModel, IArticleService>(service, newArticleRecords, (s, m) => s.UpsertArticle(m, true).Result )); } return(retvalue); }