Beispiel #1
0
        public async ValueTask <(bool isSuccess, string error)> AddGallery(GalleryDTO entityDTO)
        {
            var gallery = new Gallery()
            {
                Alias          = entityDTO.Alias,
                NormalizeAlias = entityDTO.Alias.TransformToId(),
                IsVisible      = entityDTO.IsVisible ?? true,

                Photos = new List <Photo>()
            };

            //Добавляем и проверяем можем ли мы добавить данную категорию
            var(isSuccess, error) = await _repository.AddGallery(gallery);

            if (!isSuccess)
            {
                return(isSuccess, error);
            }

            await _photoEntityUpdater.LoadPhotosToEntity(gallery, entityDTO, maxPixel : 1600);

            await _context.SaveChangesAsync();

            return(true, null);
        }
        private async ValueTask <(Product product, string error)> CreateProduct(ProductDTO entityDTO,
                                                                                ICollection <Photo> defaultPhotoList = null,
                                                                                List <Photo> scheduleAddedPhotoList  = null,
                                                                                List <Photo> scheduleDeletePhotoList = null)
        {
            var product = new Product()
            {
                CategoryId    = entityDTO.NewCategoryId,
                SubcategoryId = entityDTO.NewSubcategoryId,
                ProductId     = entityDTO.Alias.TransformToId(),

                Alias       = entityDTO.Alias,
                Price       = entityDTO.Price,
                Description = entityDTO.Description,
                IsVisible   = entityDTO.IsVisible ?? true,

                SeoTitle       = entityDTO.SeoTitle,
                SeoDescription = entityDTO.SeoDescription,
                SeoKeywords    = entityDTO.SeoKeywords,

                Photos = new List <Photo>()
            };

            //Добавляем и проверяем можем ли мы добавить данную категорию
            var(isSuccess, error) = await _repository.AddProduct(product);

            if (!isSuccess)
            {
                return(null, error);
            }

            _photoEntityUpdater.MovePhotosToEntity(product, defaultPhotoList);

            await _photoEntityUpdater.LoadPhotosToEntity(product,
                                                         entityDTO,
                                                         scheduleAddedPhotoList,
                                                         scheduleDeletePhotoList);

            await _context.SaveChangesAsync();

            return(product, null);
        }
 /// <inheritdoc/>
 public Task <int> SaveChangesAsync()
 {
     return(Context.SaveChangesAsync());
 }