Ejemplo n.º 1
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipAddress = address;
            order.ShipMobile  = mobile;
            order.ShipName    = shipName;
            order.ShipEmail   = email;

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new Model.Dao.OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);

                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
            }
            catch
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
Ejemplo n.º 2
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipAddress = address;
            order.ShipMobile  = mobile;
            order.ShipName    = shipName;
            order.ShipEmail   = email;
            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new Model.Dao.OrderDetailDao();
                decimal total     = 0;
                decimal quantity  = 0;
                string  price     = null;
                string  name      = null;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);
                    name     = item.Product.Name;
                    price    = item.Product.Price.ToString();
                    quantity = item.Quantity;

                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{NameProduct}}", name);

                content = content.Replace("{{Quantity}}", quantity.ToString("N0"));
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(email, "WHEYSTORE", content);
                new MailHelper().SendMail(toEmail, "WHEYSTORE", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }

            return(Redirect("/hoan-thanh"));
        }
        public ActionResult Payment(string First_Name, string Last_Name, string Street_Address, string Country, string City, string Phone, string Email)
        {
            //try
            //{
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipName    = First_Name + " " + Last_Name;
            order.ShipMobile  = Phone;
            order.ShipEmail   = Email;
            //order.Status = Status ? 1 : 0;
            order.ShipAddress = Street_Address + "-" + City + "-" + Country;

            var     id        = new OrderDao().Insert(order);
            var     cart      = (List <CartItem>)Session[CartSession];
            var     detailDao = new Model.Dao.OrderDetailDao();
            decimal total     = 0;

            if (cart.Count > 0)
            {
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);

                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
            }
            string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

            content = content.Replace("{{CustomerName}}", order.ShipName);
            content = content.Replace("{{Phone}}", order.ShipMobile);
            content = content.Replace("{{Email}}", order.ShipEmail);
            content = content.Replace("{{Address}}", order.ShipAddress);
            content = content.Replace("{{Total}}", total.ToString("N0"));
            var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

            new MailHelper().SendMail(order.ShipEmail, "Đơn hàng mới từ HLwatch", content);
            new MailHelper().SendMail(toEmail, "Đơn hàng mới từ HLwatch", content);

            //return View();
            return(Redirect("/thanh-cong"));
            //}
            //catch (Exception)
            //{
            //    return Redirect("/loi-thanh-toan");
            //    throw;
            //}
        }
Ejemplo n.º 4
0
        public ActionResult Payment(string shipname, string address, string mobile, string email)
        {
            var order = new Order();

            order.CreateDate  = DateTime.Now;
            order.ShipAddress = address;
            order.ShipPhone   = mobile;
            order.ShipName    = shipname;
            order.ShipEmail   = email;
            if (order.ShipAddress != null && order.ShipPhone != null && order.ShipName != null &&
                order.ShipAddress != "" && order.ShipPhone != "" && order.ShipName != "")
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new Model.Dao.OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderdetail = new OrderDetail();
                    orderdetail.BookID   = item.Book.ID;
                    orderdetail.OrderID  = id;
                    orderdetail.Price    = item.Book.Price;
                    orderdetail.Quantity = item.Quantity;
                    detailDao.Insert(orderdetail);

                    total += (item.Book.Price.GetValueOrDefault(0) * item.Quantity);
                    Session[CommonConstants.CartSession] = null;
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipname);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            else
            {
                return(Redirect("/loi-mua-hang"));
            }

            return(Redirect("/hoan-thanh"));
        }
Ejemplo n.º 5
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreateDate  = DateTime.Now;
            order.ShipName    = shipName;
            order.ShipMobile  = mobile;
            order.ShipAddress = address;
            order.ShipEmail   = email;

            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CartSession];
                var detailDao = new Model.Dao.OrderDetailDao();


                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    var odd         = new OrderDetailDao();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    //item.Product.Quantity -= item.Quantity;
                    odd.UpdatePDQuantity(item.Product, item.Quantity);
                    detailDao.Insert(orderDetail);
                }
            }
            catch (Exception)
            {
                return(Redirect("/gioi-thieu"));
            }
            return(Redirect("/hoan-thanh-don-hang"));
        }
Ejemplo n.º 6
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipAddress = address;
            order.ShipMobile  = mobile;
            order.ShipName    = shipName;
            order.ShipEmail   = email;

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new Model.Dao.OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    if (ModelState.IsValid)
                    {
                        var dao      = new ProductDao();
                        var product  = new Product();
                        var quantity = item.Product.Quantity;
                        product.ID               = item.Product.ID;
                        product.Name             = item.Product.Name;
                        product.Code             = item.Product.Code;
                        product.MetaTitle        = item.Product.MetaTitle;
                        product.Description      = item.Product.Description;
                        product.Image            = item.Product.Image;
                        product.MoreImages       = item.Product.MoreImages;
                        product.PromotionPrice   = item.Product.PromotionPrice;
                        product.IncludedVAT      = item.Product.IncludedVAT;
                        product.Price            = item.Product.Price;
                        product.Quantity         = quantity - item.Quantity;
                        product.CategoryID       = item.Product.CategoryID;
                        product.Detail           = item.Product.Detail;
                        product.Warranty         = item.Product.Warranty;
                        product.CreatedBy        = item.Product.CreatedBy;
                        product.CreatedDate      = item.Product.CreatedDate;
                        product.ModifiedDate     = item.Product.ModifiedDate;
                        product.ModifiedBy       = item.Product.ModifiedBy;
                        product.MetaKeywords     = item.Product.MetaKeywords;
                        product.MetaDescriptions = item.Product.MetaDescriptions;
                        product.Status           = item.Product.Status;
                        product.TopHot           = item.Product.TopHot;
                        product.ViewCount        = item.Product.ViewCount + item.Quantity;
                        product.Color            = item.Product.Color;
                        product.Fuels            = item.Product.Fuels;
                        product.Gear             = item.Product.Gear;
                        var result = dao.Update(product);
                    }
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);
                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(email, "Đơn hàng mới từ Car Market", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ Car Market", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            Session[CartSession] = null;
            return(Redirect("/hoan-thanh"));
        }
Ejemplo n.º 7
0
        //Pay=paypal
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            UserLogin user     = (UserLogin)Session[Common.CommonConstants.USER_SESSION];
            var       cart     = (List <CartItem>)Session[Common.CommonConstants.CART_SESSION];
            var       itemList = new List <CartItem>();

            if (cart != null)
            {
                itemList = (List <CartItem>)cart;
            }
            var coupon     = (List <Coupon>)Session[Common.CommonConstants.COUPON_SESSION];
            var couponList = new List <Coupon>();

            if (cart != null)
            {
                couponList = (List <Coupon>)coupon;
            }
            var productDao = new ProductDao();

            //check quantity+status của product
            foreach (var item in cart)
            {
                if (productDao.CheckProduct(item.Product.ID, item.Quantity) == false)
                {
                    var alertMessage = "Số lượng sản phẩm [" + item.Product.Name + "] đã hết. Xin vui lòng chọn sản phẩm khác.";
                    SetAlert(alertMessage, "error");
                    return(Redirect("/het-san-pham"));
                }
            }
            //getting the apiContext
            APIContext apiContext = helper.PaypalConfiguration.GetAPIContext();

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    // So we have provided URL of this controller only
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority +
                                     "/Cart/PaymentWithPaypal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution.
                    //guid we are generating for storing the paymentID received in session
                    //after calling the create function and it is used in the payment execution
                    var guid = Convert.ToString((new Random()).Next(100000));
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This section is executed when we have received all the payments parameters
                    // from the previous call to the function Create
                    // Executing a payment
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        Session.Remove(guid);
                        return(View("FailureView"));
                    }

                    //Tới đây coi như thành công
                    //ghi order vào databasse
                    var orderDetailDao  = new Model.Dao.OrderDetailDao();
                    var orderCounponDao = new Model.Dao.OrderCouponDao();
                    var order           = new Model.EF.Order();
                    order.CreatedDate = DateTime.Parse(executedPayment.create_time);
                    if (user != null)
                    {
                        order.CustomerID = user.UserID;
                    }
                    order.ShipName    = executedPayment.payer.payer_info.shipping_address.recipient_name;
                    order.ShipMobile  = executedPayment.payer.payer_info.shipping_address.phone;
                    order.ShipAddress = executedPayment.payer.payer_info.shipping_address.line1 + ", "
                                        + executedPayment.payer.payer_info.shipping_address.city + ", "
                                        + executedPayment.payer.payer_info.shipping_address.state + ", "
                                        + executedPayment.payer.payer_info.shipping_address.country_code + ".";
                    order.ShipEmail = executedPayment.payer.payer_info.email;
                    order.Status    = -1; //đang chờ shipper nhận
                    var     orderID    = new OrderDao().Insert(order);
                    decimal sumProduct = 0;
                    foreach (var item in itemList)
                    {
                        //Xử lý orderDetail
                        var orderDetail = new OrderDetail();
                        orderDetail.ProductID = item.Product.ID;
                        orderDetail.OrderID   = orderID;
                        decimal?tempPrice = item.Product.PromotionPrice != null ? item.Product.PromotionPrice : item.Product.Price;
                        orderDetail.Price    = tempPrice;
                        orderDetail.Quantity = item.Quantity;
                        orderDetailDao.Insert(orderDetail);
                        //Xử lý sản phẩm // cập nhật số lượng sản phẩm
                        productDao.UpdateQuantity(item.Product.ID, item.Quantity);
                        //
                        sumProduct += orderDetail.Price.GetValueOrDefault(0) * orderDetail.Quantity.GetValueOrDefault(0);
                    }
                    //xử lý coupon + CouponUser
                    var couponDao     = new CouponDao();
                    var couponUserDao = new CouponUserDao();
                    if (couponList != null)
                    {
                        foreach (var item in couponList)
                        {
                            //xử lý coupon // giảm quantity của coupon đi 1
                            couponDao.UseCouponDiscountCode(item.Code);
                            //Xử lý CouponUser
                            var couponUser = new CouponUser();
                            couponUser.CouponID = item.ID;
                            couponUser.UserID   = user.UserID;
                            couponUserDao.Insert(couponUser);
                            //Xử lý orderCoupon
                            var orderCoupon = new OrderCoupon();
                            orderCoupon.OrderID  = orderID;
                            orderCoupon.CouponID = item.ID;
                            decimal tempAmount = 0;
                            if (item.ByPercentage == true)
                            {
                                tempAmount = sumProduct * item.DiscountBy / 100; //discount theo %
                            }
                            else
                            {
                                tempAmount = item.DiscountBy; //discount cố định
                            }
                            orderCoupon.DiscountAmount = tempAmount;
                            orderCounponDao.Insert(orderCoupon);
                        }
                    }
                    //gán cart+coupon null
                    Session[Common.CommonConstants.CART_SESSION]   = null;
                    Session[Common.CommonConstants.COUPON_SESSION] = null;
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Error" + ex.Message);
                return(View("FailureView"));
            }
            //on successful payment, show success page to user.
            return(View("SuccessView"));
        }
Ejemplo n.º 8
0
        public ActionResult Payment(string shipName,string mobile,string address,string email)
        {
            var order = new Order();
            order.CreatedDate = DateTime.Now;
            order.ShipAddress = address;
            order.ShipMobile = mobile;
            order.ShipName = shipName;
            order.ShipEmail = email;

            try
            {
                var id = new OrderDao().Insert(order);
                var cart = (List<CartItem>)Session[CartSession];
                var detailDao = new Model.Dao.OrderDetailDao();
                decimal total = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID = id;
                    orderDetail.Price = item.Product.Price;
                    orderDetail.Quantity = item.Quantity;
                    detailDao.Insert(orderDetail);

                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return Redirect("/loi-thanh-toan");
            }
            return Redirect("/hoan-thanh");
        }