Пример #1
0
        public static Tuple <bool, string, dynamic> edit(string s_key, string s_item)
        {
            try
            {
                string json = "";

                m_kh_dienluc m = JsonConvert.DeserializeObject <m_kh_dienluc>(s_item);

                int index = list.FindIndex(o => o.id == m.id);
                if (index != -1)
                {
                    m_kh_dienluc o = list[index];


                    o.name = m.name;
                    //o.code = m.code;
                    o.id_parent = m.id_parent;

                    lock (lock_list)
                        list[index] = o;

                    update();

                    json = JsonConvert.SerializeObject(o);
                }

                return(new Tuple <bool, string, dynamic>(true, json, m));
            }

            catch { }
            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
Пример #2
0
        public static string edit_ItemJsonString(string item_json, string msg_default = "")
        {
            string json = msg_default;

            try
            {
                m_kh_dienluc m = JsonConvert.DeserializeObject <m_kh_dienluc>(item_json);

                int index = list.FindIndex(o => o.id == m.id);
                if (index != -1)
                {
                    m_kh_dienluc o = list[index];


                    o.name = m.name;
                    //o.code = m.code;
                    o.id_parent = m.id_parent;

                    lock (lock_list)
                        list[index] = o;

                    update();

                    json = JsonConvert.SerializeObject(o);
                }
            }
            catch { }

            return(json);
        }
Пример #3
0
        public static Tuple <bool, string, dynamic> add(string s_key, string s_item)
        {
            try
            {
                string json = "";

                var json_obj = JsonConvert.DeserializeObject <m_kh_dienluc>(s_item);

                m_kh_dienluc m = JsonConvert.DeserializeObject <m_kh_dienluc>(s_item);

                int index = list.FindIndex(o => o.code == m.code);
                if (index == -1)
                {
                    bool c       = false;
                    int  new_rnd = 0;
                    while (c == false)
                    {
                        Random rnd = new Random();
                        new_rnd = rnd.Next(1, int.MaxValue);
                        int idx = list.FindIndex(o => new_rnd == m.id);
                        if (idx == -1)
                        {
                            c = true;
                        }
                        ;
                    }

                    m.id        = new_rnd;
                    m.name      = json_obj.name;
                    m.code      = json_obj.code;
                    m.id_parent = json_obj.id_parent;
                    m.status    = true;

                    lock (lock_list)
                        list.Add(m);

                    update();

                    json = JsonConvert.SerializeObject(m);

                    return(new Tuple <bool, string, dynamic>(true, json, m));
                }
                else
                {
                    json = "trung_ma";
                    return(new Tuple <bool, string, dynamic>(true, json, null));
                }
            }

            catch { }

            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
Пример #4
0
        public static string add_ItemJson(string item_json, string msg_default = "")
        {
            string json = msg_default;

            var json_obj = JsonConvert.DeserializeObject <m_kh_dienluc>(item_json);

            try
            {
                m_kh_dienluc m = JsonConvert.DeserializeObject <m_kh_dienluc>(item_json);

                int index = list.FindIndex(o => o.code == m.code);
                if (index == -1)
                {
                    bool c       = false;
                    int  new_rnd = 0;
                    while (c == false)
                    {
                        Random rnd = new Random();
                        new_rnd = rnd.Next(1, int.MaxValue);
                        int idx = list.FindIndex(o => new_rnd == m.id);
                        if (idx == -1)
                        {
                            c = true;
                        }
                        ;
                    }

                    m.id        = new_rnd;
                    m.name      = json_obj.name;
                    m.code      = json_obj.code;
                    m.id_parent = json_obj.id_parent;
                    m.status    = true;

                    lock (lock_list)
                        list.Add(m);

                    update();

                    json = JsonConvert.SerializeObject(m);
                }
            }
            catch { }

            return(json);
        }