public async Task <IActionResult> RemoveCategory(int id) { var categoryFromRepo = await _repo.GetCategory(id); _repo.Delete(categoryFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Delete fail"); }
public async Task <IActionResult> Delete(string id) { var userId = User.GetUserId(); // Option 1: Check if the user has access to the project and then delete var issue = await _repo.GetIssue(id); if (issue == null) { return(NotFound(new { message = "Issue not found." })); } var projectId = issue.Phase.ProjectId; var projectUser = await _repo.GetProjectUser(projectId, userId); if (projectUser == null) { return(Unauthorized(new { message = "You do not have the authorization to delete the issue." })); } _repo.Delete(issue); if (await _repo.SaveAll()) { var issueToReturn = _mapper.Map <IssueListItemDto>(issue); return(Ok(new { message = "Successfully deleted the issue.", issue = issueToReturn })); } return(BadRequest(new { message = "Error deleting the issue." })); }
public async Task <IActionResult> Delete(string id) { var userId = User.GetUserId(); var project = await _repo.GetProject(id, userId); if (project == null) { return(NotFound("Project not found.")); } _repo.Delete(project); if (await _repo.SaveAll()) { return(Ok(new { message = "Project successfully deleted." })); } return(BadRequest(new { message = "Error deleting the project." })); }
public async Task <IActionResult> RemoveUser(string id) { var userFromRepo = await _userManager.FindByIdAsync(id); if (userFromRepo.Tickets != null || userFromRepo.project != null) { BadRequest("User been assigned to job"); } _repo.Delete(userFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception(userFromRepo.UserName + " unable to remove"); }
public async Task <IActionResult> Delete([FromRoute] string id) { var userId = User.GetUserId(); var comment = await _repo.GetComment(id); if (comment.CreatedById != userId) { return(Unauthorized()); } _repo.Delete(comment); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> Delete([FromRoute] string id) { var userId = User.GetUserId(); var attachment = await _repo.GetAttachment(id); if (attachment.CreatedById != userId) { return(Unauthorized()); } var fullPath = $"C:\\Users\\Luka\\Desktop\\BugTracker\\Api\\{attachment.Url}"; System.IO.File.Delete(fullPath); _repo.Delete(attachment); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest()); }