public HttpResponseMessage DeleteChart(int id) { if (Request.Method == HttpMethod.Options) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.OK } } ; if (loggedUserId == null) { //TODO: you are not logged message here return(Request.CreateResponse(HttpStatusCode.Unauthorized, "err niezalogowany")); } var chartUserId = _chartRepository.GetChart(id).Select(x => x.UserId).FirstOrDefault(); if (chartUserId == null) { return(Request.CreateResponse(HttpStatusCode.OK, "err chart nie istenieje")); } if (chartUserId != loggedUserId) { return(Request.CreateResponse(HttpStatusCode.OK, "err nie twoj chart")); } var result = _chartRepository.DeleteChart(id); //TODO: what if chart with this name already exists?? return(Request.CreateResponse(HttpStatusCode.OK, "success karta usunieta")); }
public async Task <ActionResult <ChartVM> > DeleteChart(int id) { try { var chartToDelete = await chartRepository.GetChart(id); if (chartToDelete == null) { return(NotFound($"Chart with Id = {id} not found")); } return(await chartRepository.DeleteChart(id)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public IActionResult DeleteChart(int id) { if (!_chartRepository.ChartExists(id)) { return(NotFound()); } var chartEntity = _chartRepository.GetChart(id); if (chartEntity == null) { return(NotFound()); } _chartRepository.DeleteChart(chartEntity); if (!_chartRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }