コード例 #1
0
        public async Task <IActionResult> CreateConference([FromBody] ConferenceDTO.GlobalConference input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var gc = new GlobalConference
            {
                Name        = input.Name,
                Description = input.Description,
                StartDate   = input.StartDate,
                Summary     = input.Summary,
                EndDate     = input.EndDate,
                Location    = input.Location,
                TagLine     = input.TagLine
            };

            _db.GlobalConferences.Add(gc);
            await _db.SaveChangesAsync();

            var result = new ConferenceDTO.GlobalConferenceResponse
            {
                ID          = gc.ID,
                Name        = gc.Name,
                Description = gc.Description,
                StartDate   = gc.StartDate,
                Summary     = gc.Summary,
                EndDate     = gc.EndDate,
                Location    = gc.Location,
                TagLine     = gc.TagLine
            };

            return(CreatedAtAction(nameof(GetGlobalConference), new { id = gc.ID }, result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateConference([FromRoute] Guid id, [FromBody] ConferenceDTO.GlobalConference input)
        {
            var gc = await _db.FindAsync <GlobalConference>(id);

            if (gc == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            gc.Name = input.Name;

            await _db.SaveChangesAsync();

            var result = new ConferenceDTO.GlobalConferenceResponse
            {
                ID          = gc.ID,
                Name        = gc.Name,
                Description = gc.Description,
                StartDate   = gc.StartDate,
                Summary     = gc.Summary,
                EndDate     = gc.EndDate,
                Location    = gc.Location,
                TagLine     = gc.TagLine
            };

            return(Ok(result));
        }