Example #1
0
 public string Get(string userId, string id)
 {
     try {
         SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase));
         connection.Open();
         string        sql     = @"SELECT id, title, description, energy, mealGroup
                     FROM recipes
                     WHERE id = @id";
         SQLiteCommand command = new SQLiteCommand(sql, connection);
         command.Parameters.Add(new SQLiteParameter("id", id));
         NewRecipe        x      = new NewRecipe();
         Clients.Client   client = new Clients.Client();
         SQLiteDataReader reader = command.ExecuteReader();
         while (reader.Read())
         {
             x.id          = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
             x.title       = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
             x.description = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
             x.energy      = reader.GetValue(3) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(3));
             x.mealGroup   = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
             x.data        = JsonConvert.DeserializeObject <JsonFile>(GetJsonFile(userId, x.id));
             x.mealGroups  = InitMealGroups();
         }
         connection.Close();
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Example #2
0
        public IActionResult PostRecipe(NewRecipe model)
        {
            var recipe = mapper.Map(model);

            service.CreateNewRecipe(recipe);
            return(RedirectToAction(nameof(GetRecipes)));
        }
Example #3
0
 public string Save(string userId, NewRecipe x)
 {
     try {
         db.CreateDataBase(userId, db.recipes);
         db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, mealGroup);  //new column in recipes tbl.
         string sql = "";
         if (x.id == null)
         {
             x.id = Convert.ToString(Guid.NewGuid());
         }
         x.energy = x.data.selectedFoods.Sum(a => a.energy);
         SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase));
         connection.Open();
         SQLiteCommand command = new SQLiteCommand(sql, connection);
         sql     = @"BEGIN;
                 INSERT OR REPLACE INTO recipes (id, title, description, energy, mealGroup)
                 VALUES (@id, @title, @description, @energy, @mealGroup);
                 COMMIT;";
         command = new SQLiteCommand(sql, connection);
         command.Parameters.Add(new SQLiteParameter("id", x.id));
         command.Parameters.Add(new SQLiteParameter("title", x.title));
         command.Parameters.Add(new SQLiteParameter("description", x.description));
         command.Parameters.Add(new SQLiteParameter("energy", x.energy));
         command.Parameters.Add(new SQLiteParameter("mealGroup", x.mealGroup));
         command.ExecuteNonQuery();
         connection.Close();
         SaveJsonToFile(userId, x.id, JsonConvert.SerializeObject(x.data, Formatting.None));
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Example #4
0
        public IRecipeSlot SetRecipe(NewRecipe recipe)
        {
            currentItem = Inventory.CreateItem(recipe.RecipeOutcome);
            icon.sprite = currentItem.Icon;

            return(this);
        }
Example #5
0
    public static string GetRecipeImgPath(string userId, string recipeId, string recipeImg)
    {
        SharingRecipes SR = new SharingRecipes();
        NewRecipe      x  = SR.GetRecipeById(recipeId);

        return(string.Format("../upload/users/{0}/recipes/{1}/recipeimg/{2}", recipeId == x.id ? x.sharingData.recipeOwner.userGroupId : userId, recipeId, recipeImg));
    }
Example #6
0
 public string LoadAppRecipes(string lang)
 {
     try {
         //add mealGroup
         SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath(string.Format("~/App_Data/{0}", appDataBase)));
         connection.Open();
         string           sql     = string.Format(@"SELECT id, title, description, energy FROM recipes
                     WHERE language = '{0}'
                     ORDER BY rowid DESC", lang);
         SQLiteCommand    command = new SQLiteCommand(sql, connection);
         List <NewRecipe> xx      = new List <NewRecipe>();
         SQLiteDataReader reader  = command.ExecuteReader();
         while (reader.Read())
         {
             NewRecipe x = new NewRecipe();
             x.id          = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
             x.title       = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
             x.description = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
             x.energy      = reader.GetValue(3) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(3));
             xx.Add(x);
         }
         connection.Close();
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Example #7
0
    public NewRecipe InitData()
    {
        NewRecipe x = new NewRecipe();

        x.id          = null;
        x.title       = null;
        x.description = null;
        x.energy      = 0;
        x.mealGroup   = new MealGroup();
        JsonFile data = new JsonFile();

        data.selectedFoods     = new List <Foods.NewFood>();
        data.selectedInitFoods = new List <Foods.NewFood>();
        x.data          = data;
        x.mealGroups    = InitMealGroups(null);
        x.recipeImg     = null;
        x.recipeImgPath = null;
        x.isShared      = false;
        SharingRecipes sr = new SharingRecipes();

        x.sharingData = sr.InitSharingData();
        x.userId      = null;
        x.dishDesc    = new Meals.DishDesc();
        x.consumers   = 1;
        x.recipeOwner = new Users.NewUser();
        return(x);
    }
Example #8
0
 public string GetAppRecipe(string id, string lang)
 {
     try {
         NewRecipe x = new NewRecipe();
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath(string.Format("~/App_Data/{0}", appDataBase)))) {
             connection.Open();
             string sql = string.Format(@"SELECT id, title, description, energy FROM recipes WHERE id = '{0}'", id);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 Clients.Client client = new Clients.Client();
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         x.id          = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
                         x.title       = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                         x.description = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                         x.energy      = reader.GetValue(3) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(3));
                         x.data        = JsonConvert.DeserializeObject <JsonFile>(GetAppJsonFile(x.id, lang));
                     }
                 }
             }
             connection.Close();
         }
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Example #9
0
 public string Load(string userId)
 {
     try {
         db.CreateDataBase(userId, db.recipes);
         db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, mealGroup);  //new column in recipes tbl.
         SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase));
         connection.Open();
         string           sql     = @"SELECT id, title, description, energy, mealGroup
                     FROM recipes
                     ORDER BY rowid DESC";
         SQLiteCommand    command = new SQLiteCommand(sql, connection);
         List <NewRecipe> xx      = new List <NewRecipe>();
         SQLiteDataReader reader  = command.ExecuteReader();
         while (reader.Read())
         {
             NewRecipe x = new NewRecipe();
             x.id          = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
             x.title       = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
             x.description = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
             x.energy      = reader.GetValue(3) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(3));
             x.mealGroup   = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
             xx.Add(x);
         }
         connection.Close();
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Example #10
0
 public string Get(string userId, string id)
 {
     try {
         NewRecipe x = new NewRecipe();
         //db.CreateDataBase(userId, db.recipes);
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, MEAL_GROUP);  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, RECIPE_DATA, "TEXT");  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, CONSUMERS, "INTEGER");  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, USER_ID, "VARCHAR(50)");  //new column in recipes tbl.
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             string sql = @"SELECT id, title, description, energy, mealGroup, recipeData, consumers, userId FROM recipes WHERE id = @Id";
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.Parameters.Add(new SQLiteParameter("Id", id));
                 Clients.Client client = new Clients.Client();
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         x = GetData(reader, userId, true);
                     }
                 }
             }
         }
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, id, null, "Recipes", "Get");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Example #11
0
        public async Task <IActionResult> addrecipe([FromBody] NewRecipe recipeobj)
        {
            // Get recipeobj containing recipe info
            // Create a new entry in the Recipe table (model) with given info
            Recipe newrecipe = new Recipe();

            {
                newrecipe.Name        = recipeobj.Name;
                newrecipe.PicFilePath = recipeobj.PicFilePath;
                newrecipe.Calories    = recipeobj.Calories;
                newrecipe.PrepTime    = recipeobj.PrepTime;
            }
            try
            {
                // Add recipe to the Recipe table (model)
                _context.Recipe.Add(newrecipe);
                _context.SaveChanges();
                //return Content(Newtonsoft.Json.JsonConvert.SerializeObject(newrecipe));
                // Return a confirmation message
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }

            return(StatusCode(StatusCodes.Status200OK, JsonConvert.SerializeObject(new returnMsg {
                message = "Recipe added."
            })));
        }
Example #12
0
 public string Load(string userGroupId, string userId, int limit, int offset)
 {
     try {
         List <NewRecipe> xx = new List <NewRecipe>();
         //db.CreateDataBase(userId, db.recipes);
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, MEAL_GROUP);  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, RECIPE_DATA, "TEXT");  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, CONSUMERS, "INTEGER");  //new column in recipes tbl.
         //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, USER_ID, "VARCHAR(50)");  //new column in recipes tbl.
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userGroupId, dataBase))) {
             connection.Open();
             string sql = string.Format(@"SELECT id, title, description, energy, mealGroup, recipeData, consumers, userId FROM recipes
                     {0}
                     ORDER BY rowid DESC LIMIT {1} OFFSET {2}",
                                        !string.IsNullOrWhiteSpace(userId)
                             ? string.Format("WHERE userId = '{0}' {1}", userId, userId == userGroupId ? "OR userId IS NULL" : "")
                             : "", limit, offset);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         NewRecipe x = GetData(reader, userGroupId, true);
                         xx.Add(x);
                     }
                 }
             }
         }
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, null, userId, "Recipes", "Load");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Example #13
0
    private NewRecipe GetData(SQLiteDataReader reader, string userId, bool getJson)
    {
        NewRecipe x = new NewRecipe();

        x.id             = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
        x.title          = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
        x.description    = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
        x.energy         = reader.GetValue(3) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(3));
        x.mealGroup      = new MealGroup();
        x.mealGroup.code = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
        // x.mealGroup.title = GetMealGroupTitle(x.mealGroup.code);
        if (getJson)
        {
            string data = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5);
            if (!string.IsNullOrWhiteSpace(data))
            {
                x.data = JsonConvert.DeserializeObject <JsonFile>(data);  // new sistem: recipe saved in db
            }
            else
            {
                x.data = JsonConvert.DeserializeObject <JsonFile>(GetJsonFile(userId, x.id)); // old sistem: recipe saved in json file
            }
        }
        x.recipeImg     = GetRecipeImg(userId, x.id);
        x.recipeImgPath = GetRecipeImgPath(userId, x.id, x.recipeImg);
        x.mealGroups    = InitMealGroups(x.mealGroup.code);
        SharingRecipes SR = new SharingRecipes();

        x.isShared    = SR.Check(x.id);
        x.sharingData = SR.InitSharingData();
        // x.userId = userId;
        if (getJson)
        {
            x.dishDesc       = new Meals.DishDesc();
            x.dishDesc.title = x.title;
            x.dishDesc.desc  = x.description;
            x.dishDesc.id    = x.id;
        }
        x.consumers = reader.GetValue(6) == DBNull.Value ? 1 : reader.GetInt32(6);
        x.userId    = reader.GetValue(7) == DBNull.Value ? null : reader.GetString(7);
        if (string.IsNullOrWhiteSpace(x.userId))
        {
            x.userId = userId;
        }
        Users U = new Users();

        x.recipeOwner           = new Users.NewUser();
        x.recipeOwner.firstName = U.GetUserFullName(x.userId, true);
        if (x.data != null)
        {
            if (x.data.selectedFoods.Count > 0)
            {
                x.carbohydrates = x.data.selectedFoods.Sum(a => a.carbohydrates);
                x.proteins      = x.data.selectedFoods.Sum(a => a.proteins);
                x.fats          = x.data.selectedFoods.Sum(a => a.fats);
            }
        }
        return(x);
    }
Example #14
0
        public async Task Create_Recipe(NewRecipe recipe)
        {
            using var client = Factory.CreateClient();

            var(_, name) = await PostRecipeAsync(client, recipe);

            name.Should().Be(recipe.Name);
        }
 public async Task <IActionResult> AddRecipe([FromBody] NewRecipe input)
 {
     return(await SendCommandAsync(new AddRecipe(
                                       PeriodId.From(input.PeriodId),
                                       Amount.From(input.Amount),
                                       Label.From(input.Label),
                                       Pair.From(input.Pair),
                                       RecipeCategory.From(input.Category))));
 }
Example #16
0
        public async Task UpdateRecipeAsync_Success(int recipeId, NewRecipe newRecipe, FullRecipe recipe)
        {
            A.CallTo(() => recipeService.GetRecipeAsync(recipeId)).Returns(recipe);

            var result = await sut.UpdateRecipeAsync(recipeId, newRecipe).ConfigureAwait(false);

            A.CallTo(() => recipeService.UpdateRecipeAsync(recipeId, newRecipe)).MustHaveHappenedOnceExactly();
            result.Should().Be(recipe);
        }
Example #17
0
        public async Task Create_and_Update_Recipe(NewRecipe recipe, NewRecipe newRecipe)
        {
            using var client = Factory.CreateClient();

            var(id, _) = await PostRecipeAsync(client, recipe);

            var(_, name) = await PutRecipeAsync(client, id, newRecipe);

            name.Should().Be(newRecipe.Name);
        }
Example #18
0
        public async Task Create_And_Get_Recipe(NewRecipe recipe)
        {
            using var client = Factory.CreateClient();

            var(id, _) = await PostRecipeAsync(client, recipe);

            var(getId, name) = await GetRecipeAsync(client, id);

            getId.Should().Be(id);
            name.Should().Be(recipe.Name);
        }
Example #19
0
 public string SaveAsFood(string userId, NewRecipe recipe, string unit)
 {
     try {
         NewRecipe     x    = JsonConvert.DeserializeObject <NewRecipe>(Save(userId, recipe));
         Foods.NewFood food = TransformRecipeToFood(recipe);
         food.id   = x.id;
         food.unit = unit;
         MyFoods mf = new MyFoods();
         mf.Save(userId, food);
         return("saved");
     } catch (Exception e) { return(e.Message); }
 }
Example #20
0
 public string SaveAsFood(string userId, NewRecipe recipe, string unit)
 {
     try {
         NewRecipe     x    = JsonConvert.DeserializeObject <NewRecipe>(Save(userId, recipe));
         Foods.NewFood food = TransformRecipeToFood(recipe);
         food.id   = x.id;
         food.unit = unit;
         MyFoods mf = new MyFoods();
         mf.Save(userId, food);
         return(JsonConvert.SerializeObject("saved", Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, recipe.id, null, "Recipes", "SaveAsFood");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Example #21
0
        public async Task UpdateRecipeAsync(int recipeId, NewRecipe newRecipe)
        {
            if (newRecipe is null)
            {
                throw new ArgumentNullException(nameof(newRecipe));
            }

            var ingredients = newRecipe.Ingredients.Select(mapper.Map <DBModel.RecipeIngredient>);

            using var tran = transactionFactory.BeginTransaction();
            await recipeRepository.UpdateRecipeAsync(recipeId, newRecipe.Name, tran).ConfigureAwait(false);

            await recipeRepository.UpsertRecipeIngredientsAsync(recipeId, ingredients, tran).ConfigureAwait(false);

            tran.Commit();
        }
Example #22
0
    public string Init()
    {
        NewRecipe x = new NewRecipe();

        x.id          = null;
        x.title       = null;
        x.description = null;
        x.energy      = 0;
        x.mealGroup   = null;
        JsonFile data = new JsonFile();

        data.selectedFoods     = new List <Foods.NewFood>();
        data.selectedInitFoods = new List <Foods.NewFood>();
        x.data       = data;
        x.mealGroups = InitMealGroups();
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }
Example #23
0
 private bool Check(string userId, NewRecipe x)
 {
     try {
         bool             result     = false;
         SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase));
         connection.Open();
         string           sql     = string.Format("SELECT EXISTS(SELECT id FROM recipes WHERE LOWER(title) = '{0}')", x.title.ToLower());
         SQLiteCommand    command = new SQLiteCommand(sql, connection);
         SQLiteDataReader reader  = command.ExecuteReader();
         while (reader.Read())
         {
             result = reader.GetBoolean(0);
         }
         connection.Close();
         return(result);
     } catch (Exception e) { return(false); }
 }
Example #24
0
        public async Task UpdateRecipeSuccess(int recipeId, string recipeName, IEnumerable <DBModel.RecipeIngredient> ingredients)
        {
            var newRecipe = new NewRecipe
            {
                Name        = recipeName,
                Ingredients = ingredients.Select(x => new RecipeIngredient
                {
                    Amount = x.Amount,
                    Name   = x.IngredientName,
                    Unit   = x.UnitName
                }).ToList()
            };

            await sut.UpdateRecipeAsync(recipeId, newRecipe).ConfigureAwait(false);

            A.CallTo(() => recipeRepository.UpdateRecipeAsync(recipeId, recipeName, transaction)).MustHaveHappenedOnceExactly();
            A.CallTo(() => recipeRepository.UpsertRecipeIngredientsAsync(recipeId, A <IEnumerable <DBModel.RecipeIngredient> > ._, transaction)).MustHaveHappenedOnceExactly();
        }
Example #25
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (label1.Visible == true)
            {
                if (label1.Text == "Recipe Name")
                {
                    NewRecipe nr = new NewRecipe();
                    nr.updatelistbox += new NewRecipe.UpdateListbox(btnModule_Click);
                    nr.ShowDialog();
                }
                else if (label1.Text == "Cassette Recipe Name")
                {
                    CassetteWafer cassette = new CassetteWafer();
                    cassette.updatelistbox += new CassetteWafer.UpdateListbox(btnCassette_Click);

                    OpenCassetteWafer opencassettewafer = new OpenCassetteWafer();
                    opencassettewafer.updatelistbox += new OpenCassetteWafer.UpdateListbox(btnCassette_Click);


                    cassette.ShowDialog();


                    //    cassette.
                }

                else if (label1.Text == "Conditioning Recipe Name")
                {
                    NewConditioning newConditioning = new NewConditioning();
                    newConditioning.updatelistview += new NewConditioning.UpdateListView(btnConditioning_Click);

                    OpenConditionRecipe openconditionrecipe = new OpenConditionRecipe();
                    openconditionrecipe.updatelistbox += new OpenConditionRecipe.UpdateListbox(btnConditioning_Click);


                    newConditioning.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Please select Cassette or Module");
            }
        }
Example #26
0
        public void btnCassette_Click(object sender, EventArgs e)
        {
            label1.Visible            = true;
            label2.Visible            = true;
            tbrecipename.Visible      = true;
            tbrecipeDate.Visible      = true;
            listboxRecipeName.Visible = true;
            // this.Refresh();
            listboxRecipeName.Items.Clear();
            label1.Text = "Cassette Recipe Name";
            labelstring = "Cassette Recipe Name";

            tbrecipename.Text = "";
            tbrecipeDate.Text = "";
            NewRecipe nr = new NewRecipe();

            //  listboxRecipeName.Items.Add(nr.recipeName);
            tbrecipename.ReadOnly = true;
            tbrecipeDate.ReadOnly = true;
            // TODO: 這行程式碼會將資料載入 'recipeTypeDataSet.recipe' 資料表。您可以視需要進行移動或移除。
            // this.recipeTableAdapter.Fill(this.recipeTypeDataSet.recipe);
            scsb                    = new SqlConnectionStringBuilder();
            scsb.DataSource         = Form1.datasource;
            scsb.InitialCatalog     = "RecipeType";
            scsb.IntegratedSecurity = true;
            SqlConnection con = new SqlConnection(scsb.ToString());

            con.Open();
            string        strSql = "select * from CassetteRecipe ";
            SqlCommand    cmd    = new SqlCommand(strSql, con);
            SqlDataReader reader = cmd.ExecuteReader();



            while (reader.Read())
            {
                listboxRecipeName.Items.Add(reader["CassetteRecipeName"]);
            }

            con.Close();
        }
Example #27
0
    public string Search(string userGroupId, string userId, string query, string mealGroup, double?energyMin, double?energyMax)
    {
        List <NewRecipe> xx = new List <NewRecipe>();

        try {
            //db.CreateDataBase(userId, db.recipes);
            //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, MEAL_GROUP);  //new column in recipes tbl.
            //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, RECIPE_DATA, "TEXT");  //new column in recipes tbl.
            //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, CONSUMERS, "INTEGER");  //new column in recipes tbl.
            //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.recipes, USER_ID, "VARCHAR(50)");  //new column in recipes tbl.
            Global G = new Global();
            query = G.SpecChrSearchQuery(query);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userGroupId, dataBase))) {
                connection.Open();
                string sql = string.Format(@"SELECT id, title, description, energy, mealGroup, recipeData, consumers, userId FROM recipes
                                {0} {1} {2} {3} {4} ORDER BY rowid DESC"
                                           , (string.IsNullOrWhiteSpace(query) && string.IsNullOrEmpty(mealGroup) && energyMin == null && energyMax == null && string.IsNullOrWhiteSpace(userId)) ? "" : "WHERE"
                                           , !string.IsNullOrWhiteSpace(query) ? string.Format("(LOWER(title) LIKE LOWER('%{0}%') OR LOWER(description) LIKE LOWER('%{0}%') OR LOWER(id) = LOWER('{0}'))", query) : ""
                                           , !string.IsNullOrEmpty(mealGroup) ? string.Format(" {0} mealGroup LIKE '%{1}%'", !string.IsNullOrEmpty(query) ? "AND" : "", mealGroup) : ""
                                           , (energyMin >= 0 && energyMax > 0) ? string.Format(" {0} (CAST(energy AS DOUBLE) >= {1} AND CAST(energy as DOUBLE) <= {2})", !string.IsNullOrEmpty(query) || !string.IsNullOrEmpty(mealGroup) ? "AND" : "", energyMin, energyMax) : ""
                                           , !string.IsNullOrWhiteSpace(userId)
                                                    ? string.Format(" {0} userId = '{1}' {2}"
                                                                    , !string.IsNullOrEmpty(query) || !string.IsNullOrEmpty(mealGroup) || (energyMin >= 0 && energyMax > 0) ? "AND" : "", userId, userId == userGroupId ? "OR userId IS NULL" : "")
                                                    : "");
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewRecipe x = GetData(reader, userGroupId, true);
                            xx.Add(x);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, query, userId, "Recipes", "Search");
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        }
    }
Example #28
0
        public Recipe Map(NewRecipe model)
        {
            var recipe = new Recipe
            {
                Id                 = Guid.NewGuid(),
                Description        = model.Description,
                Title              = model.Title,
                SourceURL          = model.SourceURL,
                CookingTimeMinutes = model.CookingTimeMinutes,
                CookingTypeId      = model.CookingTypeId,
                DishTypeId         = model.DishTypeId,
                RecipeTypeId       = model.RecipeTypeId,
                Stages             = model.Stages?.Select(s => stageMapper.Map(s)).ToList(),
                Ingredients        = model.Ingredients?.Select(i => ingredientMapper.Map(i)).ToList()
            };

            if (model.Thumbnail != null)
            {
                recipe.Thumbnail = GetThumbnail(model.Thumbnail);
            }
            return(recipe);
        }
Example #29
0
 private Foods.NewFood TransformRecipeToFood(NewRecipe recipe)
 {
     try {
         Foods         foods = new Foods();
         Foods.NewFood f     = foods.GetFoodsTotal(recipe.data.selectedFoods);
         Foods.NewFood x     = new Foods.NewFood();
         x.id                        = null;
         x.food                      = recipe.title;
         x.quantity                  = 1;
         x.mass                      = f.mass;
         x.energy                    = f.energy;
         x.carbohydrates             = f.carbohydrates;
         x.proteins                  = f.proteins;
         x.fats                      = f.fats;
         x.servings.cerealsServ      = f.servings.cerealsServ;
         x.servings.vegetablesServ   = f.servings.vegetablesServ;
         x.servings.fruitServ        = f.servings.fruitServ;
         x.servings.meatServ         = f.servings.meatServ;
         x.servings.milkServ         = f.servings.milkServ;
         x.servings.fatsServ         = f.servings.fatsServ;
         x.servings.otherFoodsServ   = f.servings.otherFoodsServ;
         x.servings.otherFoodsEnergy = f.servings.otherFoodsEnergy;
         x.starch                    = f.starch;
         x.totalSugar                = f.totalSugar;
         x.glucose                   = f.glucose;
         x.fructose                  = f.fructose;
         x.saccharose                = f.saccharose;
         x.maltose                   = f.maltose;
         x.lactose                   = f.lactose;
         x.fibers                    = f.fibers;
         x.saturatedFats             = f.saturatedFats;
         x.monounsaturatedFats       = f.monounsaturatedFats;
         x.polyunsaturatedFats       = f.polyunsaturatedFats;
         x.trifluoroaceticAcid       = f.trifluoroaceticAcid;
         x.cholesterol               = f.cholesterol;
         x.sodium                    = f.sodium;
         x.potassium                 = f.potassium;
         x.calcium                   = f.calcium;
         x.magnesium                 = f.magnesium;
         x.phosphorus                = f.phosphorus;
         x.iron                      = f.iron;
         x.copper                    = f.copper;
         x.zinc                      = f.zinc;
         x.chlorine                  = f.chlorine;
         x.manganese                 = f.manganese;
         x.selenium                  = f.selenium;
         x.iodine                    = f.iodine;
         x.retinol                   = f.retinol;
         x.carotene                  = f.carotene;
         x.vitaminD                  = f.vitaminD;
         x.vitaminE                  = f.vitaminE;
         x.vitaminB1                 = f.vitaminB1;
         x.vitaminB2                 = f.vitaminB2;
         x.vitaminB3                 = f.vitaminB3;
         x.vitaminB6                 = f.vitaminB6;
         x.vitaminB12                = f.vitaminB12;
         x.folate                    = f.folate;
         x.pantothenicAcid           = f.pantothenicAcid;
         x.biotin                    = f.biotin;
         x.vitaminC                  = f.vitaminC;
         x.vitaminK                  = f.vitaminK;
         return(x);
     } catch (Exception e) {
         return(new Foods.NewFood());
     }
 }
Example #30
0
        private void MenuRecipeNew_Click(object sender, RoutedEventArgs e)
        {
            NewRecipe newRecipePage = new NewRecipe();

            Content = newRecipePage;
        }