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)); }
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); }
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); }
private Global.Response DeleteRecord(string userId, string id, SQLiteConnection connection, string tbl) { Global.Response response = new Global.Response(); try { string sql = null; switch (tbl) { case "clients": sql = string.Format(@"DELETE FROM clients WHERE clientId = '{0}'; DELETE FROM clientsdata WHERE clientId = '{0}'", id); F.DeleteClientFolder(userId, id); break; case "menus": sql = string.Format("DELETE FROM menues WHERE id = '{0}'", id); F.DeleteJsonFile(userId, id, "menues", null); break; case "weeklymenus": sql = string.Format("DELETE FROM weeklymenus WHERE id = '{0}'", id); break; case "recipes": sql = string.Format("DELETE FROM recipes WHERE id = '{0}'", id); F.DeleteJsonFile(userId, id, "recipes", null); /******* Delete from My Foods if exists (Recipes as My Food) *******/ MyFoods mf = new MyFoods(); mf.Delete(userId, id); F.DeleteRecipeFolder(userId, id); /******* Delete from My Sharing Recipes if exists *******/ SharingRecipes SR = new SharingRecipes(); SR.DeleteSharedRecipe(id); break; case "foods": sql = string.Format("DELETE FROM myfoods WHERE id = '{0}'", id); break; case "appointments": sql = string.Format("DELETE FROM scheduler WHERE rowid = '{0}'", id); break; default: break; } using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { command.ExecuteNonQuery(); } response.isSuccess = true; response.msg = "deleted"; return(response); } catch (Exception e) { response.isSuccess = false; response.msg = e.Message; L.SendErrorLog(e, id, userId, "Archives", "DeleteRecord"); return(response); } }
public string Delete(string userGroupId, string id, string userId, int adminType, string authorId) { var x = new Global.Response(); try { if (string.IsNullOrEmpty(userGroupId) || string.IsNullOrEmpty(id)) { x.isSuccess = false; x.msg = "tryAgainMsg"; return(JsonConvert.SerializeObject(x, Formatting.None)); } Global G = new Global(); if (!G.CheckUserPermission(userGroupId, userId, adminType, authorId)) { x.isSuccess = false; x.msg = "deleteRecipePermissionAlert"; return(JsonConvert.SerializeObject(x, Formatting.None)); } using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userGroupId, dataBase))) { connection.Open(); string sql = @"BEGIN; DELETE FROM recipes WHERE id = @Id; COMMIT;"; using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { command.Parameters.Add(new SQLiteParameter("Id", id)); command.ExecuteNonQuery(); } } Files F = new Files(); F.DeleteJsonFile(userGroupId, id, "recipes", null); /******* Delete from My Foods if exists (Recipes as My Food) *******/ MyFoods mf = new MyFoods(); mf.Delete(userGroupId, id); /*******************************************************************/ F.DeleteRecipeFolder(userGroupId, id); /******* Delete from My Sharing Recipes if exists *******/ SharingRecipes SR = new SharingRecipes(); SR.DeleteSharedRecipe(id); /*******************************************************************/ x.isSuccess = true; x.msg = "deleted"; return(JsonConvert.SerializeObject(x, Formatting.None)); } catch (Exception e) { x.isSuccess = false; x.msg = e.Message; L.SendErrorLog(e, id, null, "Recipes", "Delete"); return(JsonConvert.SerializeObject(x, Formatting.None)); } }