public static Model.Author GetAuthor(string authorName) { var dbAuthor = SessionState.dbBookstore.Authors.FirstOrDefault(x => x.Name == authorName); if (dbAuthor == null && !string.IsNullOrEmpty(authorName)) { dbAuthor = new Author { Name = authorName }; SessionState.dbBookstore.Authors.Add(dbAuthor); try { SessionState.dbBookstore.SaveChanges(); } catch (DbEntityValidationException exception) { SessionState.dbBookstore.Authors.Remove(dbAuthor); Console.WriteLine("Validation error. Author Name is too long or just missing."); } } return(dbAuthor); }
public static Model.Author GetAuthor(string authorName) { var dbAuthor = SessionState.dbBookstore.Authors.FirstOrDefault(x => x.Name == authorName); if (dbAuthor == null && !string.IsNullOrEmpty(authorName)) { dbAuthor = new Author { Name = authorName }; SessionState.dbBookstore.Authors.Add(dbAuthor); try { SessionState.dbBookstore.SaveChanges(); } catch (DbEntityValidationException exception) { SessionState.dbBookstore.Authors.Remove(dbAuthor); Console.WriteLine("Validation error. Author Name is too long or just missing."); } } return dbAuthor; }