public void DeleteRsvp(RSVP rsvp)
 {
     using (var connection = MvcApplication.GetOpenConnection())
     {
         connection.Execute(@"DELETE FROM rsvp where RsvpID = @id", new { id = rsvp.RsvpID });
     }
 }
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinner.HostedById = this.nerdIdentity.Name;
                dinner.HostedBy = this.nerdIdentity.FriendlyName;

                RSVP rsvp = new RSVP();
                rsvp.AttendeeNameId = this.nerdIdentity.Name;
                rsvp.AttendeeName = this.nerdIdentity.FriendlyName;

                dinner.RSVPs = new List<RSVP>();
                dinner.RSVPs.Add(rsvp);

                dinnerRepository.InsertOrUpdate(dinner);

                return RedirectToAction("Details", new { id = dinner.DinnerID });
            }

            return View(dinner);
        }
 private void UpdateRsvp(RSVP rsvp, DbConnection connection)
 {
     // Future has IsDirtyProperty...
     connection.Execute(@"update Rsvp set " +
         "DinnerID = @DinnerID, " +
         "AttendeeName = @AttendeeName, " +
         "AttendeeNameId = @AttendeeNameId " +
         "WHERE " +
         "DinnerId = @id ",
     new
     {
         id = rsvp.RsvpID,
         rsvp.DinnerID,
         rsvp.AttendeeName,
         rsvp.AttendeeNameId,
     });
 }
 private void InsertRsvp(RSVP rsvp, DbConnection connection)
 {
     rsvp.RsvpID = connection.Query<int>(@"insert into Rsvp " +
         "(DinnerId, AttendeeName, AttendeeNameId) " +
         "VALUES (@DinnerId, @AttendeeName, @AttendeeNameId); " +
         "SELECT CAST(scope_identity() as int)",
         new
         {
             rsvp.DinnerID,
             rsvp.AttendeeName,
             rsvp.AttendeeNameId,
         }).First();
 }
 private void InsertOrUpdateRsvp(RSVP rsvp, DbConnection connection)
 {
     if (rsvp.State == ObjectState.Added)
     {
         InsertRsvp(rsvp, connection);
     }
     else if (rsvp.State == ObjectState.Modified)
     {
         UpdateRsvp(rsvp, connection);
     }
 }
 public void InsertOrUpdate(RSVP rsvp)
 {
     using (var connection = MvcApplication.GetOpenConnection())
     {
         InsertOrUpdateRsvp(rsvp, connection);
     }
 }