public ApiResponse <bool> AddProvince(Province province)
        {
            ApiResponse <bool> apiResponse = ApiResponse <bool> .GetInstance();

            if (null == province)
            {
                return(apiResponse.Error());
            }

            if (string.IsNullOrEmpty(province.ProvinceName))
            {
                EnumOperate.EnumItem enumItem = ProvinceErrorCode.REQUEST_PROVINCE_NAME_IS_EMPTY.GetBaseDescription();

                return(apiResponse.Error(enumItem.Code, enumItem.Message));
            }

            try
            {
                _provinceDao.AddProvince(province);
                apiResponse.Success(true);
            }
            catch (System.Exception)
            {
                throw;
            }

            return(apiResponse);
        }
Exemple #2
0
        public ApiResponse <T> Error()
        {
            ApiResult = ApiResult.Error;

            EnumOperate.EnumItem enumItem = BaseErrorCode.FAIL.GetBaseDescription();
            Code    = enumItem.Code;
            Message = enumItem.Message;

            return(this);
        }
Exemple #3
0
        public ApiResponse <T> Success()
        {
            ApiResult = ApiResult.Success;

            EnumOperate.EnumItem enumItem = BaseErrorCode.SUCCESS.GetBaseDescription();
            Code    = enumItem.Code;
            Message = enumItem.Message;

            return(this);
        }
        /// <summary>
        /// 根据name获取学生信息
        /// </summary>
        /// <param name="stuName"></param>
        /// <returns></returns>
        public ApiResponse <IList <Student> > FindStudentByName(string stuName)
        {
            ApiResponse <IList <Student> > apiResponse = ApiResponse <IList <Student> > .GetInstance();

            if (string.IsNullOrEmpty(stuName))
            {
                EnumOperate.EnumItem enumItem = BaseErrorCode.REQUEST_PARAM_ERROR.GetBaseDescription();

                return(apiResponse.Error(enumItem.Code, enumItem.Message));
            }

            try
            {
                var studentList = _studentDao.FindStudentByName(stuName);
                apiResponse.Success(studentList);
            }
            catch (System.Exception)
            {
                throw;
            }

            return(apiResponse);
        }
        /// <summary>
        /// 添加学生信息
        /// </summary>
        /// <param name="student"></param>
        /// <returns></returns>
        public ApiResponse <bool> AddStudent(Student student)
        {
            ApiResponse <bool> apiResponse = ApiResponse <bool> .GetInstance();

            if (null == student)
            {
                EnumOperate.EnumItem enumItem = StudentErrorCode.REQUEST_PARAM_ENTITY_IS_NULL.GetBaseDescription();

                return(apiResponse.Error(enumItem.Code, enumItem.Message));
            }

            try
            {
                _studentDao.AddStudent(student);
                apiResponse.Success(true);
            }
            catch (System.Exception)
            {
                // 异常全部抛出,在全局异常处理类中捕获并处理
                throw;
            }

            return(apiResponse);
        }