Пример #1
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); }
 }
Пример #2
0
 public string Save(Users.NewUser user, NewClient x, string lang)
 {
     try {
         db.CreateDataBase(user.userGroupId, db.clients);
         db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "note");  //new column in clients tbl.
         SaveResponse r = new SaveResponse();
         if (x.clientId == null && Check(user.userGroupId, x) == false)
         {
             r.data    = null;
             r.message = t.Tran("client is already registered", lang);
             return(JsonConvert.SerializeObject(r, Formatting.None));
         }
         else
         {
             if (x.clientId == null)
             {
                 //************TODO***************
                 int clientsLimit = MonthlyLimitOfClients(user.userType);
                 if (NumberOfClientsPerMonth(user.userGroupId) > clientsLimit)
                 {
                     r.data    = null;
                     r.message = string.Format("{0} {1}.", t.Tran("client was not saved. the maximum number of clients in one month is", lang), clientsLimit);
                     return(JsonConvert.SerializeObject(r, Formatting.None));
                 }
                 else
                 {
                     x.clientId = Convert.ToString(Guid.NewGuid());
                 }
             }
             using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
                 connection.Open();
                 string sql = @"INSERT OR REPLACE INTO clients VALUES
                         (@clientId, @firstName, @lastName, @birthDate, @gender, @phone, @email, @userId, @date, @isActive, @note)";
                 using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                     using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                         command.Parameters.Add(new SQLiteParameter("clientId", x.clientId));
                         command.Parameters.Add(new SQLiteParameter("firstName", x.firstName));
                         command.Parameters.Add(new SQLiteParameter("lastName", x.lastName));
                         command.Parameters.Add(new SQLiteParameter("birthDate", x.birthDate));
                         command.Parameters.Add(new SQLiteParameter("gender", x.gender.value));
                         command.Parameters.Add(new SQLiteParameter("phone", x.phone));
                         command.Parameters.Add(new SQLiteParameter("email", x.email));
                         command.Parameters.Add(new SQLiteParameter("userId", x.userId));
                         command.Parameters.Add(new SQLiteParameter("date", x.date));
                         command.Parameters.Add(new SQLiteParameter("isActive", x.isActive));
                         command.Parameters.Add(new SQLiteParameter("note", x.note));
                         command.ExecuteNonQuery();
                         transaction.Commit();
                     }
                 }
                 connection.Close();
             }
             r.data = x;
             r.data.gender.title = GetGenderTitle(r.data.gender.value);
             r.message           = null;
             return(JsonConvert.SerializeObject(r, Formatting.None));
         }
     } catch (Exception e) { return(e.Message); }
 }
Пример #3
0
 public string Save(string userId, NewClientData x, int userType)
 {
     try {
         db.CreateDataBase(userId, db.clientsData);
         db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "note");            //new column in clients tbl.
         db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clientsData, "bodyFatPerc"); //new column in clients tbl.
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             string sql = "";
             if (Check(userId, x) != false)
             {
                 sql = string.Format(@"INSERT INTO clientsdata (clientId, height, weight, waist, hip, pal, goal, activities, diet, meals, date, userId, bodyFatPerc)
                         VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}');
                         UPDATE clients SET note = '{13}' WHERE clientId = '{0}';"
                                     , x.clientId, x.height, x.weight, x.waist, x.hip, x.pal.value, x.goal.code
                                     , JsonConvert.SerializeObject(x.activities, Formatting.None)
                                     , JsonConvert.SerializeObject(x.diet, Formatting.None)
                                     , JsonConvert.SerializeObject(x.meals, Formatting.None)
                                     , x.date
                                     , x.userId
                                     , x.bodyFat.bodyFatPerc
                                     , x.clientNote);
             }
             else
             {
                 sql = string.Format(@"UPDATE clientsdata SET  
                         height = '{0}', weight = '{1}', waist = '{2}', hip = '{3}', pal = '{4}', goal = '{5}', activities = '{6}', diet = '{7}', meals = '{8}', date = '{9}', bodyFatPerc = '{10}' 
                         WHERE clientId = '{11}' AND ((strftime('%d', date) = '{12}' AND strftime('%m', date) = '{13}' AND strftime('%Y', date) = '{14}') OR date = '{9}');
                         UPDATE clients SET note = '{15}' WHERE clientId = '{10}';"
                                     , x.height, x.weight, x.waist, x.hip, x.pal.value, x.goal.code
                                     , JsonConvert.SerializeObject(x.activities, Formatting.None)
                                     , JsonConvert.SerializeObject(x.diet, Formatting.None)
                                     , JsonConvert.SerializeObject(x.meals, Formatting.None)
                                     , x.date
                                     , x.bodyFat.bodyFatPerc
                                     , x.clientId
                                     , Convert.ToDateTime(x.date).Day
                                     , (Convert.ToDateTime(x.date).Month < 10 ? string.Format("0{0}", Convert.ToDateTime(x.date).Month) : Convert.ToDateTime(x.date).Month.ToString())
                                     , Convert.ToDateTime(x.date).Year
                                     , x.clientNote);
             }
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                     command.CommandText = sql;
                     command.ExecuteNonQuery();
                     transaction.Commit();
                 }
             }
             connection.Close();
         }
         if (userType > 1)
         {
             SaveMyMeals(userId, x.clientId, x.myMeals);
         }
         return("saved");
     } catch (Exception e) { return("Error: " + e); }
 }
Пример #4
0
 public string Get(string userId, string id)
 {
     try {
         NewMyMeals x = new NewMyMeals();
         db.AddColumn(userId, db.GetDataBasePath(userId, userDataBase), db.meals, MEAL_DATA, "TEXT");  //new column in meals tbl.
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) {
             connection.Open();
             string sql = string.Format("SELECT id, title, description, userId, userGroupId, mealData FROM meals WHERE id = '{0}'", id);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 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.userId      = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                         x.userGroupId = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
                         //x.data = JsonConvert.DeserializeObject<JsonFileMeals>(GetJsonFile(userId, id));  // OLD
                         string data = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5);
                         if (!string.IsNullOrWhiteSpace(data))
                         {
                             x.data = JsonConvert.DeserializeObject <JsonFileMeals>(data);  // new sistem: recipe saved in db
                         }
                         else
                         {
                             x.data = JsonConvert.DeserializeObject <JsonFileMeals>(GetJsonFile(userId, id)); // old sistem: recipe saved in json file
                         }
                     }
                 }
             }
         }
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, id, userId, "MyMeals", "Get");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Пример #5
0
        public NewClient GetClient(string userId, string clientId)
        {
            DataBase db       = new DataBase();
            string   dataBase = ConfigurationManager.AppSettings["UserDataBase"];

            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "note");  //new column in clients tbl.
            try {
                if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(clientId))
                {
                    return(new NewClient());
                }
                else
                {
                    NewClient x = new NewClient();
                    using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                        connection.Open();
                        string sql = string.Format("SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note FROM clients WHERE clientId = '{0}'", clientId);
                        using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                            Gender g = new Gender();
                            using (SQLiteDataReader reader = command.ExecuteReader()) {
                                while (reader.Read())
                                {
                                    x.clientId     = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                                    x.firstName    = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                                    x.lastName     = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                                    x.birthDate    = reader.GetValue(3) == DBNull.Value ? DateTime.Now.ToString() : reader.GetString(3);
                                    x.gender.value = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt32(4);
                                    x.gender.title = GetGenderTitle(x.gender.value);
                                    x.phone        = reader.GetValue(5) == DBNull.Value ? "" : reader.GetString(5);
                                    x.email        = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6);
                                    x.userId       = reader.GetValue(7) == DBNull.Value ? "" : reader.GetString(7);
                                    x.date         = reader.GetValue(8) == DBNull.Value ? DateTime.Today.ToString() : reader.GetString(8);
                                    x.isActive     = reader.GetValue(9) == DBNull.Value ? 1 : reader.GetInt32(9);
                                    x.note         = reader.GetValue(10) == DBNull.Value ? "" : reader.GetString(10);
                                    x.profileImg   = GetProfileImg(userId, x.clientId);
                                    x.clientData   = null;
                                }
                            }
                        }
                        connection.Close();
                    }
                    return(x);
                }
            } catch (Exception e) { return(new NewClient()); }
        }
Пример #6
0
    public string Load(string userId, Users.NewUser user, string query, int?limit, int offset, bool isClientGroup)
    {
        List <NewClient> xx = new List <NewClient>();

        db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "cids", "VARCHAR(200)");  //new column in cids tbl.
        try {
            Global G = new Global();
            query = G.SpecChrSearchQuery(query);
            bool isAdminTypeSql = user.adminType > (int)Global.AdminType.supervisor;

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(JsonConvert.SerializeObject(xx, Formatting.None));
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                connection.Open();
                string sql = string.Format(@"SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note, cids 
                        FROM clients
                        WHERE {0}
                        {1}
                        ORDER BY rowid DESC {2}"
                                           , isClientGroup ? "(cids NOT NULL AND cids <> '')" : "(cids IS NULL OR cids = '')"
                                           , !string.IsNullOrWhiteSpace(query)
                                        ? string.Format("AND (LOWER(firstName) LIKE '%{0}%' OR LOWER(lastName) LIKE '%{0}%' OR LOWER(clientId) = '{0}' {1})", query, isAdminTypeSql ? string.Format("AND userId = '{0}' ", user.userId) : null)
                                        : isAdminTypeSql ? string.Format("AND userId = '{0}' ", user.userId) : null
                                           , limit != null ? string.Format("LIMIT {0} OFFSET {1}", limit, offset) : null);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewClient x = GetData(reader, userId, false, connection);
                            xx.Add(x);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, null, userId, "Clients", "Load");
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        }
    }
Пример #7
0
    public NewClientData GetClientData(string userId, string clientId, SQLiteConnection connection)
    {
        NewClientData x = new NewClientData();

        try {
            List <NewClientData> xx = new List <NewClientData>();
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "note");                 //new column in clients tbl.
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "cids", "VARCHAR(200)"); //new column in cids tbl.
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "dailyActivities", "TEXT");
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "myRecommendedEnergyIntake", "VARCHAR(50)");
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "myRecommendedEnergyExpenditure", "VARCHAR(50)");
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "myMeals", "TEXT");
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "allergens", "TEXT");

            string sql = string.Format(@"SELECT cd.rowid, cd.clientId, c.birthDate, c.gender, cd.height, cd.weight, cd.waist, cd.hip, cd.pal, cd.goal, cd.activities, cd.diet, cd.meals, cd.date, cd.userId, c.note, cd.bodyFatPerc, cd.targetedMass, c.dailyActivities, c.myRecommendedEnergyIntake, c.myRecommendedEnergyExpenditure, c.myMeals
                        FROM clientsdata as cd
                        LEFT OUTER JOIN clients as c
                        ON cd.clientId = c.clientId
                        WHERE cd.clientId = '{0}'", clientId);
            using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                Calculations c = new Calculations();
                Goals        g = new Goals();
                DetailEnergyExpenditure.DailyActivities da = new DetailEnergyExpenditure.DailyActivities();
                string birthDate = null;
                using (SQLiteDataReader reader = command.ExecuteReader()) {
                    while (reader.Read())
                    {
                        x              = new NewClientData();
                        x.id           = reader.GetInt32(0);
                        x.clientId     = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                        birthDate      = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                        x.age          = C.Age(birthDate);
                        x.agemos       = C.Agemos(birthDate);
                        x.days         = C.Days(birthDate);
                        x.gender.value = reader.GetValue(3) == DBNull.Value ? 0 : reader.GetInt32(3);
                        x.gender.title = GetGender(x.gender.value).title;
                        x.height       = reader.GetValue(4) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(4));
                        x.weight       = reader.GetValue(5) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(5));
                        x.waist        = reader.GetValue(6) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(6));
                        x.hip          = reader.GetValue(7) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(7));
                        x.pal          = c.GetPal(reader.GetValue(8) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(8)));
                        x.goal.code    = reader.GetValue(9) == DBNull.Value ? "" : reader.GetString(9);
                        x.goal.title   = g.GetGoal(x.goal.code).title;
                        x.activities   = JsonConvert.DeserializeObject <List <Activities.ClientActivity> >(reader.GetString(10));
                        x.diet         = JsonConvert.DeserializeObject <Diets.NewDiet>(reader.GetString(11));
                        if (x.diet == null)
                        {
                            x.diet = new Diets.NewDiet();
                        }
                        x.meals               = JsonConvert.DeserializeObject <List <Meals.NewMeal> >(reader.GetString(12));
                        x.date                = reader.GetValue(13) == DBNull.Value ? DateTime.UtcNow.ToString() : reader.GetString(13);
                        x.userId              = reader.GetValue(14) == DBNull.Value ? "" : reader.GetString(14);
                        x.clientNote          = reader.GetValue(15) == DBNull.Value ? "" : reader.GetString(15);
                        x.bodyFat             = new BodyFat.NewBodyFat();
                        x.bodyFat.bodyFatPerc = reader.GetValue(16) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(16));
                        x.targetedMass        = reader.GetValue(17) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(17));
                        string dailyActivities = reader.GetValue(18) == DBNull.Value ? null : reader.GetString(18);
                        if (!string.IsNullOrWhiteSpace(dailyActivities))
                        {
                            var activities = JsonConvert.DeserializeObject <List <DetailEnergyExpenditure.Activity> >(dailyActivities);
                            x.dailyActivities            = new DetailEnergyExpenditure.Activities();
                            x.dailyActivities.activities = activities;
                            if (activities != null)
                            {
                                x.dailyActivities.energy   = activities.Sum(a => a.energy);
                                x.dailyActivities.duration = activities.Sum(a => a.duration);
                            }
                        }
                        else
                        {
                            x.dailyActivities = da.getDailyActivities(userId, x.clientId); // old sistem: data saved in json file
                        }
                        x.myCalculation = new Calculations.MyCalculation();
                        int?myRecommendedEnergyIntake      = reader.GetValue(19) == DBNull.Value ? 0 : string.IsNullOrWhiteSpace(reader.GetString(19)) ? 0 : Convert.ToInt32(reader.GetString(19));
                        int?myRecommendedEnergyExpenditure = reader.GetValue(20) == DBNull.Value ? 0 : string.IsNullOrWhiteSpace(reader.GetString(20)) ? 0 : Convert.ToInt32(reader.GetString(20));
                        if (myRecommendedEnergyIntake > 0 || myRecommendedEnergyExpenditure > 0)
                        {
                            x.myCalculation.recommendedEnergyIntake      = myRecommendedEnergyIntake;
                            x.myCalculation.recommendedEnergyExpenditure = myRecommendedEnergyExpenditure;
                        }
                        else
                        {
                            x.myCalculation = C.GetJsonFile(userId, x.clientId); // old sistem: data saved in json file
                        }
                        string myMeals = reader.GetValue(21) == DBNull.Value ? null : reader.GetString(21);
                        if (!string.IsNullOrWhiteSpace(myMeals))
                        {
                            x.myMeals = JsonConvert.DeserializeObject <MyMeals.NewMyMeals>(myMeals);  // new sistem: data saved in db
                        }
                        else
                        {
                            x.myMeals = GetMyMeals(userId, x.clientId); // old sistem: data saved in json file
                        }
                        // TODO: allergens
                        //x.allergens = reader.GetValue(22) == DBNull.Value ? null : reader.GetString(22);
                        x.bmrEquation   = C.MifflinStJeor; // TODO GetBmrEquation() & SaveBMREquation()
                        x.percentileSrc = C.WHO;
                        x.bmiPercentile = C.GetBmiPercentile(x.agemos, x.gender.value, x.percentileSrc);
                        xx.Add(x);
                    }
                }
            }
            if (xx.Count > 0)
            {
                x = xx.OrderByDescending(a => Convert.ToDateTime(a.date)).FirstOrDefault();
            }
            return(x);
        } catch (Exception e) {
            L.SendErrorLog(e, clientId, userId, "ClientsData", "GetClientData");
            return(x);
        }
    }
Пример #8
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));
        }
    }
Пример #9
0
        public void Buid <T>() where T : class
        {
            DataConfigureAttribute custAttribute = DataConfigureAttribute.GetAttribute <T>();

            TargeType = typeof(T);
            System.Reflection.PropertyInfo[] propertys = TargeType.GetProperties();
            if (custAttribute != null)
            {
                if (!DataBase.IsExistTable(custAttribute.MetaData.Table))
                {
                    DataBase.CreateTable <T>();
                }
                else
                {
                    foreach (var item in propertys)
                    {
                        TypeCode code = Type.GetTypeCode(item.PropertyType.IsGenericType ? item.PropertyType.GetGenericArguments()[0] : item.PropertyType);

                        if (custAttribute.MetaData.PropertyDataConfig.ContainsKey(item.Name))
                        {
                            PropertyDataInfo config = custAttribute.MetaData.PropertyDataConfig[item.Name];

                            if (!config.Ignore && !config.IsRelation)
                            {
                                string columnName = string.IsNullOrEmpty(config.ColumnName)
                                    ? config.PropertyName
                                    : config.ColumnName;
                                if (!DataBase.IsExistColumn(custAttribute.MetaData.Table, columnName))
                                {
                                    DataBase.AddColumn(custAttribute.MetaData.Table, columnName, Common.ConvertToDbType(code),
                                                       config.StringLength);
                                }
                                else
                                {
                                    DataBase.AlterColumn(custAttribute.MetaData.Table, columnName,
                                                         Common.ConvertToDbType(code),
                                                         config.StringLength);
                                }
                            }
                        }
                        else
                        {
                            if (!DataBase.IsExistColumn(custAttribute.MetaData.Table, item.Name))
                            {
                                DataBase.AddColumn(custAttribute.MetaData.Table, item.Name, Common.ConvertToDbType(code));
                            }
                            else
                            {
                                DataBase.AlterColumn(custAttribute.MetaData.Table, item.Name, Common.ConvertToDbType(code));
                            }
                        }
                    }
                }
            }
            else
            {
                if (!DataBase.IsExistTable(TargeType.Name))
                {
                    DataBase.CreateTable <T>();
                }
                else
                {
                    foreach (var item in propertys)
                    {
                        TypeCode code = Type.GetTypeCode(item.PropertyType.IsGenericType ? item.PropertyType.GetGenericArguments()[0] : item.PropertyType);
                        if (!DataBase.IsExistColumn(TargeType.Name, item.Name))
                        {
                            DataBase.AddColumn(TargeType.Name, item.Name, Common.ConvertToDbType(code));
                        }
                        else
                        {
                            DataBase.AlterColumn(TargeType.Name, item.Name, Common.ConvertToDbType(code));
                        }
                    }
                }
            }
        }