Hello everyone,
I am developing an e-commerce web site to learn ASP.Net and MVC. I have more than 10 tables that are in relation each other.
The base table is products with the columns Id(P.K)Name, Price, Category_Id(F.K) and Brand_Id(F.K)
The other table is Categories table with the columns Id(PK)and Category_Name,
The lasttable is Brands table with the columns Id(PK)and Brand_Name.(And more tables but not related about this question)
I have constructed the class that operates CRUD operations.
The problem is that; I am trying to add a product with a web form. I have textboxes for Name and price and also I have dropdownlists for Category and Brand. Below code show my ProducsBLL Insert method.
Urun _Urun = new Urun
{
Adi = _Adi,
Adet = _Adet,
Fiyat = _Fiyat,
Garanti = _Garanti,
KargoDurumu = _KargoDurumu,
AnaResim = _AnaResim,
İcerik = _Icerik,
Kategori_Id = _KategoriId,
Marka_Id = _MarkaId,
};
db.Uruns.InsertOnSubmit(_Urun);
db.SubmitChanges();
}
and below code shows my PL Add product code behind codes.
protected void btnEkle_Click(object sender, EventArgs e)
{
UrunBLL _Urun = new UrunBLL();
if (cbTavsiyemi.Checked == true)
{
statusTavsiye = true;
}
else if (cbTavsiyemi.Checked == false)
{
statusTavsiye = false;
}
if (cbKargo.Checked == true)
{
statusKargo = true;
}
else if (cbTavsiyemi.Checked == false)
{
statusKargo = false;
}
if (Convert.ToInt32(DropDownList1.SelectedItem.Value) == 1)
{
GarantiSure = Convert.ToInt32(TextBox1.Text);
}
else if (Convert.ToInt32(DropDownList1.SelectedItem.Value) == 0)
{
GarantiSure = 0;
}
_Urun.Ekle(txtUrunAd.Text, Convert.ToInt32(txtUrunAdet.Text), Convert.ToInt32(txtMarkaFiyat.Text), GarantiSure,statusKargo, "yeni.jpg", txtUrunIcerik.Text, DropDownList2.SelectedIndex, DropDownList3.SelectedIndex);
}
First question: How can I list the items as Category names and Brand names.
Second question: How can I get the selected category and brand's id, then add them in product table.
Thanks for your consideration.
Emre.