예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public JsonResult Delete(List <string> code)
        {
            var ret   = 0;
            var error = false;

            if (_ses.isLogin() < 0)
            {
                return(Json(new { ret = -1 }, JsonRequestBehavior.AllowGet));
            }
            if (code != null)
            {
                var bus = new CLASS_BUS();
                foreach (string t in code)
                {
                    if (t != null)
                    {
                        var item = bus.GetByID(new CLASS_OBJ.BusinessObjectID(t));
                        if (item == null)
                        {
                            ret   = -1;
                            error = true;
                            continue;
                        }
                        if (item.UNIVERSITYCODE != _ses.gUNIVERSITYCODE)
                        {
                            ret = -4;
                        }
                        // kiểm tra có học sinh nào trong lớp hay chưa
                        if (ret >= 0)
                        {
                            STUDENT_BUS busStudent = new STUDENT_BUS();
                            //check children
                            ret = busStudent.checkCode(null, new fieldpara("CLASSCODE", t));
                            busStudent.CloseConnection();
                            //exist children
                            if (ret != 0)
                            {
                                ret = -2;
                            }
                        }
                        if (ret >= 0)
                        {
                            ret = bus.delete(item._ID);
                        }
                        if (!error && ret < 0)
                        {
                            error = true;
                        }
                    }
                }
                bus.CloseConnection();
            }

            //   ret = error ? -1 : 0;
            return(Json(new
            {
                ret
            }, JsonRequestBehavior.AllowGet));
        }