public async Task <HelloWorldResponse> Post(HelloWorldRequest request) { var response = new HelloWorldResponse(); try { if (ModelState.IsValid) { var entityToStore = HelloWorldMapper.MapToEntity(request); _context.HelloWorld.Add(entityToStore); //uncomment this once the database is actually set up await _context.SaveChangesAsync(); response.Message = "Message successfully saved to the database"; } } catch (DbUpdateException ex) { response.Message = string.Format("There was an error when updating database: {0}", ex.InnerException); } return(response); }
public async Task <HelloWorldResponse> GetMessage([FromBody] HelloWorldRequest request) { var response = new HelloWorldResponse(); if (!ModelState.IsValid) { response.Message = "Invalid request"; return(response); } //implement logic here to get the message from the database once the database becomes available //similar to the below //var helloWorld = await _context.HelloWorld // .AsNoTracking() // .Where(x => x.Message == request.Message) // .FirstOrDefaultAsync(); //since the database is not available at this time to return the data into the HelloWorld model, //I'm assigning it the value of HelloWorldRequest var helloWorld = new HelloWorld(); helloWorld.Message = request.Message; response = HelloWorldMapper.MapFromEntity(helloWorld); return(response); }
public void InitTestSuite() { // Create object to test this.helloWorldMapper = new HelloWorldMapper(); }
public void InitTestSuite() { this.helloWorldMapper = new HelloWorldMapper(); }