public async Task <ActionResult> EditCategory([FromRoute] int id, [FromBody] NCategoryCreateDTO category) { var _category = await _context.Categories.FindAsync(id); if (_category == null) { return(NotFound(id)); } _category = _mapper.Map <NCategoryCreateDTO, NCategory>(category, _category); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> CreateCategory([FromBody] NCategoryCreateDTO category) { if ((await _context.Categories.FirstOrDefaultAsync(x => x.Name == category.Name)) != null) { return(BadRequest(new { error = "Already exists a tag with this name" })); } var _category = _mapper.Map <NCategory>(category); await _context.Categories.AddAsync(_category); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateSocial), new { id = _category.Id })); }