Ejemplo n.º 1
0
 public void AddSlide(CarouselSlide model)
 {
     using (var db = new CarouselDbContext(_db))
     {
         db.CarouselSlides.Add(model);
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IViewComponentResult> InvokeAsync(string widgetId, string slideId)
        {
            var model = new CarouselSlide();

            if (string.IsNullOrEmpty(slideId))
            {
                model.Id         = Guid.NewGuid().ToString("N");
                model.WidgetId   = widgetId;
                model.LinkTarget = "_self";
            }
            else
            {
                model = _carouselWidgetService.GetModel(widgetId).Slides?.FirstOrDefault(x => x.Id == slideId);
            }

            return(await Task.Run(() => View(model)));
        }
Ejemplo n.º 4
0
        public IActionResult AddItem(CarouselSlide model)
        {
            if (ModelState.IsValid)
            {
                var widget = _widgetService.GetModel(model.WidgetId);


                if (widget.Slides.Any(x => x.Id == model.Id))
                {
                    _carouselSlideService.UpdateSlide(model);
                }
                else
                {
                    _carouselSlideService.AddSlide(model);
                }

                return(Ok(model));
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 5
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);
            }
        }