Пример #1
0
        public IActionResult Delete(string id, string data)
        {
            var idComponents = id.Split('.');
            var entityType   = idComponents[0];
            var entityId     = int.Parse(idComponents[1]);

            switch (entityType)
            {
            case "article":
                var article = articleRepository.GetById(entityId);
                articleRepository.Delete(article);
                break;

            case "carousel":
                var carousel = carouselRepository.GetById(entityId);
                carousel.Slides.Clear();
                carouselRepository.Update(carousel);
                carouselRepository.Delete(carousel);
                break;

            case "slide":
                var slide = carouselSlideRepository.GetById(entityId);
                carouselSlideRepository.Delete(slide);
                break;

            default:
                return(Json(new { succss = false }));
            }

            return(Json(new { succss = true }));
        }
Пример #2
0
        public void Delete(long tenantId, long elementId, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Begin work
            try
            {
                // Get carousel settings
                CarouselSettings carouselSettings = (CarouselSettings)New(tenantId);
                carouselSettings.ElementId = elementId;
                _carouselRepository.Read(carouselSettings, unitOfWork ?? localUnitOfWork);

                // Delete carousel from underlying storage
                _carouselRepository.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork);

                // Delete slide images
                foreach (CarouselSlide slide in carouselSettings.Slides)
                {
                    _uploadService.Delete(slide.ImageTenantId, slide.ThumbnailImageUploadId, GetCarouselSlideStorageHierarchy(slide.ElementId), unitOfWork ?? localUnitOfWork);
                    _uploadService.Delete(slide.ImageTenantId, slide.PreviewImageUploadId, GetCarouselSlideStorageHierarchy(slide.ElementId), unitOfWork ?? localUnitOfWork);
                    _uploadService.Delete(slide.ImageTenantId, slide.ImageUploadId, GetCarouselSlideStorageHierarchy(slide.ElementId), unitOfWork ?? localUnitOfWork);
                }

                // Commit work if local unit of work in place and return result
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
Пример #3
0
 public ActionResult ConfirmDelete(int id)
 {
     try
     {
         _carouselRepo.Delete(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }