public bool CreateAdminUser(User user, Author author, Role role, out List <string> errorList) { errorList = new List <string>(); var saveSuccessful = true; using (var context = new DomainDBContext()) { try { LogQueryToVSTrace(context); AutoDetectChange(context, false); context.Roles.Add(role); context.Users.Add(user); context.Authors.Add(author); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var entityValidationError in context.GetValidationErrors()) { foreach (var error in entityValidationError.ValidationErrors) { errorList.Add("Entity: " + entityValidationError.Entry.Entity.GetType().FullName + " Property Name: " + error.PropertyName + " ErrorMessage: " + error.ErrorMessage); } } saveSuccessful = false; } finally { AutoDetectChange(context, true); } } return(saveSuccessful); }
/// <summary> /// Save changes to DB /// </summary> /// <returns>Action status</returns> public bool SaveChanges(DomainDBContext context) { context.SaveChanges(); return(true); }