/// <summary> /// Posts the choice /// </summary> /// <param name="choice">The choice.</param> /// <response code="200"> Created</response> /// <response code="400"> parameter issue</response> /// <response code="500">Other issues, see message included</response> public IHttpActionResult PostChoice([FromBody] ChoiceDto choice) { if (choice == null) { return(BadRequest("Choice Id is required")); } try { ChoiceDto choiceDto = _choiceService.AddChoice( new ChoiceDto { CurrentScenarioId = choice.CurrentScenarioId, NextScenarioId = choice.NextScenarioId, Text = choice.Text, } ); return(Ok(choiceDto)); } catch (Exception e) { return(InternalServerError(e)); } }
public ChoiceDto AddChoice(ChoiceDto choice) { using (ChoiceRepository _choiceRepo = new ChoiceRepository()) { return(_choiceRepo.AddChoice(choice)); } }
public static Choice ToEntity(this ChoiceDto dto) { return(new Choice { CurrentScenarioId = dto.CurrentScenarioId, NextScenarioId = dto.NextScenarioId, Text = dto.Text }); }
public void MapChoiceDtoToStringCorrectly() { var expect = new ChoiceDto { Description = "foo" }; var mapper = CreateMapper(); var actual = mapper.Map <string>(expect); Assert.Equal(expect.Description, actual); }
public ChoiceDto AddChoice(ChoiceDto choice) { try { Choice newChoice = choice.ToEntity(); var choiceCreated = _dbcontext.Choice.Add(newChoice); _dbcontext.SaveChanges(); return(choiceCreated.ToDto()); } catch (Exception e) { Console.WriteLine(e.Message); throw; } }