Beispiel #1
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            if (@new["_id"] == null && old["_id"] != null)
            {
                @new["_id"] = old["_id"];
            }

            @new.StoreFiles();
            ((IPersistable)@new).OnSaving();
            var database = old.GetRepository().GetDatabase();
            MongoCollection <BsonDocument> collection = database.GetCollection(old.GetSchema().GetSchemaCollectionName());
            var query = new QueryDocument {
                { "UUID", old.UUID }
            };

            collection.Update(query, @new.ToUpdateDocument());
            ((IPersistable)@new).OnSaved();
        }
Beispiel #2
0
        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();
                }
            }
        }