public void Add(Models.TextContent content) { try { content.StoreFiles(); ((IPersistable)content).OnSaving(); var command = dbCommands.Add(content); if (command != null) { if (SQLServerTransactionUnit.Current != null) { SQLServerTransactionUnit.Current.RegisterCommand(command); SQLServerTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); }); } else { SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), command); ((IPersistable)content).OnSaved(); } } } catch (Exception e) { throw e; } }
// private static void CreateMediaContentTable(Repository repository) // { // string ddl = string.Format(@" //IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{0}') // CREATE TABLE [{0}] ( // Id int IDENTITY (100,1), // UUID nvarchar(36) NOT NULL PRIMARY KEY, // UserKey nvarchar(526), // UtcCreationDate datetime, // UtcLastModificationDate datetime, // Published bit, // OriginalUUID nvarchar(36), // FolderName nvarchar(256), // FileName nvarchar(256), // VirtualPath nvarchar(256), // UserId nvarchar(256) // );", repository.GetMediaContentTableName()); // ExecuteDDL(repository, ddl); // } protected static void ExecuteDDL(Repository repository, string ddl) { if (!string.IsNullOrEmpty(ddl)) { SQLServerHelper.BatchExecuteNonQuery(repository, ddl.Split(';').Where(it => !string.IsNullOrEmpty(it)).Select(it => new SqlCommand(it, null)).ToArray()); } }
public void Delete(Models.MediaContent content) { string sql = string.Format("DELETE FROM {0} WHERE UUID=@UUID", content.GetRepository().GetMediaContentTableName()); SqlCommand command = new SqlCommand(); command.CommandText = sql; command.Parameters.Add(new SqlParameter("UUID", content.UUID)); SQLServerHelper.BatchExecuteNonQuery(content.GetRepository().GetConnectionString(), command); }
public void Add(Models.TextContent content) { try { content.StoreFiles(); ((IPersistable)content).OnSaving(); var folder = content.GetFolder().GetActualFolder(); var schema = content.GetSchema().GetActualSchema(); if (folder != null && folder.StoreInAPI) { var proxy = new BackendProxy(); var additionalData = new Dictionary <string, object>() { { "CreatedBy", AuthHelper.GetCurrentUserName() }, { "ModifiedBy", AuthHelper.GetCurrentUserName() }, { "OwnerId", AuthHelper.GetCurrentUserName() } }; //Get payload // var payload = JsonConvert.SerializeObject(content, new CustomJsonDictionaryConverter(schema.GetJsonSerializationIgnoreProperties(), additionalData)); //Send data to API // proxy.Execute("POST", schema.Name, payload); } else { var command = dbCommands.Add(content); if (command != null) { if (SQLServerTransactionUnit.Current != null) { SQLServerTransactionUnit.Current.RegisterCommand(command); SQLServerTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); }); } else { SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), command); ((IPersistable)content).OnSaved(); } } } } catch (Exception e) { throw e; } }
public void Delete(Models.TextContent content) { var command = dbCommands.Delete(content); if (SQLServerTransactionUnit.Current != null) { SQLServerTransactionUnit.Current.RegisterCommand(command); SQLServerTransactionUnit.Current.RegisterPostAction(delegate() { TextContentFileHelper.DeleteFiles(content); }); } else { SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), command); TextContentFileHelper.DeleteFiles(content); } }
public void Update(Models.MediaContent @new, Models.MediaContent old) { ((IPersistable)@new).OnSaving(); string sql = string.Format("UPDATE {0} SET FolderName = @FolderName,FileName = @FileName,VirtualPath=@VirtualPath) WHERE UUID=@UUID" , @new.GetRepository().GetMediaContentTableName()); SqlCommand command = new SqlCommand(); command.CommandText = sql; command.Parameters.Add(new SqlParameter("UUID", @new.UUID)); command.Parameters.Add(new SqlParameter("FolderName", @new.FolderName)); command.Parameters.Add(new SqlParameter("FileName", @new.FileName)); command.Parameters.Add(new SqlParameter("VirtualPath", @new.VirtualPath)); SQLServerHelper.BatchExecuteNonQuery(@new.GetRepository().GetConnectionString(), command); ((IPersistable)@new).OnSaved(); }
public void Add(Models.MediaContent content) { ((IPersistable)content).OnSaving(); string sql = string.Format("INSERT INTO {0}(UUID,FolderName,FileName,VirtualPath,UserId) VALUES(@UUID,@FolderName,@FileName,@VirtualPath,@UserId)" , content.GetRepository().GetMediaContentTableName()); SqlCommand command = new SqlCommand(); command.CommandText = sql; command.Parameters.Add(new SqlParameter("UUID", content.UUID)); command.Parameters.Add(new SqlParameter("FolderName", content.FolderName)); command.Parameters.Add(new SqlParameter("FileName", content.FileName)); command.Parameters.Add(new SqlParameter("VirtualPath", content.VirtualPath)); command.Parameters.Add(new SqlParameter("@UserId", content.UserId)); SQLServerHelper.BatchExecuteNonQuery(content.GetRepository().GetConnectionString(), command); ((IPersistable)content).OnSaved(); }
public void Update(Models.TextContent @new, Models.TextContent old) { @new.StoreFiles(); ((IPersistable)@new).OnSaving(); var command = dbCommands.Update(@new); if (SQLServerTransactionUnit.Current != null) { SQLServerTransactionUnit.Current.RegisterCommand(command); SQLServerTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)@new).OnSaved(); }); } else { SQLServerHelper.BatchExecuteNonQuery(@new.GetRepository(), command); ((IPersistable)@new).OnSaved(); } }
public void Update(Models.TextContent @new, Models.TextContent old) { @new.StoreFiles(); ((IPersistable)@new).OnSaving(); var folder = @new.GetFolder().GetActualFolder(); var schema = @new.GetSchema().GetActualSchema(); if (folder != null && folder.StoreInAPI) { var proxyBackend = new BackendProxy(); //Add additional data // var additionalData = new Dictionary <string, object> { { "ModifiedBy", AuthHelper.GetCurrentUserName() } }; //Get payload // var payload = JsonConvert.SerializeObject(@new, new CustomJsonDictionaryConverter(schema.GetJsonSerializationIgnoreProperties(), additionalData)); //Send data to API // proxyBackend.Execute("PUT", string.Format("{0}({1})", schema.Name, @new.Id), payload); } else { var command = dbCommands.Update(@new); if (SQLServerTransactionUnit.Current != null) { SQLServerTransactionUnit.Current.RegisterCommand(command); SQLServerTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)@new).OnSaved(); }); } else { SQLServerHelper.BatchExecuteNonQuery(@new.GetRepository(), command); ((IPersistable)@new).OnSaved(); } } }
public void ClearCategories(TextContent content) { SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), dbCommands.ClearCategories(content)); }
public void DeleteCategories(Models.TextContent content, params Models.Category[] categories) { SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), categories.Select(it => dbCommands.DeleteCategory(content.GetRepository(), it)).ToArray()); }