Ejemplo n.º 1
0
        public ActionResult Checkout(user _user, bool?shipbox, int?shipmethod, int?paymentmethod, int?paymenttype, string ad, string soyad, string adres, string sehir, int?postakodu, string eposta, string telefon)
        {
            //shipbox-> shipbox true ise başkası adına yada basşa bir farklı adrese gönderim
            //shipmethod-> Hızlıgönderim:10 tl yada normal gönderim 5 tl
            //paymentmethod_>ödeme tipi 1-havale,2-kredi kartı,3- kapıda ödeme vb.
            string message        = "";
            bool   status         = false;
            bool   orderCompleted = false;

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "User"));
            }
            user   loginUser = repoUser.GetAll().Where(x => x.email == User.Identity.Name).FirstOrDefault();
            orders newOrder  = new orders();

            newOrder.customerId = loginUser.userId;
            newOrder.orderDate  = DateTime.Now;
            if (paymentmethod == null)
            {
                message         = "Bir ödeme tipi seçmeniz gerekir";
                ViewBag.message = message;
                return(View());
            }
            else
            {
                newOrder.paymentType = paymentmethod;
            }
            if (shipmethod == null)
            {
                message         = "Bir gönderme tipi(Hızlı ya da Normal gönderim) seçmeniz gerekir";
                ViewBag.message = message;
                return(View());
            }
            else
            {
                // hızlı gönderim seçilmişse
                if (shipmethod == 1)
                {
                    newOrder.shipPrice = 10;
                }

                else
                {
                    newOrder.shipPrice = 5;
                }
            }

            // eğer kendine gönderiyorsa
            if (shipbox == null)
            {
                if (_user != null)
                {
                    // faklı birine yada farklı bir adrese göndermiyorsa
                    newOrder.isOther = false;

                    if (string.IsNullOrEmpty(_user.firstName))
                    {
                        message         = "isim alanını doldurmanız gerekir";
                        ViewBag.message = message;
                        return(View());
                    }
                    else
                    {
                        newOrder.firstname = _user.firstName;
                    }
                    if (string.IsNullOrEmpty(_user.lastName))
                    {
                        message         = "Soyad alanını doldurmanız gerekir";
                        ViewBag.message = message;
                        return(View());
                    }
                    else
                    {
                        newOrder.lastname = _user.lastName;
                    }
                    if (string.IsNullOrEmpty(_user.address))
                    {
                        message         = "adres alanını doldurmanız gerekir";
                        ViewBag.message = message;
                        return(View());
                    }
                    else
                    {
                        newOrder.address = _user.address;
                    }
                    if (string.IsNullOrEmpty(_user.city))
                    {
                        message         = "Şehir alanını doldurmanız gerekir";
                        ViewBag.message = message;
                        return(View());
                    }
                    else
                    {
                        newOrder.city = _user.city;
                    }
                    if (string.IsNullOrEmpty(_user.phone))
                    {
                        message         = "telefon alanını doldurmanız gerekir";
                        ViewBag.message = message;
                        return(View());
                    }
                    else
                    {
                        newOrder.phone = _user.phone;
                    }

                    newOrder.postCode = _user.postCode;
                    // sipariş kaydet
                    repoOrder.Save(newOrder);
                }
            }
            // farklı birine yada farklı bir adrese gönderiyorsa
            else
            {
                Session["ad"]    = ad;
                Session["soyad"] = soyad;
                Session["adres"] = adres;
                Session["sehir"] = sehir;

                Session["telefon"]   = telefon;
                Session["postakodu"] = postakodu ?? 0;
                Session["isGuest"]   = true;


                if (string.IsNullOrEmpty(ad))
                {
                    message         = "isim alanı boş bıraktınız";
                    ViewBag.message = message;
                    return(View());
                }
                else
                {
                    newOrder.firstname = ad;
                }
                if (string.IsNullOrEmpty(soyad))
                {
                    message         = "Soyisim alanı boş bıraktınız";
                    ViewBag.message = message;
                    return(View());
                }
                else
                {
                    newOrder.lastname = soyad;
                }

                if (string.IsNullOrEmpty(adres))
                {
                    message         = "Adres alanı boş bıraktınız";
                    ViewBag.message = message;
                    return(View());
                }
                else
                {
                    newOrder.address = adres;
                }
                if (string.IsNullOrEmpty(sehir))
                {
                    message         = "Şehir alanı boş bıraktınız";
                    ViewBag.message = message;
                    return(View());
                }
                else
                {
                    newOrder.city = sehir;
                }
                if (postakodu != null)
                {
                    newOrder.postCode = postakodu;
                }
                if (!string.IsNullOrEmpty(eposta))
                {
                    newOrder.email = eposta;
                }

                if (string.IsNullOrEmpty(telefon))
                {
                    message         = "Telefon alanı boş bıraktınız";
                    ViewBag.message = message;
                    return(View());
                }
                else
                {
                    newOrder.phone = telefon;
                }

                // faklı birine yada farklı bir adrese gönderİyorsa
                newOrder.isOther = true;
                repoOrder.Save(newOrder);
            }


            // sepette ürünler varsa
            if (Session["card"] != null)
            {
                List <BasketItem> Basket         = (List <BasketItem>)Session["card"];
                orderDetails      newOrderDetail = new orderDetails();
                foreach (var item in Basket)
                {
                    newOrderDetail.orderId   = newOrder.orderId;
                    newOrderDetail.productId = item.product.productId;
                    newOrderDetail.quantity  = item.quantity;
                    repoOrderDetail.Save(newOrderDetail);
                }
                decimal total = (decimal)Basket.Sum(x => x.quantity * x.product.price);
                //indirim kullanımı talep edilmişse
                if (Session["discount"] != null)
                {
                    coupons _discount = (coupons)Session["discount"];
                    //indirim kullanılıyor.
                    total -= (decimal)_discount.discount;
                    // indirim kullanıldığı için indirimi pasif et
                    coupons usedCoupon = repoCoupon.GetAll().FirstOrDefault(x => x.couponCode == _discount.couponCode);
                    // kullanıldı olarak işaretle
                    usedCoupon.isUsed = true;
                    // durumunu pasif et
                    usedCoupon.isActive = false;
                    // değişklilikleri güncelle
                    repoCoupon.Update(usedCoupon);
                    // sipariş tablosundaki indirim tutarını ekle
                    newOrder.discountPrice = _discount.discount;
                }
                if (total >= 2500)
                {
                    string couponCode = createCouponCode();
                    string subject    = " Bookstore İndirim Kuponu";
                    string body       = "Tebrikler! 2500 TL alışveriş yaptığınız için % 5 indirim kuponu kazandınız." +
                                        "Bir sonraki alışverişinizde indirim kuponunuzu kullanmak için son gün:" + DateTime.Now.AddDays(10);
                    coupons newCoupon = new coupons()
                    {
                        userId     = loginUser.userId,
                        isActive   = true,
                        created    = DateTime.Now,
                        expired    = DateTime.Now.AddDays(10),
                        couponCode = couponCode,
                        Title      = "%5 Hediye kuponu",
                        discount   = Basket.Sum(x => x.quantity * x.product.price) * 0.05m,
                        isUsed     = false
                    };

                    //kupon haketmişse kaydediliyor.
                    repoCoupon.Save(newCoupon);
                    // kupon haketmişse mail gönderiliyor.
                    SendCouponMail(User.Identity.Name, couponCode, subject, body);
                }
                //sipariş tutarı güncelleniyor
                newOrder.orderPrice = total;
                repoOrder.Update(newOrder);

                SendOrderInfo(loginUser.email);
                message = " Sipariş işlemi tamamlandı. siparişiniz ile ilgili bilgi mailinize gönderilmiştir. <br/>" +
                          "Goldstore sayfanızda sipariş detaylarını görebilirisiniz. Detay için aşağıdaki linke tıklayınız";
                status = true;
                // satışı tamamla
                orderCompleted = true;
                if (orderCompleted)
                {
                    // sepeti temizle;
                    Session.Remove("card");
                    //indirim sil
                    Session.Remove("discount");
                    // gönderme ücretini sil
                    Session.Remove("shipPrice");
                }
            }
            ViewBag.message = message;
            ViewBag.status  = status;
            return(View());
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("../Index.aspx");
            }
            else
            {
                Label1.Text = "Administrator";
                coupons cou = new coupons();

                na_bar.Controls.Add(new LiteralControl(cou.coup_nav()));


                SqlConnection cn = new SqlConnection();
                cn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cnstring"].ToString();
                cn.Open();
                String        s    = " SELECT * FROM coupons  order by limit desc ";
                SqlCommand    cmd  = new SqlCommand(s, cn);
                SqlDataReader dr   = cmd.ExecuteReader();
                return_       name = new return_();


                int count = 0;
                int co    = 0;
                while (dr.Read())
                {
                    count++;
                    co++;
                    string nam_ = name.bal_(dr[1].ToString(), "companyname", 9);
                    myPortfolio.Controls.Add(new LiteralControl(" <li onclick='' class='item " + nam_ + " col-sm-4'><div class='border'>"));


                    myPortfolio.Controls.Add(new LiteralControl("	<div class='view image-hover-1'>"));

                    myPortfolio.Controls.Add(new LiteralControl("<img class='img-responsive full-width' src='../images/coupons/" + count + ".jpg' >"));

                    myPortfolio.Controls.Add(new LiteralControl("<div class='mask'>   <div class='image-hover-content'>"));

                    myPortfolio.Controls.Add(new LiteralControl("<b><span class='badge' style='color:white;font-size:15px' ><b>Coupon Count : " + dr[4].ToString() + "</b></span>"));
                    myPortfolio.Controls.Add(new LiteralControl("</div></div> </div><div class='portfolio-text background-white'>	<h1 class='portfolio-title'> Get "+ dr[2].ToString() + " % cashback </h1><div class='project-category'> "));

                    Button l = new Button();
                    l.Text = " Coupon - " + dr[3].ToString();

                    l.Attributes.Add("style", "margin-left:20px");
                    l.CssClass = "button button-glow button-rounded button-caution";

                    myPortfolio.Controls.Add(l);



                    myPortfolio.Controls.Add(new LiteralControl("</Div> </Div></div></li>"));


                    if (count == 3)
                    {
                        count = 0;
                    }
                }


                cmd.Dispose();
                cn.Close();

                if (co == 0)
                {
                    myPortfolio.Controls.Add(new LiteralControl("<div class='button button-glow button-rounded button-highlight'>No Coupons Found</div><br><br><b"));
                }
            }
        }