Пример #1
0
        public OperationResult Edit(EditProduct command)
        {
            var operationResult = new OperationResult();
            var product         = _productRepository.GetProductWithCategory(command.Id);

            if (product == null)
            {
                return(operationResult.Failed(QueryValidationMessage.NotFound));
            }

            if (_productRepository.Exists(p => p.Name == command.Name && p.Id != command.Id))
            {
                return(operationResult.Failed(QueryValidationMessage.DuplicateRecord));
            }

            var productCategorySlug = product.Category.Slug;
            var productSlug         = GenerateSlug.Slugify(command.Slug);
            var picturePath         = $"{productCategorySlug}/{productSlug}";
            var pictureName         = _fileUploader.FileUpload(command.Picture, picturePath);

            product.Edit(command.Name, command.Code, GenerateSlug.Slugify(command.Slug),
                         command.MetaDescription, command.Keywords, command.Description, command.ShortDescription, pictureName,
                         command.PictureAlt, command.PictureTitle, command.CategoryId);
            _productRepository.SaveChanges();
            return(operationResult.Succeeded());
        }
Пример #2
0
        public OperationResult Edit(EditProduct command)
        {
            OperationResult operationResult = new OperationResult();
            var             product         = _productRepo.GetProductWithCategory(command.Id);

            if (product == null)
            {
                return(operationResult.Failed(ApplicationMessage.recordNotFound));
            }

            if (_productRepo.Exists(c => c.Name == command.Name && c.Id != command.Id))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }
            if (_productRepo.Exists(c => c.Code == command.Code && c.Id != command.Id))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }

            var slug = GenerateSlug.Slugify(command.Slug);

            var path       = $"{product.ProductCategory.Slug}/{slug}";
            var pictuepath = _fileUploader.Upload(command.picture, path);

            product.Edit(command.Name, command.Code, command.ShortDescription, command.Description,
                         pictuepath, command.pictureAlt, command.pictureTitle, command.KeyWords,
                         command.MetaDescription, slug, command.CategoryId);

            _productRepo.Save();
            return(operationResult.Succeeded());
        }
Пример #3
0
        public OperationResult Create(CreateProduct command)
        {
            OperationResult operationResult = new OperationResult();

            if (_productRepo.Exists(c => c.Name == command.Name))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }
            if (_productRepo.Exists(c => c.Code == command.Code))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }


            var slug = GenerateSlug.Slugify(command.Slug);

            var categorySlug = _productCategoryRepo.GetcategorySlugeby(command.CategoryId);
            var path         = $"{categorySlug}/{slug}";
            var pictuepath   = _fileUploader.Upload(command.picture, path);


            var Product = new Product(command.Name, command.Code, command.ShortDescription, command.Description,
                                      pictuepath, command.pictureAlt, command.pictureTitle, command.KeyWords,
                                      command.MetaDescription, slug, command.CategoryId);

            _productRepo.Create(Product);
            _productRepo.Save();
            return(operationResult.Succeeded());
        }
Пример #4
0
        public OperationResult Create(CreateProduct command)
        {
            var operationResult = new OperationResult();

            if (_productRepository.Exists(p => p.Name == command.Name))
            {
                return(operationResult.Failed(QueryValidationMessage.DuplicateRecord));
            }

            var productCategorySlug = _productCategoryRepository.GetSlugBy(command.CategoryId);
            var productSlug         = GenerateSlug.Slugify(command.Slug);
            var picturePath         = $"{productCategorySlug}/{productSlug}";

            var pictureName = _fileUploader.FileUpload(command.Picture, picturePath);

            var product = new Product(command.Name, command.Code, productSlug,
                                      command.MetaDescription, command.Keywords, command.Description, command.ShortDescription, pictureName,
                                      command.PictureAlt, command.PictureTitle, command.CategoryId);

            _productRepository.Create(product);
            _productRepository.SaveChanges();
            return(operationResult.Succeeded());
        }