Exemple #1
0
        public ActionResult <MazeDTO> CreateNewMaze(MazeDTO mazeDTO)
        {
            // Handle error if no data is sent.
            if (mazeDTO == null)
            {
                return(BadRequest("Maze data must be set!"));
            }

            // Map the DTO to entity and save the entity
            Maze createdEntity = _service.Create(mazeDTO.ToEntity());

            // According to the conventions, we have to return a HTTP 201 created repsonse, with
            // field "Location" in the header pointing to the created object
            return(CreatedAtAction(
                       nameof(GetMaze),
                       new { id = createdEntity.Id },
                       new MazeDTO(createdEntity)));
        }
Exemple #2
0
        public ActionResult UpdateMaze(string id, MazeDTO mazeDTO)
        {
            // Handle error if no data is sent.
            if (mazeDTO == null)
            {
                return(BadRequest("Maze data must be set!"));
            }

            try
            {
                // Map the DTO to entity and save it
                _service.Update(id, mazeDTO.ToEntity());

                // According to the conventions, we have to return HTTP 204 No Content.
                return(NoContent());
            }
            catch (DocumentDoesntExistsException)
            {
                // Handle error if the maze to update doesn't exists.
                return(BadRequest("No Maze exists with the given ID!"));
            }
        }