public void AddAuthor(author newAuthor) { using (var dbModel = new LMSDataModelEntities()) { dbModel.authors.AddObject(newAuthor); dbModel.ObjectStateManager.ChangeObjectState(newAuthor, System.Data.EntityState.Added); var saveCount = dbModel.SaveChanges(); if (saveCount < 1) { throw new Exception("Fail to insert Author " + newAuthor.FirstName +" " +newAuthor.LastName + " into DB"); } } }
private void Fixupauthor(author previousValue) { if (previousValue != null && previousValue.bookauthors.Contains(this)) { previousValue.bookauthors.Remove(this); } if (author != null) { if (!author.bookauthors.Contains(this)) { author.bookauthors.Add(this); } if (AuthorId != author.Id) { AuthorId = author.Id; } } }