예제 #1
0
        public CarouselWidget CloneModel(CarouselWidget model)
        {
            var originalWidgetId = model.Id;
            var cloned           = new CarouselWidget()
            {
                Id     = Guid.NewGuid().ToString("N"),
                SiteId = model.SiteId,
                Title  = model.Title,
                Slides = new List <CarouselSlide>()
            };

            cloned.Slides = model.Slides.Select(x =>
                                                new CarouselSlide()
            {
                Id          = Guid.NewGuid().ToString("N"),
                Sort        = x.Sort,
                Title       = x.Title,
                WidgetId    = cloned.Id,
                Description = x.Description,
                LinkText    = x.LinkText,
                LinkUrl     = x.LinkUrl,
                LinkTarget  = x.LinkTarget
            }).ToList();


            using (var db = new CarouselDbContext(_db))
            {
                db.CarouselWidgets.Add(cloned);
                db.SaveChanges();
            }

            return(cloned);
        }
예제 #2
0
 internal CarouselSlide Get(string id)
 {
     using (var db = new CarouselDbContext(_db))
     {
         return(db.CarouselSlides.FirstOrDefault(x => x.Id == id));
     }
 }
예제 #3
0
 public void AddSlide(CarouselSlide model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         db.CarouselSlides.Add(model);
         db.SaveChanges();
     }
 }
예제 #4
0
 public void SaveModel(CarouselWidget model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         db.CarouselWidgets.Add(model);
         db.SaveChanges();
     }
 }
예제 #5
0
 public CarouselWidget GetModel(string widgetId)
 {
     using (var db = new CarouselDbContext(_db))
     {
         return(db.CarouselWidgets
                .Include(x => x.Slides)
                .FirstOrDefault(x => x.Id == widgetId));
     }
 }
예제 #6
0
 public void UpdateModel(CarouselWidget model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         //db.Attach<CarouselWidget>(model);
         //db.Entry(model).State = EntityState.Modified;
         db.CarouselWidgets.Update(model);
         db.SaveChanges();
     }
 }
예제 #7
0
        public async Task <bool> UpdateSortOrder(string id, int sortNumber)
        {
            using (var db = new CarouselDbContext(_db))
            {
                var slide = await db.CarouselSlides.FirstOrDefaultAsync(x => x.Id == id);

                slide.Sort = sortNumber;

                await db.SaveChangesAsync();
            }

            return(true);
        }
예제 #8
0
        internal void Delete(CarouselSlide model)
        {
            using (var db = new CarouselDbContext(_db))
            {
                var currentSlide = db.CarouselSlides.FirstOrDefault(x => x.Id == model.Id);

                if (currentSlide != null)
                {
                    db.CarouselSlides.Remove(currentSlide);
                    db.SaveChanges();
                }
            }
        }
예제 #9
0
 public void DeleteModel(string widgetId)
 {
     using (var db = new CarouselDbContext(_db))
     {
         var model = db.CarouselWidgets.Include(x => x.Slides).FirstOrDefault(x => x.Id == widgetId);
         if (model == null)
         {
             return;                     // Another view/session already deleted it (race condition)
         }
         db.CarouselWidgets.Remove(model);
         db.SaveChanges();
     }
 }
예제 #10
0
        public List <CarouselItem> LoadItemsByGroupKey(string key)
        {
            using (var dbContext = new CarouselDbContext())
            {
                var items = from c in dbContext.CarouselItems
                            join g in dbContext.CarouselGroups
                            on c.GroupId equals g.Id
                            where g.Key.Equals(key, StringComparison.OrdinalIgnoreCase)
                            orderby c.Sort descending
                            select c;

                var carousels = items.ToList();
                foreach (var carousel in carousels)
                {
                    carousel.CoverImage = LoadCoverImage(carousel.Id);
                }

                return(carousels);
            }
        }
예제 #11
0
        public CarouselSlide UpdateSlide(CarouselSlide model)
        {
            using (var db = new CarouselDbContext(_db))
            {
                var currentSlide = db.CarouselSlides.FirstOrDefault(x => x.Id == model.Id);

                if (currentSlide != null)
                {
                    currentSlide.Title       = model.Title;
                    currentSlide.Description = model.Description;
                    currentSlide.LinkUrl     = model.LinkUrl;
                    currentSlide.LinkText    = model.LinkText;
                    currentSlide.LinkTarget  = model.LinkTarget;
                    db.CarouselSlides.Update(currentSlide);
                    db.SaveChanges();

                    return(currentSlide);
                }

                return(model);
            }
        }
 public P810000_CreateInitialDocumentTables(CarouselDbContext dbContext)
 {
     _dbContext = dbContext;
 }