Esempio n. 1
0
        public static void UpdateFrom(this SoaChapter dbSoaChapter, Contracts.Soa.SoaChapter soaChapter, string isoCode)
        {
            var dbSoaChapterItem = dbSoaChapter.SoaChapterItems.FirstOrDefault(i => i.IsoCode == isoCode);

            if (dbSoaChapterItem == null)
            {
                dbSoaChapterItem = new SoaChapterItem();
                dbSoaChapter.SoaChapterItems.Add(dbSoaChapterItem);
            }
            dbSoaChapterItem.Name        = soaChapter.Name;
            dbSoaChapterItem.Description = soaChapter.Description;
            dbSoaChapterItem.Goal        = soaChapter.Goal;
            dbSoaChapterItem.HowTo       = soaChapter.HowTo;
            dbSoaChapterItem.Info        = soaChapter.Info;
        }
Esempio n. 2
0
        public static Contracts.Soa.SoaChapter ToContract(this SoaChapter soaChapter, string isoCode)
        {
            var item = soaChapter.SoaChapterItems.First(i => i.IsoCode == isoCode);

            return(new Contracts.Soa.SoaChapter()
            {
                ParentId = soaChapter.Parent,
                Id = soaChapter.Id,
                Name = item.Name,
                Description = item.Description,
                Goal = item.Goal,
                HowTo = item.HowTo,
                Info = item.Info,
                SoaType = soaChapter.SoaType,
                IsoCode = isoCode,
                //SubChapters = soaChapter.SubChapters.Select(s => s.ToContract()).ToList()
            });
        }
Esempio n. 3
0
 private void AddNewSoaChapters(List <Contracts.Soa.SoaChapter> chapters, SoaChapter parentChapter, RAAPMasterEntities db, string isoCode)
 {
     foreach (var chapter in chapters)
     {
         SoaChapter dbChapter;
         if (chapter.Id <= 0)
         {
             dbChapter = chapter.ToDataModel(parentChapter, db, isoCode);
             db.SoaChapters.Add(dbChapter);
         }
         else
         {
             dbChapter = db.SoaChapters.FirstOrDefault(c => c.Id == chapter.Id);
         }
         if (chapter.SubChapters != null && chapter.SubChapters.Count > 0)
         {
             AddNewSoaChapters(chapter.SubChapters, dbChapter, db, isoCode);
         }
     }
 }
Esempio n. 4
0
        public static SoaChapter ToDataModel(this Contracts.Soa.SoaChapter soaChapter, SoaChapter parentSoaChapter, RAAPMasterEntities db, string isoCode)
        {
            var dbSoaChapter = new SoaChapter()
            {
                ParentChapter = parentSoaChapter,
                SoaType       = soaChapter.SoaType,
            };
            var dbSoaChapterItem = new SoaChapterItem()
            {
                Name        = soaChapter.Name,
                Description = soaChapter.Description,
                Goal        = soaChapter.Goal,
                HowTo       = soaChapter.HowTo,
                Info        = soaChapter.Info,
                IsoCode     = isoCode,
            };

            dbSoaChapter.SoaChapterItems.Add(dbSoaChapterItem);
            //db.SaveChanges(); //<-not optimal, but need to save parent chapters to make recursive linking work... :/
            soaChapter.SubChapters.ForEach(c => c.ToDataModel(dbSoaChapter, db, isoCode));
            return(dbSoaChapter);
        }