public IActionResult Delete([FromQuery] DeleteTimelineDto timelineDto) { try { if (_httpContextAccessor.GetCurrentUserId() != timelineDto.AuthorId) { throw new UnauthorizedAccessException("You are not authorized to delete the specified timeline."); } var result = _timelineService.Delete(timelineDto.TimelineId, timelineDto.AuthorId); if (result) { return(Ok()); } else { return(NoContent()); } } catch (Exception ex) { Console.WriteLine($"Encountered exception while attempting to delete timeline. Message: {ex.Message}"); Console.WriteLine(ex.StackTrace); return(BadRequest(new ErrorResponseDto(ex))); } }
public ActionResult DeleteConfirmed(int id) { Timeline timelineItem = timelineService.GetById((int)id); timelineService.Delete(timelineItem); return(RedirectToAction("Details", "Referees", new { id = timelineItem.RefereeId, active = "Timeline" })); }
public IHttpActionResult Delete(int timelinePostId) { //first get the timeline post var post = _timelineService.GetById(timelinePostId); if (post == null) { return(Response(new { Success = false, Message = "Post doesn't exist" })); } //only admin or post owner should be able to delete the post if (post.OwnerId == _workContext.CurrentCustomer.Id || _workContext.CurrentCustomer.IsAdmin()) { _timelineService.Delete(post); return(Response(new { Success = true })); } return(Response(new { Success = false, Message = "Unauthorized" })); }