Пример #1
0
        public static void ExtractLoadChapterPublications()
        {
            var results = GetDataFileResults("CHAPTER");

            using (var db = new AppContext())
            {
                foreach (var record in results.ToList())
                {
                    var beholderRecord = db.Chapters.Find(Convert.ToInt32(record.Id));

                    if (beholderRecord == null)
                    {
                        continue;
                    }

                    Console.WriteLine("Creating publication for chapter: {0}: Id: {1}", beholderRecord.ChapterName, beholderRecord.Id);
                    using (var client = new WebClient())
                    {
                        byte[] buffer = client.DownloadData(record.Url);

                        var rel = new ChapterMediaPublishedRel()
                        {
                            ChapterId          = beholderRecord.Id,
                            RelationshipTypeId = 99,
                            MediaPublished     = new MediaPublished()
                            {
                                MediaTypeId           = 4,
                                ConfidentialityTypeId = 4,
                                DateCreated           = DateTime.Now,
                                DateModified          = DateTime.Now,
                                CreatedUserId         = CreatedUserId,
                                Name = "MavroImport-Chapter-" + beholderRecord.ChapterName
                            }
                        };
                        db.ChapterMediaPublishedRels.AddOrUpdate(rel);
                        db.SaveChanges();

                        var context = new MediaPublishedContext()
                        {
                            ContextText       = buffer,
                            MimeTypeId        = 7,
                            DocumentExtension = ".pdf",
                            FileStreamID      = Guid.NewGuid(),
                            FileName          = "MavroImport-Chapter-" + beholderRecord.ChapterName + ".pdf",
                            MediaPublishedId  = rel.MediaPublishedId
                        };
                        db.MediaPublishedContexts.Add(context);
                        db.SaveChanges();

                        Console.WriteLine("Created publication {0}", rel.MediaPublished);
                    }
                }
            }
        }
Пример #2
0
 public void InsertOrUpdateChapterMediaPublished(ChapterMediaPublishedRel chaptermediapublishedrel)
 {
     if (chaptermediapublishedrel.Id == default(int))
     {
         // New entity
         _ctx.ChapterMediaPublishedRels.Add(chaptermediapublishedrel);
     }
     else
     {
         // Existing entity
         _ctx.Entry(chaptermediapublishedrel).State = EntityState.Modified;
     }
 }