Пример #1
0
        public override Category GetCategoryByCategoryId(int Id)
        {
            if (Id <= DefaultValues.GetCategoryIdMinValue())
            {
                throw (new ArgumentOutOfRangeException("Id"));
            }


            SqlCommand sqlCmd = new SqlCommand();

            AddParamToSQLCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_GETCATEGORYBYID);

            List <Category> categoryList = new List <Category>();

            TExecuteReaderCmd <Category>(sqlCmd, TGenerateCategoryListFromReader <Category>, ref categoryList);

            if (categoryList.Count > 0)
            {
                return(categoryList[0]);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public override bool UpdateCategory(Category newCategory)
        {
            if (newCategory == null)
            {
                throw (new ArgumentNullException("newCategory"));
            }

            if (newCategory.Id <= DefaultValues.GetCategoryIdMinValue())
            {
                throw (new ArgumentOutOfRangeException("newCategory.Id"));
            }

            SqlCommand sqlCmd = new SqlCommand();

            AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);

            AddParamToSQLCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, newCategory.Id);
            AddParamToSQLCmd(sqlCmd, "@CategoryAbbreviation", SqlDbType.NText, 255, ParameterDirection.Input, newCategory.Abbreviation);
            AddParamToSQLCmd(sqlCmd, "@CategoryEstimateDuration", SqlDbType.Decimal, 0, ParameterDirection.Input, newCategory.EstimateDuration);
            AddParamToSQLCmd(sqlCmd, "@CategoryName", SqlDbType.NText, 255, ParameterDirection.Input, newCategory.Name);
            AddParamToSQLCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, newCategory.ProjectId);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_UPDATE);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;

            return(returnValue == 0 ? true : false);
        }
Пример #3
0
        public override bool DeleteCategory(int categoryId)
        {
            if (categoryId <= DefaultValues.GetCategoryIdMinValue())
            {
                throw (new ArgumentOutOfRangeException("categoryId"));
            }

            SqlCommand sqlCmd = new SqlCommand();

            AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParamToSQLCmd(sqlCmd, "@CategoryIdToDelete", SqlDbType.Int, 0, ParameterDirection.Input, categoryId);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_DELETE);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;

            return(returnValue == 0 ? true : false);
        }