コード例 #1
0
        public IHttpActionResult Post(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);

            if (createdResponse == null)
            {
                return(BadRequest("Er is iets misgelopen bij het registreren van het antwoord!"));
            }

            //// Circulaire referentie!! (TicketResponse <-> Ticket) -> can't be serialized!!
            //return CreatedAtRoute("DefaultApi",
            //                      new { Controller = "TicketResponse", id = createdResponse.Id },
            //                      createdResponse);

            // Gebruik DTO (Data Transfer Object)
            TicketResponseDTO responseData = new TicketResponseDTO()
            {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtRoute("DefaultApi",
                                  new { Controller = "TicketResponse", id = responseData.Id },
                                  responseData));
        }
コード例 #2
0
        public IActionResult Post(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber
                                                                   , response.ResponseText, response.IsClientResponse);

            if (createdResponse == null)
            {
                return(BadRequest("Er is iets misgelopen bij het registreren van het antwoord!"));
            }

            //return CreatedAtAction("Get", new { id = createdResponse.Id }, null);
            //return CreatedAtAction("Get", new { id = createdResponse.Id }, createdResponse); // -> serializing: circulaire referentie!!

            /* Oplossing 'DTO' */
            TicketResponseDTO responseData = new TicketResponseDTO()
            {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtAction("Get", new { id = responseData.Id }, responseData));
        }
コード例 #3
0
        public TicketResponse AddResponse(NewTicketResponseDTO response)
        {
            TicketResponse createdResponse = mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);

            TicketResponse responseData = new TicketResponse()
            {
                Id               = createdResponse.Id,
                Text             = createdResponse.Text,
                Date             = createdResponse.Date,
                IsClientResponse = createdResponse.IsClientResponse
            };

            return(responseData);
        }
コード例 #4
0
        public IActionResult Post(NewTicketResponseDTO response)
        {
            var createdResponse =
                mgr.AddTicketResponse(response.TicketNumber, response.ResponseText, response.IsClientResponse);


            //// Circulaire referentie!! (TicketResponse <-> Ticket) -> can't be serialized!!
            //return CreatedAtRoute("DefaultApi",
            //                      new { Controller = "TicketResponse", id = createdResponse.Id },
            //                      createdResponse);

            // Gebruik DTO (Data Transfer Object)
            var responseData = new TicketResponseDTO {
                Id                   = createdResponse.Id,
                Text                 = createdResponse.Text,
                Date                 = createdResponse.Date,
                IsClientResponse     = createdResponse.IsClientResponse,
                TicketNumberOfTicket = createdResponse.Ticket.TicketNumber
            };

            return(CreatedAtRoute("DefaultApi",
                                  new { Controller = "TicketResponse", id = responseData.Id },
                                  responseData));
        }