public void ConvertToEntity_InputNotNull_ReturnSameSubCategories() { CreateProductCategoryInput input = MockCreateProductCategoryInput(); ProductCategory category = input.ConvertToEntity(); Assert.Equal(input.SubCategories, category.SubCategories); }
public static ProductCategory ConvertToEntity(this CreateProductCategoryInput source) { return(new() { Name = source.Name, SubCategories = source.SubCategories }); }
public void ConvertToEntity_InputNotNull_ReturnSameName() { CreateProductCategoryInput input = MockCreateProductCategoryInput(); ProductCategory category = input.ConvertToEntity(); Assert.Equal(input.Name, category.Name); }
public void ConvertToEntity_InputNotNull_ReturnEmplyId() { CreateProductCategoryInput input = MockCreateProductCategoryInput(); ProductCategory category = input.ConvertToEntity(); Assert.Equal(Guid.Empty, category.Id); }
public void CreateProductCategory(CreateProductCategoryInput input) { var productcategory = new ProductCategory { CategoryCode = input.CategoryCode, CategoryName = input.CategoryName, CreatorUserId = input.CreatorUserId }; _ProductCategoryRepository.Insert(productcategory); }
public async Task <IActionResult> Create([FromForm] CreateProductCategoryInput input) { var absolutePath = Path.Combine(_webHostEnvironment.WebRootPath, ProductCategory.IMAGE_PATH); await _productCateService.Create(input, absolutePath); return(Ok()); }
public async Task <IServiceResult <int> > Create(CreateProductCategoryInput input) { var category = new ProductCategory(input.Name); await _databaseContext.ProductCategories.AddAsync(category); await _databaseContext.SaveChangesAsync(); return(ServiceResult <int> .Ok(category.Id)); }
public async Task Create(CreateProductCategoryInput input, string imageFolderPath) { var imageName = await Upload.UploadImageAsync(input.Image, imageFolderPath); var proCate = new ProductCategory(image: imageName, name: input.Name, status: input.Status, url: input.Url); await _productCateRepo.Create(proCate); await _dbContext.SaveChangesAsync(); }
public async Task <ValidationResult> ValidateCreateProductCategory(CreateProductCategoryInput input) { ValidationResult validationResult = new(); if (string.IsNullOrWhiteSpace(input.Name)) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "Debe ingresar un nombre para la categoria.")); } else if (input.Name.HasFileInvalidChars()) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "El nombre no puede contener caracteres invalidos (<, >, :, \", /, \\, |, ?, *).")); } else if (!input.SubCategories.Any()) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.SubCategories), "No se puede crear una categoria sin subcategorias.")); } else if (input.SubCategories.GroupBy(x => x).Any(g => g.Count() > 1)) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "No pueden haber subcategorias repetidas.")); } else if (SubCategoriesHasInvalidChars()) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "El nombre de las subcategorias no puede contener caracteres invalidos (<, >, :, \", /, \\, |, ?, *).")); } else { var productCategory = await _repository.GetByNameAsync(input.Name); if (productCategory is not null) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "La categoria ya existe.")); } } bool SubCategoriesHasInvalidChars() { foreach (var item in input.SubCategories) { if (item.HasFileInvalidChars()) { return(true); } } return(false); } return(validationResult); }
public async Task <OperationResult <ProductCategoryDto> > CreateAsync(CreateProductCategoryInput input) { var validationResult = await _productCategoryValidator.ValidateCreateProductCategory(input); if (validationResult.IsSuccess) { var entity = input.ConvertToEntity(); entity = await _productCategoryRepository.CreateAsync(entity); return(OperationResult <ProductCategoryDto> .Success(entity.ConvertToDto(0))); } return(OperationResult <ProductCategoryDto> .Fail(validationResult)); }
public async Task <IServiceResult <int> > Post(CreateProductCategoryInput input) => await _createProductCategoryService.Create(input);
public async Task <IActionResult> Create(CreateProductCategoryInput input) { var result = await _service.CreateAsync(input); return(new OperationActionResult(result)); }