예제 #1
0
        public async Task <IActionResult> UpdateConference([FromRoute] int id, [FromBody] ConferencePlanner.Models.Conference input)
        {
            var conference = await _db.FindAsync <Conference>(id);

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

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

            conference.Name = input.Name;

            await _db.SaveChangesAsync();

            var result = new ConferencePlanner.Models.ConferenceResponse
            {
                ID   = conference.ID,
                Name = conference.Name,
                //Sessions = ??,
                //Tracks = ??
                //Sessions = ??
            };

            return(Ok(result));
        }
예제 #2
0
        public async Task <IActionResult> CreateConference([FromBody] ConferencePlanner.Models.Conference input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var conference = new Conference
            {
                Name = input.Name
            };

            _db.Conferences.Add(conference);
            await _db.SaveChangesAsync();

            var result = new ConferencePlanner.Models.ConferenceResponse
            {
                ID   = conference.ID,
                Name = conference.Name,
                //Sessions = ??,
                //Tracks = ??
                //Sessions = ??
            };

            return(CreatedAtAction(nameof(GetConference), new { id = conference.ID }, result));
        }