protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "sepet")
     {
         if (Session["sepet"] == null)
         {
             Session["sepet"] = spt.BosSepet();
         }
         List <cSepet> sepet = (List <cSepet>)Session["sepet"];
         cSepet        yeni  = new cSepet();
         yeni.UrunId = Convert.ToInt32(e.CommandArgument);
         TextBox Adet  = (TextBox)e.Item.FindControl("txtAdet");
         Label   Fiyat = (Label)e.Item.FindControl("lblFiyat");
         yeni.Adet       = Convert.ToInt32(Adet.Text);
         yeni.UrunAdi    = repoUrun.UrunAdiBul(yeni.UrunId);
         yeni.BirimFiyat = Convert.ToDecimal(Fiyat.Text);
         yeni.Tutar      = yeni.Adet * yeni.BirimFiyat;
         bool Varmi = false;
         foreach (cSepet mevcut in sepet)
         {
             if (mevcut.UrunId == yeni.UrunId)
             {
                 Varmi         = true;
                 mevcut.Adet  += yeni.Adet;
                 mevcut.Tutar += yeni.Tutar;
                 break;
             }
         }
         if (!Varmi)
         {
             sepet.Add(yeni);
         }
         Session["sepet"]       = sepet;
         Session["toplamadet"]  = spt.ToplamAdet(sepet);
         Session["toplamtutar"] = spt.ToplamTutar(sepet);
     }
     else if (e.CommandName == "Kate")
     {
         int UrunId        = Convert.ToInt32(e.CommandArgument);
         int KategoriId    = repoUrun.KategoriIdBul(UrunId);
         int AltKategoriId = 0;
         Response.Redirect("Default.aspx?KategoriId=" + KategoriId + "&AltKategoriId=" + AltKategoriId);
     }
     else if (e.CommandName == "AltKate")
     {
         int UrunId        = Convert.ToInt32(e.CommandArgument);
         int KategoriId    = repoUrun.KategoriIdBul(UrunId);
         int AltKategoriId = repoUrun.AltKategoriIdBul(UrunId);
         Response.Redirect("Default.aspx?KategoriId=" + KategoriId + "&AltKategoriId=" + AltKategoriId);
     }
 }
Exemple #2
0
 protected void repSepet_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "Urune")
     {
         int UrunId        = Convert.ToInt32(e.CommandArgument);
         int KategoriId    = repoUrun.KategoriIdBul(UrunId);
         int AltKategoriId = repoUrun.AltKategoriIdBul(UrunId);
         Response.Redirect("UrunDetay.aspx?KategoriId=" + KategoriId + "&AltKategoriId=" + AltKategoriId + "&UrunId=" + UrunId);
     }
     else if (e.CommandName == "sepettencikar")
     {
         int           SepetId = Convert.ToInt32(e.CommandArgument);
         List <cSepet> sepet   = (List <cSepet>)Session["sepet"];
         if (sepet.Count == 1)
         {
             Session["sepet"]       = null;
             Session["toplamadet"]  = null;
             Session["toplamtutar"] = null;
             Response.Redirect("Default.aspx");
         }
         cSepet cikar = sepet.Where(s => s.SepetId == SepetId).First();
         sepet.Remove(cikar);
         Session["sepet"]       = sepet;
         Session["toplamadet"]  = spt.ToplamAdet(sepet);
         Session["toplamtutar"] = spt.ToplamTutar(sepet);
         Response.Redirect("Sepet.aspx");
     }
     else if (e.CommandName == "Azalt")
     {
         int           SepetId       = Convert.ToInt32(e.CommandArgument);
         List <cSepet> sepet         = (List <cSepet>)Session["sepet"];
         cSepet        guncellenecek = sepet.Where(s => s.SepetId == SepetId).First();
         if (guncellenecek.Adet > 1)
         {
             guncellenecek.Adet--;
             guncellenecek.Tutar    = guncellenecek.Adet * guncellenecek.BirimFiyat;
             Session["sepet"]       = sepet;
             Session["toplamadet"]  = spt.ToplamAdet(sepet);
             Session["toplamtutar"] = spt.ToplamTutar(sepet);
             Response.Redirect("Sepet.aspx");
         }
         else
         {
             Button Azalt = e.Item.FindControl("Azalt") as Button;
             Azalt.Enabled = false;
         }
     }
     else if (e.CommandName == "Arttir")
     {
         int           SepetId       = Convert.ToInt32(e.CommandArgument);
         List <cSepet> sepet         = (List <cSepet>)Session["sepet"];
         cSepet        guncellenecek = sepet.Where(sp => sp.SepetId == SepetId).First();
         int           UrunId        = guncellenecek.UrunId;
         int           StokMiktari   = ent.Urunler.Where(u => u.Id == UrunId).Select(u => u.Miktar).First();
         if (StokMiktari - (guncellenecek.Adet + 1) >= 0)
         {
             guncellenecek.Adet++;
             guncellenecek.Tutar    = guncellenecek.Adet * guncellenecek.BirimFiyat;
             Session["sepet"]       = sepet;
             Session["toplamadet"]  = spt.ToplamAdet(sepet);
             Session["toplamtutar"] = spt.ToplamTutar(sepet);
             Response.Redirect("Sepet.aspx");
         }
         else
         {
             Button Arttır = e.Item.FindControl("Arttir") as Button;
             Arttır.Enabled = false;
         }
     }
 }