public async Task <IActionResult> Post([FromBody] ConferenceDTO.Attendee input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var avatar = input.Avatar; if (avatar != null) { _db.Files.Add(avatar); await _db.SaveChangesAsync(); input.AvatarId = avatar.FileId; } var attendee = new Attendee { FirstName = input.FirstName, LastName = input.LastName, UserName = input.UserName, EmailAddress = input.EmailAddress, AvatarId = input.AvatarId }; _db.Attendees.Add(attendee); await _db.SaveChangesAsync(); var result = attendee.MapAttendeeResponse(); return(CreatedAtAction(nameof(Get), new { username = result.UserName }, result)); }
public async Task <IActionResult> Post([FromBody] ConferenceDTO.AttendeeDto input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var attendee = new Attendee { FirstName = input.FirstName, LastName = input.LastName, UserName = input.UserName }; _db.Attendees.Add(attendee); await _db.SaveChangesAsync(); var result = attendee.MapAttendeeResponse(); return(CreatedAtAction(nameof(Get), new { username = result.UserName }, result)); }