Exemplo n.º 1
0
 private MyMeals.NewMyMeals GetMyMeals(string userId, string clientId)
 {
     MyMeals.NewMyMeals x = new MyMeals.NewMyMeals();
     x = JsonConvert.DeserializeObject <MyMeals.NewMyMeals>(GetJsonFile(userId, clientId));
     if (x == null)
     {
         x = new MyMeals.NewMyMeals();
     }
     return(x);
 }
Exemplo n.º 2
0
 private void SaveMyMeals(string userId, string clientId, MyMeals.NewMyMeals myMeals)
 {
     try {
         if (myMeals.data != null)
         {
             string path     = string.Format("~/App_Data/users/{0}/clients/{1}", userId, clientId);
             string filepath = string.Format("{0}/myMeals.json", path);
             CreateFolder(path);
             WriteFile(filepath, JsonConvert.SerializeObject(myMeals, Formatting.None));
         }
     }
     catch (Exception e) {}
 }
Exemplo n.º 3
0
    public string Save(string userId, NewMenu x, Users.NewUser user, MyMeals.NewMyMeals myMeals)
    {
        db.CreateDataBase(userId, db.menues);
        if (x.id == null && Check(userId, x) != false)
        {
            return("error");
        }
        else
        {
            try {
                string sql = null;
                if (x.id == null)
                {
                    x.id = Convert.ToString(Guid.NewGuid());
                    sql  = string.Format(@"BEGIN;
                    INSERT INTO menues (id, title, diet, date, note, userId, clientId, userGroupId, energy)
                    VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}');
                    COMMIT;", x.id, x.title, x.diet, x.date, x.note, user.userId, x.client.clientId, string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId, x.energy);
                }
                else
                {
                    sql = string.Format(@"BEGIN;
                    UPDATE menues SET
                    title = '{1}', diet = '{2}', date = '{3}', note = '{4}', userId = '{5}', clientId = '{6}', userGroupId = '{7}', energy = '{8}'
                    WHERE id = '{0}';
                    COMMIT;", x.id, x.title, x.diet, x.date, x.note, user.userId, x.client.clientId, string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId, x.energy);
                }
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                    connection.Open();
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                        command.ExecuteNonQuery();
                    }
                    connection.Close();
                }

                SaveJsonToFile(userId, x.id, JsonConvert.SerializeObject(x.data, Formatting.None));
                if (myMeals != null)
                {
                    if (myMeals.data != null)
                    {
                        if (myMeals.data.meals.Count > 2)
                        {
                            SaveMyMealsJsonToFile(userId, x.id, JsonConvert.SerializeObject(myMeals, Formatting.None));
                        }
                    }
                }
                string json = JsonConvert.SerializeObject(x, Formatting.None);
                return(json);
            } catch (Exception e) { return(e.Message); }
        }
    }
Exemplo n.º 4
0
 private void SaveMyMeals(string userId, string clientId, MyMeals.NewMyMeals myMeals)
 {
     try {
         if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(clientId))
         {
             return;
         }
         string sql = string.Format(@"BEGIN;
                                     UPDATE clients SET myMeals = '{1}' WHERE clientId = '{0}';
                                     COMMIT;", clientId, JsonConvert.SerializeObject(myMeals, Formatting.None));
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.ExecuteNonQuery();
             }
         }
         Files F = new Files();
         F.DeleteClientJsonFile(userId, clientId, "myMeals");
     } catch (Exception e) {
         L.SendErrorLog(e, clientId, userId, "ClientsData", "SaveMyMeals");
     }
 }
Exemplo n.º 5
0
    public string Save(string userId, NewMenu x, Users.NewUser user, MyMeals.NewMyMeals myMeals)
    {
        SaveResponse r = new SaveResponse();

        try {
            //db.CreateDataBase(userId, db.menues);
            db.AddColumn(userId, db.GetDataBasePath(userId, userDataBase), db.menues, MENU_DATA, "TEXT"); //new column in menues tbl.
            db.AddColumn(userId, db.GetDataBasePath(userId, userDataBase), db.menues, MY_MEALS, "TEXT");  //new column in menues tbl.
            if (string.IsNullOrWhiteSpace(x.id) && Check(userId, x) != false)
            {
                r.data      = x;
                r.msg       = "there is already a menu with the same name";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            if (!G.CheckUserPermission(user, x.userId))
            {
                r.data      = x;
                r.msg       = "you can only save menus that you have created yourself";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }

            string myMealsData = null;
            if (myMeals != null)
            {
                if (myMeals.data != null)
                {
                    if (myMeals.data.meals.Count > 2)
                    {
                        myMealsData = JsonConvert.SerializeObject(myMeals, Formatting.None);
                    }
                }
            }
            x.data.meals = CombineTitleDesc(x);
            string sql = null;
            if (string.IsNullOrEmpty(x.id))
            {
                x.id = Guid.NewGuid().ToString();
                sql  = @"BEGIN;
                INSERT INTO menues (id, title, diet, date, note, userId, clientId, userGroupId, energy, menuData, myMeals)
                VALUES (@Id, @Title, @Diet, @Date, @Note, @UserId, @ClientId, @UserGroupId, @Energy, @MenuData, @MyMealsData);
                COMMIT;";
            }
            else
            {
                sql = @"BEGIN;
                UPDATE menues SET
                title = @Title, diet = @Diet, date = @Date, note = @Note, userId = @UserId, clientId = @ClientId, userGroupId = @UserGroupId, energy = @Energy, menuData = @MenuData, myMeals = @MyMealsData
                WHERE id = @Id;
                COMMIT;";
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                using (SQLiteCommand 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("Diet", x.diet));
                    command.Parameters.Add(new SQLiteParameter("Date", x.date));
                    command.Parameters.Add(new SQLiteParameter("Note", x.note));
                    command.Parameters.Add(new SQLiteParameter("UserId", user.userId));
                    command.Parameters.Add(new SQLiteParameter("ClientId", x.client.clientId));
                    command.Parameters.Add(new SQLiteParameter("UserGroupId", string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId));
                    command.Parameters.Add(new SQLiteParameter("Energy", x.energy));
                    command.Parameters.Add(new SQLiteParameter("MenuData", JsonConvert.SerializeObject(x.data, Formatting.None)));
                    command.Parameters.Add(new SQLiteParameter("MyMealsData", myMealsData));
                    command.ExecuteNonQuery();
                }
            }

            Files F = new Files();
            F.RemoveJsonFile(userId, x.id, "menues", MENU_DATA, db, userDataBase, null);     //******* Remove json file if exists (old sistem).
            F.RemoveJsonFile(userId, x.id, "menues", MY_MEALS, db, userDataBase, "mymeals"); //******* Remove myMeals json file if exists (old sistem).

            r.data      = x;
            r.msg       = "saved";
            r.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data      = x;
            r.msg       = e.Message;
            r.msg1      = "report a problem";
            r.isSuccess = false;
            L.SendErrorLog(e, x.id, userId, "Menues", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }