Пример #1
0
        public object UpdateGroup(Models.Group.Group data)
        {
            int           status   = 0;
            string        Id       = "";
            int           id_group = 0;
            string        Token    = "";
            SqlConditions Conds    = new SqlConditions();
            DataTable     dt       = new DataTable();

            DataRow[]     dr;
            bool          Visible = true;
            List <object> rs = new List <object>();
            string        title = "", link = "";
            Hashtable     val        = new Hashtable();
            Hashtable     val_member = new Hashtable();
            DataTable     dt_token   = new DataTable();
            DataTable     lastid     = new DataTable();

            try
            {
                val.Add("TEN_GROUP", data.ten_group);


                val.Add("UPDATE_DATE", DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
                val.Add("UPDATE_BY", data.CreatedBy);

                Conds.Add("ID_GROUP", data.id_group);
                using (DpsConnection cnn = new DpsConnection(_config.ConnectionString))
                {
                    if (cnn.Update(val, Conds, "TBL_GROUP") < 0)

                    {
                        return(JsonResultCommon.ThatBai("Cập nhật thất bại", cnn.LastError));
                    }
                }
                return(JsonResultCommon.ThanhCong());
            }
            catch (Exception ex)
            {
                return(JsonResultCommon.Exception(ex));
            }
        }
Пример #2
0
        public object addGroup(Models.Group.Group data)
        {
            string    Token     = lc.GetHeader(Request);
            LoginData loginData = lc._GetInfoUser(Token);

            if (loginData == null)
            {
                return(JsonResultCommon.DangNhap());
            }
            int           status   = 0;
            string        Id       = "";
            int           id_group = 0;
            SqlConditions Conds    = new SqlConditions();
            DataTable     dt       = new DataTable();

            DataRow[]     dr;
            bool          Visible = true;
            List <object> rs = new List <object>();
            string        title = "", link = "";
            Hashtable     val        = new Hashtable();
            Hashtable     val_member = new Hashtable();
            DataTable     dt_token   = new DataTable();
            DataTable     lastid     = new DataTable();
            string        sqlq       = "";



            try
            {
                val.Add("TEN_GROUP", data.ten_group);


                val.Add("CREATE_DATE", DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
                val.Add("CREATE_BY", loginData.Id);
                val.Add("UPDATE_DATE", DateTime.Now.ToString("MM/dd/yyyy HH:mm"));


                using (DpsConnection cnn = new DpsConnection(_config.ConnectionString))
                {
                    sqlq = "select TEN_GROUP from TBL_GROUP where TEN_GROUP='" + data.ten_group + "'";

                    dt = cnn.CreateDataTable(sqlq);
                    if (dt.Rows.Count == 0)
                    {
                        if (cnn.Insert(val, "TBL_GROUP") < 0)

                        {
                            return(JsonResultCommon.ThatBai("Cập nhật thất bại", cnn.LastError));
                        }
                    }
                    else
                    {
                        return(JsonResultCommon.ThatBai("Tên Nhóm Đã Tồn Tại", cnn.LastError));
                    }


                    lastid = cnn.CreateDataTable(@"
SELECT TOP 1 ID_GROUP asLastID FROM TBL_GROUP ORDER BY ID_GROUP DESC");
                    dr     = lastid.Select();

                    foreach (DataRow r in dr[0].Table.Rows)
                    {
                        Id = r["asLastID"].ToString();
                    }
                    id_group = Int32.Parse(Id);


                    val_member.Add("ID_GROUP", id_group);


                    val_member.Add("CREATE_DATE", DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
                    val_member.Add("ID_USER", loginData.Id);
                    val_member.Add("QUYEN_ADMIN", 1);


                    if (cnn.Insert(val_member, "TBL_GROUPMEMBER") < 0)

                    {
                        return(JsonResultCommon.ThatBai("Cập nhật thất bại", cnn.LastError));
                    }
                }
                return(JsonResultCommon.ThanhCong(id_group));
            }
            catch (Exception ex)
            {
                return(JsonResultCommon.Exception(ex));
            }
        }