// returns the id of the new list public static int?CreateNewList(IDbConnection dbConnection, string userToken, string listName = "New List") { string listId; int userId; User user = UserFactory.LoadSingleByToken(userToken); string checkedListName = FactoryUtils.CheckInput(listName, 0, 30, @"^[a-zA-Z0-9!'_\-\.\s]*$"); // if listName is bad don't create if (checkedListName == null) { return(null); } // if user doesn't exist don't create if (user != null) { userId = user.Id; } else { return(null); } dbConnection.Insert("lists", new KeyValuePair <string, object>[] { Pairing.Of("name", checkedListName), Pairing.Of("owner", userId) }).Execute(); listId = dbConnection.Take("lists").OrderBy("id", "desc").Limit(1).Execute()[0][0]; return(Int32.TryParse(listId, out int id) ? id : (int?)null); }
public static void UpdateListName(IDbConnection dbConnection, int id, string listName) { string checkedListName = FactoryUtils.CheckInput(listName, 0, 30, @"^[a-zA-Z0-9!'_\-\.\s]*$"); if (checkedListName != null) { dbConnection.Update("lists", Pairing.Of("name", checkedListName)).Where(Pairing.Of("id", id)).Execute(); } }
public static void UpdateBook(IDbConnection dbConnection, int id, string title, string author) { string checkedBookTitle = FactoryUtils.CheckInput(title, 0, 120, @"^[a-zA-Z0-9!.:;""'?\s]*$"); string checkedBookAuthor = FactoryUtils.CheckInput(author, 0, 30, @"^[a-zA-Z\s]*$"); // If title or author don't pass the CheckInput test then don't update the book if (checkedBookTitle == null || checkedBookAuthor == null) { return; } dbConnection.Update("books", Pairing.Of("title", $"{checkedBookTitle}")).Execute(); dbConnection.Update("books", Pairing.Of("author", $"{checkedBookAuthor}")).Execute(); }
// returns the id of the new book // if the book can't be created returns null public static int?CreateNewBook(IDbConnection dbConnection, string title, string author) { string bookId; string checkedBookTitle = FactoryUtils.CheckInput(title, 0, 120, @"^[a-zA-Z0-9!.:;""'?\s]*$"); string checkedBookAuthor = FactoryUtils.CheckInput(author, 0, 30, @"^[a-zA-Z\s]*$"); // If title or author don't pass the CheckInput test then don't create the book if (checkedBookTitle == null || checkedBookAuthor == null) { return(null); } dbConnection.Insert("books", new KeyValuePair <string, object>[] { Pairing.Of("title", $"{checkedBookTitle}"), Pairing.Of("author", $"{checkedBookAuthor}") }).Execute(); bookId = dbConnection.Take("books").OrderBy("id", "desc").Limit(1).Execute()[0][0]; return(Int32.TryParse(bookId, out int id) ? id : (int?)null); }
private static bool CheckFirstname(string firstname) { return(firstname.Length <= 40 && FactoryUtils.CheckInput(firstname, 1, 40, @"^[a-zA-Z]*$") != null); }
private static bool CheckPassword(string password) { return(password.Length <= 40 && FactoryUtils.CheckInput(password, 7, 40) != null); }
private static bool CheckUsername(string username) { return(username.Length <= 40 && FactoryUtils.CheckInput(username, 7, 40, @"^[a-zA-Z0-9_.@-]*$") != null); }