Esempio n. 1
0
        public CategoryEntity GetCategory(int id)
        {
            CategoryEntity c = null;
            using (var conn = new SqlConnection(_connectionString))
            {
                var cmd = new SqlCommand(string.Format(Resources.DB_SQL_CAL_SEL,
                                                       Resources.DB_COL_CAT_NAME + ", " +
                                                       Resources.DB_COL_CAT_DESC,
                                                       Resources.DB_TAB_CAT,
                                                       Resources.DB_COL_CAT_ID,
                                                       Resources.DB_COL_CAT_ID), conn);

                cmd.Parameters.AddWithValue("@" + Resources.DB_COL_CAT_ID, id);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    c = new CategoryEntity
                            {
                                CategoryID = id,
                                CategoryName = (string) reader[Resources.DB_COL_CAT_NAME],
                                Description = (string) reader[Resources.DB_COL_CAT_DESC]
                            };
                }
            }
            return c;
        }
Esempio n. 2
0
 private Category TranslateCategoryEntityToCategoryContractData(
     CategoryEntity categoryEntity)
 {
     return new Category
                {
                    ID = categoryEntity.CategoryID,
                    Name = categoryEntity.CategoryName,
                    Description = categoryEntity.Description
                };
 }
Esempio n. 3
0
        public bool UpdateCategory(CategoryEntity category)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                var cmd = new SqlCommand(
                    string.Format(Resources.DB_SQL_CAL_UPD, Resources.DB_TAB_CAT, Resources.DB_COL_CAT_NAME,
                                  Resources.DB_COL_CAT_NAME,
                                  Resources.DB_COL_CAT_DESC, Resources.DB_COL_CAT_DESC, Resources.DB_COL_CAT_ID,
                                  Resources.DB_COL_CAT_ID), conn);

                cmd.Parameters.AddWithValue("@" + Resources.DB_COL_CAT_NAME, category.CategoryName);
                cmd.Parameters.AddWithValue("@" + Resources.DB_COL_CAT_DESC, category.Description);
                cmd.Parameters.AddWithValue("@" + Resources.DB_COL_CAT_ID, category.CategoryID);
                conn.Open();
                int numRows = cmd.ExecuteNonQuery();

                return (numRows == 1);
            }
        }
Esempio n. 4
0
        public void UpdateCategory(CategoryEntity category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (string.IsNullOrEmpty(category.CategoryName))
            {
                throw new NoNullAllowedException(Resources.MSG_NULL_CAT_NAME);
            }

            if (string.IsNullOrEmpty(category.Description))
            {
                throw new NoNullAllowedException(Resources.MSG_NULL_CAT_DESC);
            }

            if (!_categoryDAO.UpdateCategory(category))
            {
                throw new DataException(Resources.MSG_UPDATE_FAILED);
            }
        }