private NewMenu GetData(SQLiteDataReader reader, string userId) { Clients.Client client = new Clients.Client(); NewMenu x = new NewMenu(); x.id = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0); x.title = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1); x.diet = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2); x.date = reader.GetValue(3) == DBNull.Value ? DateTime.UtcNow.ToString() : reader.GetString(3); x.note = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4); x.userId = reader.GetValue(5) == DBNull.Value ? "" : reader.GetString(5); x.client = (reader.GetValue(6) == DBNull.Value || reader.GetValue(7) == DBNull.Value) ? new Clients.NewClient() : client.GetClient(reader.GetString(7), reader.GetString(6)); x.userGroupId = reader.GetValue(7) == DBNull.Value ? "" : reader.GetString(7); x.energy = reader.GetValue(8) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(8)); string data = reader.GetValue(9) == DBNull.Value ? null : reader.GetString(9); if (!string.IsNullOrWhiteSpace(data)) { x.data = JsonConvert.DeserializeObject <Data>(data); // new sistem: menu saved in db } else { string jsonData = GetJsonFile(userId, x.id); // old sistem: menu saved in json file. if (!string.IsNullOrWhiteSpace(jsonData)) { x.data = JsonConvert.DeserializeObject <Data>(jsonData); } } if (x.data.selectedFoods.Count == 0) { x.data.selectedFoods = new List <Foods.NewFood>(); x.data.selectedInitFoods = new List <Foods.NewFood>(); Meals M = new Meals(); x.data.meals = M.LoadData(); } if (x.data != null) { x.splitMealDesc = MealTitleDesc(x.data.meals); } x.client.clientData = new ClientsData.NewClientData(); string myMeals = reader.GetValue(10) == DBNull.Value ? null : reader.GetString(10); if (!string.IsNullOrWhiteSpace(myMeals)) { x.client.clientData.myMeals = JsonConvert.DeserializeObject <MyMeals.NewMyMeals>(myMeals); // new sistem: myMeals saved in db } else { x.client.clientData.myMeals = JsonConvert.DeserializeObject <MyMeals.NewMyMeals>(GetMyMealsJsonFile(userId, x.id)); // old sistem: myMeals saved in json file. } return(x); }