public ContentModel ContentCreate(ContentModel newArticle) { var table = _tableClient.GetTableReference("Content"); table.CreateIfNotExists(); var con = new Content(newArticle.Type); var tableOperation = TableOperation.Insert(con); table.Execute(tableOperation); foreach (var locale in newArticle.Locales) { var loc = new ContentLocale(locale.Locale) { ContentId = con.RowKey, Name = locale.Name, Author = locale.Author, IsDraft = locale.IsDraft, Text = locale.Text }; if (locale.Tags.Any()) loc.Tags = locale.Tags.Aggregate((workingSentence, next) => workingSentence + ";" + next); ContentLocaleCreate(loc); } newArticle.Id = con.RowKey; newArticle.Date = DateTime.ParseExact(con.RowKey, "yyyyMMddHHmmssffff", System.Globalization.CultureInfo.InvariantCulture); return newArticle; }
public bool ContentUpdate(ContentModel updateArticle) { var table = _tableClient.GetTableReference("Content"); var query = new TableQuery<Content>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, updateArticle.Id)); var res = table.ExecuteQuery(query).First(); var locTable = _tableClient.GetTableReference("ContentLocale"); var locQuery = new TableQuery<ContentLocale>().Where(TableQuery.GenerateFilterCondition("ContentId", QueryComparisons.Equal, res.RowKey)); var locRes = locTable.ExecuteQuery(locQuery).ToList(); foreach (var loc in locRes.Where(l=>!updateArticle.Locales.Exists(ul=>Enum.GetName(typeof(Locale), ul.Locale).Equals(l.PartitionKey)))) { var tableOperation = TableOperation.Delete(loc); table.Execute(tableOperation); } foreach (var locale in updateArticle.Locales) { var locStr = Enum.GetName(typeof (Locale), locale.Locale); var con = new ContentLocale(locale.Locale) { PartitionKey = locStr, ContentId = res.RowKey, Name = locale.Name, Author = locale.Author, IsDraft = locale.IsDraft, Text = locale.Text, Tags = locale.Tags.Any() ? locale.Tags.Aggregate((workingSentence, next) => workingSentence + ";" + next) : null }; if (locRes.Any(l => l.PartitionKey.Equals(locStr))) con.RowKey = locRes.Single(l => l.PartitionKey.Equals(locStr)).RowKey; var tableOperation = TableOperation.InsertOrReplace(con); locTable.Execute(tableOperation); } return true; }
public void ContentLocaleCreate(ContentLocale locale) { var table = _tableClient.GetTableReference("ContentLocale"); table.CreateIfNotExists(); var tableOperation = TableOperation.Insert(locale); table.Execute(tableOperation); }