Ejemplo n.º 1
0
        public ActionResult UpdateUserCode(string id, UserCodeDTO userCodeDTO)
        {
            // Handle error if no data is sent.
            if (userCodeDTO == null)
            {
                return(BadRequest("User code data must be set!"));
            }

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

                // According to the conventions, we have to return HTTP 204 No Content.
                return(NoContent());
            }
            catch (DocumentDoesntExistsException)
            {
                // Handle error if the user code to update doesn't exists.
                return(BadRequest("No user code exists with the given ID!"));
            }
            catch (ProgramLanguageNotSupportedException)
            {
                // Handle error if programming language is not supported
                return(BadRequest("This programming language is not supported!"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult <UserCodeDTO> CreateNewUserCode(UserCodeDTO userCodeDTO)
        {
            // Handle error if no data is sent.
            if (userCodeDTO == null)
            {
                return(BadRequest("User code data must be set!"));
            }

            try
            {
                // Map the DTO to entity and save the entity
                UserCode createdEntity = _service.Create(userCodeDTO.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(GetUserCode),
                           new { id = createdEntity.Id },
                           new UserCodeDTO(createdEntity)));
            }
            catch (ProgramLanguageNotSupportedException)
            {
                // Handle error if programming language is not supported
                return(BadRequest("This programming language is not supported!"));
            }
        }