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); }
internal CarouselSlide Get(string id) { using (var db = new CarouselDbContext(_db)) { return(db.CarouselSlides.FirstOrDefault(x => x.Id == id)); } }
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 CarouselWidget GetModel(string widgetId) { using (var db = new CarouselDbContext(_db)) { return(db.CarouselWidgets .Include(x => x.Slides) .FirstOrDefault(x => x.Id == widgetId)); } }
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(); } }
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); }
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 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); } }
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; }