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); }
public void AddSlide(CarouselSlide model) { using (var db = new CarouselDbContext(_db)) { db.CarouselSlides.Add(model); db.SaveChanges(); } }
public void SaveModel(CarouselWidget model) { using (var db = new CarouselDbContext(_db)) { db.CarouselWidgets.Add(model); db.SaveChanges(); } }
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(); } }
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(); } } }
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(); } }
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); } }