Exemple #1
0
        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;
            }
        }
Exemple #2
0
        void IContentProvider <Models.TextContent> .Add(Models.TextContent content)
        {
            content.StoreFiles();
            var list = content.GetSchema().GetContents();

            ((IPersistable)content).OnSaving();
            list.Add(content.ConvertToUTCTime());
            content.GetSchema().SaveContents(list);
            ((IPersistable)content).OnSaved();
        }
Exemple #3
0
        public void Add(Models.TextContent content)
        {
            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var bucket = content.GetRepository().GetClient();

            //bucket.Store(StoreMode.Set, "Schema." + content.UUID, content.ToJson());
            bucket.ExecuteStore(StoreMode.Set, content.UUID, content.ToJson(), PersistTo.One);
            ((IPersistable)content).OnSaved();
        }
Exemple #4
0
        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;
            }
        }
Exemple #5
0
        public void Add(Models.TextContent content)
        {
            content.Remove("_id");

            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var database = content.GetRepository().GetDatabase();
            MongoCollection <BsonDocument> collection = database.GetCollection(content.GetSchema().GetSchemaCollectionName());

            collection.Insert(content.ToBsonDocument());
            ((IPersistable)content).OnSaved();
        }
Exemple #6
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 bucket = old.GetRepository().GetClient();

            bucket.ExecuteStore(StoreMode.Replace, old.UUID, @new.ToJson(), PersistTo.One);
            ((IPersistable)@new).OnSaved();
        }
Exemple #7
0
        void IContentProvider <Models.TextContent> .Update(Models.TextContent @new, Models.TextContent old)
        {
            @new.StoreFiles();

            var list  = @new.GetSchema().GetContents();
            var index = list.IndexOf(old);

            if (index != -1)
            {
                list.RemoveAt(index);
                ((IPersistable)@new).OnSaving();
                list.Insert(index, @new.ConvertToUTCTime());
                ((IPersistable)@new).OnSaved();
                @new.GetSchema().SaveContents(list);
            }
        }
Exemple #8
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();
        }
Exemple #9
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            @new.StoreFiles();

            ((IPersistable)@new).OnSaving();
            var command = dbCommands.Update(@new);

            if (SQLCeTransactionUnit.Current != null)
            {
                SQLCeTransactionUnit.Current.RegisterCommand(command);
                SQLCeTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)@new).OnSaved(); });
            }
            else
            {
                SQLCeHelper.ExecuteNonQuery(@new.GetRepository().GetConnectionString(), command);
                ((IPersistable)@new).OnSaved();
            }
        }
Exemple #10
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();
                }
            }
        }
Exemple #11
0
        public void Add(Models.TextContent content)
        {
            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var command = dbCommands.Add(content);

            if (command != null)
            {
                if (SQLCeTransactionUnit.Current != null)
                {
                    SQLCeTransactionUnit.Current.RegisterCommand(command);
                    SQLCeTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); });
                }
                else
                {
                    SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(), command);
                    ((IPersistable)content).OnSaved();
                }
            }
        }