public async Task <IActionResult> UpdateSession([FromRoute] int id, [FromBody] ConferenceDTO.Session input) { var session = await _db.FindAsync <Session>(id); if (session == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } session.ID = input.ID; session.Title = input.Title; session.Abstract = input.Abstract; session.StartTime = input.StartTime; session.EndTime = input.EndTime; session.TrackId = input.TrackId; session.ConferenceID = input.ConferenceID; await _db.SaveChangesAsync(); var result = session.MapSessionResponse(); return(Ok(result)); }
public async Task <IActionResult> Post([FromBody] ConferenceDTO.Session input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var session = new Session { Title = input.Title, Slug = input.Title.ToSlug(), ConferenceID = input.ConferenceID, StartTime = input.StartTime, EndTime = input.EndTime, Abstract = input.Abstract, TrackId = input.TrackId }; _db.Sessions.Add(session); await _db.SaveChangesAsync(); var result = session.MapSessionResponse(); return(CreatedAtAction(nameof(Get), new { id = result.ID }, result)); }
public static Session MapSession(this ConferenceDTO.Session session) => new Session { Title = session.Title, ConferenceId = session.ConferenceId, StartTime = session.StartTime, EndTime = session.EndTime, Abstract = session.Abstract, TrackId = session.TrackId };
public async Task <Session> UpdateAsync(ConferenceDTO.Session session, CancellationToken cancellationToken = default(CancellationToken)) { var newSession = await _dbContext.Sessions.FindAsync(new object[] { session.ID }, cancellationToken); newSession.ID = session.ID; newSession.Title = session.Title; newSession.Abstract = session.Abstract; newSession.StartTime = session.StartTime; newSession.EndTime = session.EndTime; newSession.TrackId = session.TrackId; newSession.ConferenceId = session.ConferenceId; await _dbContext.SaveChangesAsync(cancellationToken); return(newSession); }
public async Task <ActionResult <SessionResponse> > Post(ConferenceDTO.Session input) { var session = new Data.Session { Title = input.Title, StartTime = input.StartTime, EndTime = input.EndTime, Abstract = input.Abstract, TrackId = input.TrackId }; context.Sessions.Add(session); await context.SaveChangesAsync(); var result = session.MapSessionResponse(); return(CreatedAtAction(nameof(Get), new { id = result.Id }, result)); }
public async Task <IActionResult> Put(int id, ConferenceDTO.Session input) { var session = await context.Sessions.FindAsync(id); if (session == null) { return(NotFound()); } session.Id = input.Id; session.Title = input.Title; session.Abstract = input.Abstract; session.StartTime = input.StartTime; session.EndTime = input.EndTime; session.TrackId = input.TrackId; await context.SaveChangesAsync(); return(NoContent()); }