Exemple #1
0
        public void Create(Recipe recipe)
        {
            var parsedDirections  = String.Join(";", recipe.Directions).Replace("'", "\\'");
            var parsedIngredients = String.Join(";", recipe.Ingredients).Replace("'", "\\'");
            var query             = $"insert into recipes(title, accountId, createdAt, description, calories, directions, ingredients, public) " +
                                    $"values('{recipe.Title.Replace("'", "\\'")}', {recipe.AccountId}, current_timestamp(), '{recipe.Description}', {recipe.Calories}, '{parsedDirections}', '{parsedIngredients}', {recipe.Public.Value})";

            MySqlDatabase.ExecuteNoneQuery(query);
        }
        public bool Create(CreateAccountPostData data)
        {
            bool success = false;

            MySqlDatabase.ExecuteNoneQuery(
                $"insert into accounts(username, password, email, authKey) values ('{data.Username}','{data.Password}','{data.Email}','{Hash.Sha256(data.Username + data.Password)}')",
                count =>
            {
                if (count == 1)
                {
                    success = true;
                }
            }
                );
            return(success);
        }
Exemple #3
0
        public void UpdateAccount(Account account)
        {
            var query = "update accounts set ";

            if (account.FirstName != null)
            {
                query += $"firstName = '{account.FirstName}',";
            }
            if (account.LastName != null)
            {
                query += $"lastName = '{account.LastName}',";
            }
            if (account.Email != null)
            {
                query += $"email = '{account.Email}',";
            }
            if (account.IsMale.HasValue)
            {
                query += $"isMale = {account.IsMale},";
            }
            if (account.Birthdate.HasValue)
            {
                query += $"birthdate = str_to_date('{account.Birthdate.Value.ToString("dd-MM-yyyy")}','%d-%m-%Y'),";
            }
            if (account.Weight.HasValue)
            {
                query += $"weight = {account.Weight},";
            }
            if (account.Height.HasValue)
            {
                query += $"height = {account.Height},";
            }
            if (account.Description != null)
            {
                query += $"description = '{account.Description}',";
            }
            query = query.Remove(query.Length - 1);
            MySqlDatabase.ExecuteNoneQuery(query + $" where accounts.id = {account.Id}");
        }
Exemple #4
0
        public void Update(int id, Recipe recipe)
        {
            var sql = "update recipes set ";

            if (recipe.Title != null)
            {
                sql += $"title = '{recipe.Title.Replace("'", "\\'")}',";
            }
            if (recipe.Description != null)
            {
                sql += $"description = '{recipe.Description.Replace("'", "\\'")}',";
            }
            if (recipe.Calories.HasValue)
            {
                sql += $"calories = {recipe.Calories.Value},";
            }
            if (recipe.Directions != null)
            {
                sql += $"directions = '{String.Join(";", recipe.Directions).Replace("'", "\\'")}',";
            }
            if (recipe.Ingredients != null)
            {
                sql += $"ingredients = '{String.Join(";", recipe.Ingredients).Replace("'", "\\'")}',";
            }
            if (recipe.Public.HasValue)
            {
                sql += $"public = {recipe.Public.Value},";
            }

            sql = sql.Remove(sql.Length - 1);
            if (sql != "update recipes set ")
            {
                sql += " where id = " + id;
                MySqlDatabase.ExecuteNoneQuery(sql);
            }
        }
Exemple #5
0
 public void Create(CreateAccountPostData data)
 {
     MySqlDatabase.ExecuteNoneQuery($"insert into accounts(username, password, email, authKey) values ('{data.Username}','{data.Password}','{data.Email}','{Hash.Sha256(data.Username + data.Password)}')");
 }
Exemple #6
0
 public void Create(int accountId, int recipeId)
 {
     MySqlDatabase.ExecuteNoneQuery($"insert into eatenRecipes(accountId, recipeId, date) values({accountId}, {recipeId}, current_date())");
 }
Exemple #7
0
 public void Delete(int id)
 {
     MySqlDatabase.ExecuteNoneQuery("delete from recipes where id = " + id);
 }