Ejemplo n.º 1
0
 public async Task <ActionResult <ResultOutDto <PostCategory> > > PostPostCategory(
     [FromBody] TagCreateInDto createOptions)
 {
     try
     {
         return(Ok(ResultOutDtoBuilder.Success(await _categoryService.Create(createOptions))));
     }
     catch (ExistedConflictException e)
     {
         return(Conflict(ResultOutDtoBuilder.Fail <PostCategory>(e, "Category name existed.")));
     }
 }
Ejemplo n.º 2
0
        public async Task <PostCategory> Create(TagCreateInDto createOptions)
        {
            if (await _context.PostCategories.AnyAsync(t => t.Name == createOptions.Name))
            {
                throw new ExistedConflictException();
            }

            var newCategory = new PostCategory {
                Name = createOptions.Name, Description = createOptions.Description
            };
            await _context.PostCategories.AddAsync(newCategory);

            await _context.SaveChangesAsync();

            return(newCategory);
        }