コード例 #1
0
        /// <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));
            }
        }
コード例 #2
0
 public ChoiceDto AddChoice(ChoiceDto choice)
 {
     using (ChoiceRepository _choiceRepo = new ChoiceRepository())
     {
         return(_choiceRepo.AddChoice(choice));
     }
 }
コード例 #3
0
 public static Choice ToEntity(this ChoiceDto dto)
 {
     return(new Choice
     {
         CurrentScenarioId = dto.CurrentScenarioId,
         NextScenarioId = dto.NextScenarioId,
         Text = dto.Text
     });
 }
コード例 #4
0
    public void MapChoiceDtoToStringCorrectly()
    {
        var expect = new ChoiceDto
        {
            Description = "foo"
        };
        var mapper = CreateMapper();
        var actual = mapper.Map <string>(expect);

        Assert.Equal(expect.Description, actual);
    }
コード例 #5
0
 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;
     }
 }