Example #1
0
        private void SaveCMSItem(string key, HttpFile file, DateTime dateToBePublished)
        {
            using (var db = DataDocumentStore.DocumentStore.OpenSession())
            {
                var cmsItem = db.Query <CMSItem>().SingleOrDefault(x => x.Key == key);

                if (cmsItem == null)
                {
                    cmsItem = new CMSItem
                    {
                        DateCreated = DateTime.Now,
                        Key         = key
                    };
                }
                var newVersion = new Version
                {
                    ContentType        = file.ContentType,
                    DateCreated        = DateTime.Now,
                    DateToBePublished  = dateToBePublished,
                    AttachmentLocation = "content/" + key + "/" + cmsItem.Versions.Count + 1
                };

                cmsItem.AddVersion(newVersion);

                db.Store(cmsItem);

                DataDocumentStore.DocumentStore.DatabaseCommands.
                PutAttachment(newVersion.AttachmentLocation,
                              null,
                              file.Value,
                              new RavenJObject());

                db.SaveChanges();
            }
        }
Example #2
0
        private void SaveCMSItem(string key, HttpFile file, DateTime dateToBePublished)
        {
            using (var db = DataDocumentStore.DocumentStore.OpenSession())
            {
                var cmsItem = db.Query<CMSItem>().SingleOrDefault(x => x.Key == key);

                if (cmsItem == null)
                {
                    cmsItem = new CMSItem
                    {
                        DateCreated = DateTime.Now,
                        Key = key
                    };

                }
                var newVersion = new Version
                {
                    ContentType = file.ContentType,
                    DateCreated = DateTime.Now,
                    DateToBePublished = dateToBePublished,
                    AttachmentLocation = "content/" + key + "/" + cmsItem.Versions.Count + 1
                };

                cmsItem.AddVersion(newVersion);

                db.Store(cmsItem);

                DataDocumentStore.DocumentStore.DatabaseCommands.
                  PutAttachment(newVersion.AttachmentLocation,
                  null,
                  file.Value,
                  new RavenJObject());

                db.SaveChanges();
            }
        }