예제 #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 async Task <BlogPostViewModelResponse> UpdatePost(string slug, BlogPostTagViewModelRequest model)
        {
            BlogPostViewModelResponse response = new BlogPostViewModelResponse();

            Models.BlogPost blog = new Models.BlogPost();
            blog.Tags = new List <BlogPostTag>();
            if (db != null)
            {
                BlogPostTag foundPost = db.BlogPostTag
                                        .AsNoTracking()
                                        .Include(p => p.BlogPost)
                                        .Include(p => p.Tag)
                                        .Where(p => p.BlogPost.Slug == slug).FirstOrDefault();

                if (!String.IsNullOrEmpty(model.BlogPost.Title) && model.BlogPost.Title != foundPost.BlogPost.Title)
                {
                    blog.Title = response.Title = model.BlogPost.Title;
                    blog.Slug  = response.Slug = GenerateSlug.ToUrlSlug(blog.Title);
                }
                blog.Id                      = foundPost.BlogPostId;
                blog.CreatedAt               = foundPost.BlogPost.CreatedAt;
                blog.UpdatedAt               = response.UpdatedAt = DateTime.Now;
                blog.Description             = response.Description
                                             = !String.IsNullOrEmpty(model.BlogPost.Description) ? model.BlogPost.Description : foundPost.BlogPost.Description;
                blog.Body                    = response.Body
                                             = !String.IsNullOrEmpty(model.BlogPost.Body) ? model.BlogPost.Body : foundPost.BlogPost.Body;
                if (model.BlogPost.Tags != null)
                {
                    response.tagList = model.BlogPost.Tags;
                }
                else
                {
                    blog.Tags        = foundPost.BlogPost.Tags;
                    response.tagList = ConvertToListString(foundPost.BlogPost.Tags);
                }

                db.BlogPosts.Update(blog);
                await db.SaveChangesAsync();
            }
            return(response);
        }
예제 #5
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());
        }
예제 #6
0
 public ApplicationBook(IBookRepositoy bookRepository, GenerateSlug generateSlug)
 {
     _bookRepository = bookRepository;
     _generateSlug   = generateSlug;
 }