public async Task <JsonResult> AddDepartment(VmDepartment dep)
        {
            var jsonResult = new VM_JsonOnlyResult();
            var modelState = (new VmDepartmentValidator()).Validate(dep);

            if (!modelState.IsValid)
            {
                jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage));
                return(await Task.FromResult(Json(jsonResult)));
            }

            m_DepartmentService.PreOnAddHandler =
                () => !m_DepartmentService.DepartmentExists(dep.NagigatedDomainObject.Name);
            var addedRet = await m_DepartmentService.AddObject(dep.NagigatedDomainObject, true);

            if (addedRet == AppServiceExecuteStatus.Success)
            {
                jsonResult.Value  = dep.NagigatedDomainObject.ID;
                jsonResult.Result = true;
                return(Json(jsonResult));
            }

            jsonResult.Err = string.Format(addedRet.ToDescription(), "部门名称已存在");
            return(Json(jsonResult));
        }
        public async Task <JsonResult> UpdateDepartment(VmDepartment dep)
        {
            var jsonResult = new VM_JsonOnlyResult();
            var modelState = (new VmDepartmentValidator()).Validate(dep);

            if (!modelState.IsValid)
            {
                jsonResult.Err = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage));
                return(await Task.FromResult(Json(jsonResult)));
            }


            m_DepartmentService.PreOnUpdateHandler =
                () =>
            {
                var existDep = m_DepartmentService.GetDepartment(dep.NagigatedDomainObject.ID);
                if (existDep == null)
                {
                    return(null);
                }
                var otherDep = m_DepartmentService.GetDepartment(dep.NagigatedDomainObject.Name);
                if (otherDep == null || otherDep.ID == dep.NagigatedDomainObject.ID)
                {
                    return(existDep);
                }
                return(null);
            };
            m_DepartmentService.OnUpdatingHandler = (oDep, nDep) =>
            {
                ((Department)oDep).Name = ((Department)nDep).Name;
                ((Department)oDep).Desc = ((Department)nDep).Desc;
            };
            var updatedRet = await m_DepartmentService.UpdateObject(dep.NagigatedDomainObject, true);

            if (updatedRet == AppServiceExecuteStatus.Success)
            {
                jsonResult.Value  = dep.NagigatedDomainObject.ID;
                jsonResult.Result = true;
            }

            jsonResult.Err = string.Format(updatedRet.ToDescription(), "部门名称重复");
            return(Json(jsonResult));
        }