private static void CreateUser(CreateUserContext context) { context.Database.Initialize(true); var cmdText = File.ReadAllText(UsersDataInsertionQueryPath); var affectedRows = context.Database.ExecuteSqlCommand(cmdText); Console.WriteLine(affectedRows); }
public static void Main() { using (CreateUserContext context = new CreateUserContext()) { // CreateUser(context); // 8. Create User // GetUsersByEmailProvider(context); // 11. Get Users by Email Provider // RemoveInactiveUsers(context); // 12. Remove Inactive Users } }
private static void GetUsersByEmailProvider(CreateUserContext context) { Console.Write(GetUsersByEmailProviderUserLeadingToEnterTargetEmailEndMessage); var emailEndsWith = Console.ReadLine(); var cmdText = File.ReadAllText(GetUsersByEmailProviderSqlQueryPath); var selectedResult = context.Database.SqlQuery <string>( cmdText, new SqlParameter(GetUsersByEmailProviderParameterName, emailEndsWith)).ToList(); Console.WriteLine(string.Join(Environment.NewLine, selectedResult)); }
private static void RemoveInactiveUsers(CreateUserContext context) { Console.WriteLine(DeleteUsersWitLastLoginBeforeDateGetDateMessage); var deleteBefore = Console.ReadLine(); // Mark users as deleted var markCmdText = File.ReadAllText(MarkAsDeletedUserWithLoginBeforeDateQueryPath); var markAffectedRows = context.Database.ExecuteSqlCommand(markCmdText, new SqlParameter(MarkAsDeletedUserWithLoginBeforeDateParameterName, deleteBefore)); Console.WriteLine((markAffectedRows > 0) ? string.Format(MarkAsDeletedUsersMessageWhenAtLeastOneIsMarked, markAffectedRows) : MarkAsDeletedUsersMessageWhenNoOneIsMarked); // Delete all marked users var deleteCmdText = File.ReadAllText(DeleteAllMarkedUsersQueryPath); var deleteAffectedRows = context.Database.ExecuteSqlCommand(deleteCmdText); Console.WriteLine(string.Format(DeleteAllMarkedUsersMessage, deleteAffectedRows)); }