Ejemplo n.º 1
0
        public HttpResponseMessage AddChart(ChartVm chartVm)
        {
            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"));
            }

            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            Chart chart  = _chartVmRepository.CreateNewChartFromChartVm(loggedUserId, chartVm);
            var   result = _chartRepository.AddChart(chart);

            //TODO: what if chart with this name already exists??
            return(Request.CreateResponse(HttpStatusCode.Created,
                                          new string[] { result.ToString(), "success nowa karta dodana" }));
        }
        public IActionResult PostChart([FromBody] ChartForCreationDto chart)
        {
            if (chart == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mapChart = Mapper.Map <Entities.Chart>(chart);

            _chartRepository.AddChart(mapChart);

            if (!_chartRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdChartToReturn = Mapper.Map <ChartDto>(mapChart);

            return(CreatedAtRoute("GetChart", new
                                  { id = createdChartToReturn.Id }, createdChartToReturn));
        }