public async Task <IActionResult> DeleteChangelogCategory([FromBody] IdEntryModel model) { var user = await TokenHelper.GetUser(User, _userManager); if (user == null) { return(RequestHandler.Unauthorized()); } var changelogCategory = await _websiteContext.ChangelogCategories.FirstOrDefaultAsync(x => x.Id == model.Id); if (changelogCategory == null) { return(RequestHandler.BadRequest($"No changelog category with id {model.Id} exists")); } var result = await _websiteContext.Changelogs.CountAsync(x => x.CategoryId == model.Id); if (result > 0) { return(RequestHandler.BadRequest($"There are {result} changes that uses this category, please remove them or change their category.")); } _websiteContext.ChangelogCategories.Remove(changelogCategory); await _websiteContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> DeleteChangelog([FromBody] IdEntryModel model) { var user = await TokenHelper.GetUser(User, _userManager); if (user == null) { return(RequestHandler.Unauthorized()); } var changelog = await _websiteContext.Changelogs.FirstOrDefaultAsync(x => x.Id == model.Id); if (changelog == null) { return(RequestHandler.BadRequest($"No changelog with id {model.Id} exists")); } _websiteContext.Changelogs.Remove(changelog); await _websiteContext.SaveChangesAsync(); return(Ok()); }