コード例 #1
0
        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"));
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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());
        }