public virtual void Insert(MeetingViewModel meeting) { if (meeting.Attendees == null) { meeting.Attendees = new int[0]; } if (string.IsNullOrEmpty(meeting.Title)) { meeting.Title = ""; } var entity = meeting.ToEntity(); foreach (var attendeeId in meeting.Attendees) { entity.MeetingAttendees.Add(new MeetingAttendee { AttendeeID = attendeeId }); } db.Meetings.Add(entity); db.SaveChanges(); meeting.MeetingID = entity.MeetingID; }
public void Create(ProductViewModel product) { var entity = new Product(); entity.ProductName = product.ProductName; entity.UnitPrice = product.UnitPrice; entity.UnitsInStock = (short)product.UnitsInStock; entity.Discontinued = product.Discontinued; entities.Products.Add(entity); entities.SaveChanges(); product.ProductID = entity.ProductID; }