Beispiel #1
0
        public List <CategoryDE> selectAll()
        {
            String            connectstring  = ConfigurationManager.ConnectionStrings["MyDataDB"].ConnectionString;
            List <CategoryDE> categorylist   = new List <CategoryDE>();
            CategoryDE        categoryResult = new CategoryDE();

            SqlConnection connection = new SqlConnection(connectstring);

            connection.Open();
            SqlCommand command = connection.CreateCommand();

            command.CommandText = "select * from Category";

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            foreach (DataRow row in table.Rows)
            {
                CategoryDE category = new CategoryDE()
                {
                    CategoryId   = Convert.ToInt32(row["CategoryId"]),
                    CategoryName = Convert.ToString(row["CategoryName"]),
                };
                categorylist.Add(category);
            }
            connection.Close();

            return(categorylist);
        }
Beispiel #2
0
        //public CategoryDE Insert(CategoryDE category)
        //{
        //    dataAcess.Open();
        //    dataAcess.BeginTran();
        //    QueryParameter[] list = new QueryParameter[2];
        //    list[0] = new QueryParameter("CategoryId", category.CategoryId, DbType.Int32);
        //    list[1] = new QueryParameter("CategoryName", category.CategoryName, DbType.String);
        //    string sql = "insert into Category values(@CategoryName)";
        //    dataAcess.ExecuteNonQuery(sql, list);
        //    dataAcess.CommitTran();
        //    dataAcess.Close();
        //    return category;
        //}

        //public bool Update(CategoryDE category)
        //{
        //    return true;
        //}

        //public bool Delete(int id)
        //{
        //    return true;
        //}

        public CategoryDE GetById(int id)
        {
            String            connectstring  = ConfigurationManager.ConnectionStrings["MyDataDB"].ConnectionString;
            List <CategoryDE> categoryList   = new List <CategoryDE>();
            CategoryDE        categoryResult = new CategoryDE();

            if (id >= 0)
            {
                SqlConnection connection = new SqlConnection(connectstring);
                connection.Open();
                SqlCommand command = connection.CreateCommand();

                command.CommandText = "select * from Category where CategoryId = @id";

                command.Parameters.AddWithValue("id", id);

                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable      table   = new DataTable();
                adapter.Fill(table);
                foreach (DataRow row in table.Rows)
                {
                    CategoryDE category = new CategoryDE()
                    {
                        CategoryName = Convert.ToString(row["CategoryName"]),
                        CategoryId   = Convert.ToInt32(row["CategoryId"])
                    };

                    categoryList.Add(category);
                    categoryResult = categoryList.First();
                }
                connection.Close();
            }
            return(categoryResult);
        }
 public async Task UpdateCategory([FromBody] CategoryModel category)
 {
     CategoryDE categoryDE = new CategoryDE();
     await categoryDE.AddOrEdit(category);
 }
        public async Task <IEnumerable <CategoryModel> > GetCategories(int categoryID = 0)
        {
            CategoryDE categoryDE = new CategoryDE();

            return(await categoryDE.GetCategories(categoryID));
        }