Beispiel #1
0
        public async Task <Guid> AddSubcategoryAsync(AddSubcategoryBindingModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new ToolsException("A subcategory name cannot be empty.");
            }

            var existingSubcategory = _subcategoriesRepository.Read <SubcategoryReadModel>()
                                      .FirstOrDefault(s => s.Name == model.Name && s.CategoryId == model.CategoryId);

            if (existingSubcategory != null)
            {
                throw new ToolsException("A subcategory with the same name already exists.");
            }

            var newSubcategory = new Subcategory
            {
                Id         = Guid.NewGuid(),
                CategoryId = model.CategoryId,
                Name       = model.Name,
                CreatedOn  = DateTime.Now
            };

            return(await _subcategoriesRepository.CreateAsync(newSubcategory));
        }
Beispiel #2
0
 public async Task <Guid> AddSubcategoryAsync([FromBody] AddSubcategoryBindingModel model)
 {
     return(await _categoriesService.AddSubcategoryAsync(model));
 }