示例#1
0
        public IHttpActionResult LogInteraction(InteractionDto interactionDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var interaction = Mapper.Map <InteractionDto, Interaction>(interactionDto);

            _context.Interactions.Add(interaction);
            _context.SaveChanges();

            interactionDto.Id = interaction.Id;

            return(Created(new Uri(Request.RequestUri + "/" + interaction.Id), interactionDto));
        }
        public async Task <IActionResult> Put(int id, [FromBody] InteractionDto body)
        {
            var obj = new InteractionService
            {
                Name_input        = body?.Name_input,
                Date_input        = body?.Date_input,
                Num_assisted      = body?.Num_assisted.ToInt(),
                Location          = body?.Location,
                Reject_assistance = body?.Reject_assistance,
                Other             = body?.Other.ToInt(),
                Emergency         = body?.Emergency.ToInt(),
                Launchpad         = body?.Launchpad.ToInt(),
                Mission           = body?.Mission.ToInt(),
                Staging           = body?.Staging.ToInt(),
                Other_comment     = body?.Other_comment
            };

            await _context.Connection.OpenAsync();

            var query  = new InteractionService(_context);
            var result = await query.GetSingleAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            result.Id           = obj.Id;
            result.Name_input   = obj.Name_input;
            result.Date_input   = obj.Date_input;
            result.Num_assisted = obj.Num_assisted;
            result.Location     = obj.Location;

            await result.UpdateAsync();

            return(new OkObjectResult(result));
        }
        public async Task <IActionResult> Post([FromBody] InteractionDto body)
        {
            await _context.Connection.OpenAsync();

            var obj = new InteractionService
            {
                Name_input        = body?.Name_input,
                Date_input        = body?.Date_input,
                Num_assisted      = (body?.Num_assisted).ToInt(),
                Location          = body?.Location,
                Reject_assistance = body?.Reject_assistance,
                Other             = body?.Other.ToInt(),
                Emergency         = body?.Emergency.ToInt(),
                Launchpad         = body?.Launchpad.ToInt(),
                Mission           = body?.Mission.ToInt(),
                Staging           = body?.Staging.ToInt(),
                Other_comment     = body?.Other_comment
            };

            obj._context = _context;
            await obj.InsertAsync();

            return(new OkObjectResult(body));
        }