示例#1
0
        // 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);
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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();
        }
示例#4
0
        // 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);
        }
示例#5
0
 private static bool CheckFirstname(string firstname)
 {
     return(firstname.Length <= 40 && FactoryUtils.CheckInput(firstname, 1, 40, @"^[a-zA-Z]*$") != null);
 }
示例#6
0
 private static bool CheckPassword(string password)
 {
     return(password.Length <= 40 && FactoryUtils.CheckInput(password, 7, 40) != null);
 }
示例#7
0
 private static bool CheckUsername(string username)
 {
     return(username.Length <= 40 && FactoryUtils.CheckInput(username, 7, 40, @"^[a-zA-Z0-9_.@-]*$") != null);
 }