public async Task <IActionResult> Create([FromBody] CategoryBasicInfoViewModel model) { var exists = await this.categories.ExistsAsync(model.Name); if (exists) { return(BadRequest(CategoryErrorConstants.CategoryAlreadyExists)); } var result = await this.categories.CreateAsync(model.Name); return(Ok(result)); }
public async Task <IActionResult> Edit([FromRoute] int id, [FromBody] CategoryBasicInfoViewModel model) { var exists = await this.categories.ExistsAsync(id); if (!exists) { return(BadRequest(CategoryErrorConstants.CategoryDoesNotExist)); } var nameTaken = await this.categories.AlreadyExistsAsync(id, model.Name); if (nameTaken) { return(BadRequest(CategoryErrorConstants.CategoryAlreadyExists)); } await this.categories.EditAsync(id, model.Name); return(Ok()); }