Esempio n. 1
0
        public JsonResult Update(ETHNIC_OBJ obj)
        {
            // List<string> li_ref = new List<string>();// danh sach file sẽ được thêm vào
            //  List<string> li_refd = new List<string>();// sanh sách file bị xoá đi
            //if (ses.func("SUPADMIN") <= 0)
            //{
            //    return Json(new { sussess = -3 }, JsonRequestBehavior.AllowGet);

            //}
            ETHNIC_BUS bus = new ETHNIC_BUS();
            int        ret;
            int        add = 0;

            ETHNIC_OBJ objTemp;

            //kiểm tra tồn tại cho trường hợp sửa
            if (!string.IsNullOrEmpty(obj.CODE))//edit
            {
                objTemp = bus.GetByID(new ETHNIC_OBJ.BusinessObjectID(obj.CODE));
                if (objTemp == null)
                {
                    ret = -4;
                    //đóng kết nối trước khi trả về
                    bus.CloseConnection();
                    //ban ghi sửa đã bị xóa
                    return(Json(new { sussess = ret }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                objTemp = new ETHNIC_OBJ();
                //obj_temp.UNIVERSITYCODE = ses.gUNIVERSITYCODE;
            }
            //hết kiểm tra tồn tại bản ghi
            objTemp.EDITTIME = DateTime.Now;   //Thời điểm sủa bản ghi
            objTemp.EDITUSER = _ses.loginCode; //Người sửa bản ghi

            objTemp.CODEVIEW = obj.CODEVIEW;
            objTemp.NAME     = obj.NAME;
            objTemp.NOTE     = obj.NOTE;
            //obj_temp.THEORDER = obj.THEORDER;
            //  obj_temp.PARENTCODE = obj.PARENTCODE;
            objTemp.LOCK = obj.LOCK;

            //if (obj_temp.PARENTCODE == null)
            //{
            //    obj_temp.PARENTCODE = "";
            //}
            //Kiểm tra tình trạng sửa hay là thêm mới
            if (string.IsNullOrEmpty(obj.CODE))
            {
                //Thêm mới
                add = 1;
                //Sinh mã
                objTemp.CODE     = bus.genNextCode(obj);
                objTemp.LOCK     = 0;
                objTemp.LOCKDATE = DateTime.Now;
                //obj_temp.MODULECODE = "CORE";//for this
            }
            //if (string.IsNullOrEmpty(obj.EXTENSIONCODE))
            //{
            //    obj_temp.EXTENSIONCODE = obj_temp.CODE;
            //}
            //else
            //{
            //    obj_temp.EXTENSIONCODE = obj.EXTENSIONCODE + "." + obj_temp.CODE;
            //}

            if (add == 1)
            {
                ret = bus.insert(objTemp);
            }
            else
            {
                //gán _ID để xác định bản ghi sẽ được cập nhật
                objTemp._ID.CODE = obj.CODE;
                ret = bus.update(objTemp);
            }

            if (ret >= 0)
            {
                bus.CommitTransaction();
            }
            else
            {
                bus.RollbackTransaction();
            }
            bus.CloseConnection();
            //some thing like that
            return(Json(new { ret, obj = objTemp }, JsonRequestBehavior.AllowGet));
        }