public virtual async Task<Dinner> CreateDinnerAsync(Dinner dinner) { var rsvp = new Rsvp { UserName = dinner.UserName }; dinner.Rsvps = new List<Rsvp> { rsvp }; _database.Add(dinner); _database.Add(rsvp); await _database.SaveChangesAsync(); return dinner; }
public virtual async Task<Rsvp> CreateRsvpAsync(Dinner dinner, string userName) { Rsvp rsvp = null; if (dinner != null) { if (dinner.IsUserRegistered(userName)) { rsvp = dinner.Rsvps.SingleOrDefault(r => string.Equals(r.UserName, userName, StringComparison.OrdinalIgnoreCase)); } else { rsvp = new Rsvp { UserName = userName }; dinner.Rsvps.Add(rsvp); _database.Add(rsvp); await _database.SaveChangesAsync(); } } return rsvp; }