public static UpdateDocument ToUpdateDocument(this TextContent textContent) { textContent = textContent.ConvertToUTCTime(); UpdateDocument doc = new UpdateDocument(); foreach (var item in textContent) { doc[item.Key] = BsonHelper.Create(item.Value); doc[GetCaseInsensitiveFieldName(item.Key)] = BsonHelper.Create(ToCaseInsensitiveValue(item.Value)); } return(doc); }
public MySqlCommand Add(TextContent textContent) { textContent = textContent.ConvertToUTCTime(); var schema = textContent.GetSchema().AsActual(); if (schema == null) { return(null); } List <string> fields = new List <string>() { "UUID", "Repository", "FolderName", "UserKey", "UtcCreationDate", "UtcLastModificationDate", "Published", "OriginalUUID", "SchemaName", "ParentFolder", "ParentUUID", "UserId", "OriginalRepository", "OriginalFolder", "IsLocalized", "Sequence" }; MySqlCommand command = new MySqlCommand(); command.Parameters.Add(new MySqlParameter("?UUID", textContent.UUID)); command.Parameters.Add(new MySqlParameter("?Repository", textContent.Repository)); command.Parameters.Add(new MySqlParameter("?FolderName", textContent.FolderName)); command.Parameters.Add(new MySqlParameter("?UserKey", textContent.UserKey)); command.Parameters.Add(new MySqlParameter("?UtcCreationDate", textContent.UtcCreationDate)); command.Parameters.Add(new MySqlParameter("?UtcLastModificationDate", textContent.UtcLastModificationDate)); command.Parameters.Add(new MySqlParameter("?Published", textContent.Published)); command.Parameters.Add(new MySqlParameter("?OriginalUUID", textContent.OriginalUUID)); command.Parameters.Add(new MySqlParameter("?SchemaName", textContent.SchemaName)); command.Parameters.Add(new MySqlParameter("?ParentFolder", textContent.ParentFolder)); command.Parameters.Add(new MySqlParameter("?ParentUUID", textContent.ParentUUID)); command.Parameters.Add(new MySqlParameter("?UserId", textContent.UserId)); command.Parameters.Add(new MySqlParameter("?OriginalRepository", textContent.OriginalRepository)); command.Parameters.Add(new MySqlParameter("?OriginalFolder", textContent.OriginalFolder)); command.Parameters.Add(new MySqlParameter("?IsLocalized", textContent.IsLocalized)); command.Parameters.Add(new MySqlParameter("?Sequence", textContent.Sequence)); foreach (var column in schema.Columns.Where(it => !it.IsSystemField)) { fields.Add(string.Format("{0}", column.Name)); command.Parameters.Add(CreateParameter(column, textContent)); } string sql = string.Format("INSERT INTO `{0}` ({1}) VALUES({2})", schema.GetTableName(), string.Join(",", fields.Select(it => "`" + it + "`").ToArray()), string.Join(",", fields.Select(it => "?" + it).ToArray())); command.CommandText = sql; return(command); }
public SqlCeCommand Update(TextContent textContent) { textContent = textContent.ConvertToUTCTime(); var schema = textContent.GetSchema().AsActual(); List <string> fields = new List <string>() { "Repository", "FolderName", "UserKey", "UtcCreationDate", "UtcLastModificationDate", "Published", "OriginalUUID", "SchemaName", "ParentFolder", "ParentUUID", "UserId", "OriginalRepository", "OriginalFolder", "IsLocalized", "Sequence" }; SqlCeCommand command = new SqlCeCommand(); command.Parameters.Add(new SqlCeParameter("@UUID", textContent.UUID)); command.Parameters.Add(new SqlCeParameter("@Repository", textContent.Repository)); command.Parameters.Add(new SqlCeParameter("@FolderName", textContent.FolderName)); command.Parameters.Add(new SqlCeParameter("@UserKey", textContent.UserKey)); command.Parameters.Add(new SqlCeParameter("@UtcCreationDate", textContent.UtcCreationDate)); command.Parameters.Add(new SqlCeParameter("@UtcLastModificationDate", textContent.UtcLastModificationDate)); command.Parameters.Add(new SqlCeParameter("@Published", textContent.Published)); command.Parameters.Add(new SqlCeParameter("@OriginalUUID", textContent.OriginalUUID)); command.Parameters.Add(new SqlCeParameter("@SchemaName", textContent.SchemaName)); command.Parameters.Add(new SqlCeParameter("@ParentFolder", textContent.ParentFolder)); command.Parameters.Add(new SqlCeParameter("@ParentUUID", textContent.ParentUUID)); command.Parameters.Add(new SqlCeParameter("@UserId", textContent.UserId)); command.Parameters.Add(new SqlCeParameter("@OriginalRepository", textContent.OriginalRepository)); command.Parameters.Add(new SqlCeParameter("@OriginalFolder", textContent.OriginalFolder)); command.Parameters.Add(new SqlCeParameter("@IsLocalized", textContent.IsLocalized)); command.Parameters.Add(new SqlCeParameter("@Sequence", textContent.Sequence)); foreach (var column in schema.Columns.Where(it => !it.IsSystemField)) { fields.Add(string.Format("{0}", column.Name)); command.Parameters.Add(CreateParameter(column, textContent)); } string sql = string.Format("UPDATE [{0}] SET {1} WHERE UUID=@UUID", schema.GetTableName() , string.Join(",", fields.Select(it => "[" + it + "]" + "=@" + it))); command.CommandText = sql; return(command); }