示例#1
0
文件: SeedBanners.cs 项目: Saphora/FC
        public SeedBanners(string versionID, ContentModel db, UmbracoProvider provider)
            : base(versionID, db, provider)
        {
            SeedName = "Banners";
            SeedStart();
            if (SeedCanRun)
            {
                List<UBanner> results = UProvider.GetList<UBanner>("Banner").ToList();
                if (results.Count > 0)
                {
                    foreach (UBanner r in results)
                    {
                        UBanner tmp = new UBanner(r);
                        tmp.IsPublished = true;
                        if (!Db.Banners.Where(w => w.UmbracoID == tmp.UmbracoID).Any())
                        {
                            UVisibility tmpVis = new UVisibility(r.visibility);
                            UVisibility vis = Db.Visibilities.Where(w => w.ColLGCls == tmpVis.ColLGCls).FirstOrDefault();
                            tmp.Genres = new List<UGenre>();

                            tmp.BannerID = r.BannerID = Guid.NewGuid();
                            tmp.Visibility = null;
                            tmp.VisibilityID = vis.VisibilityID;
                            if (tmp.CustomerIntID != null)
                            {
                                int uID = int.Parse(tmp.CustomerIntID);
                                UCustomer customer = Db.Customers.AsNoTracking().Where(w => w.UmbracoID == uID).FirstOrDefault();
                                tmp.CustomerID = customer.CustomerID;
                            }
                            else
                            {
                                throw new Exception("Banner has no customero");
                            }
                            tmp.Genres = null;

                            Db.Banners.Add(tmp);
                        }
                    }
                }
                try
                {
                    Db.SaveChanges();
                    SeedFinished(true);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    HandleDbEntityValidationException(ex);
                    throw ex;
                }
            }
            else
            {
                SeedFinished(true);
            }
        }
示例#2
0
 public void Update(UBanner banner)
 {
     Db.Entry<UBanner>(banner).State = System.Data.Entity.EntityState.Modified;
     Db.SaveChanges();
 }
示例#3
0
 public void Create(UBanner banner)
 {
     banner.BannerID = Guid.NewGuid();
     Db.Banners.Add(banner);
     Db.SaveChanges();
 }