Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public void AddSlide(CarouselSlide model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         db.CarouselSlides.Add(model);
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void SaveModel(CarouselWidget model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         db.CarouselWidgets.Add(model);
         db.SaveChanges();
     }
 }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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();
                }
            }
        }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
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);
            }
        }