Example #1
0
        public ActionResult Payment(string customerName, string customerPhone, string customerEmail)
        {
            var order = new Order();

            order.CreateDate = DateTime.Now;
            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CartSession];
                var detailDao = new OrderDetailsDao();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.OrderID  = id;
                    orderDetail.MovieID  = item.Movie.MovieID;
                    orderDetail.Price    = 0;
                    orderDetail.Quantity = item.Quantity;
                    detailDao.Insert(orderDetail);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Redirect("/hoan-thanh"));
        }
        public ActionResult Payment(string firstName,
                                    string lastName,
                                    string companyName,
                                    string phoneNumber,
                                    string emailAddress,
                                    string countryName,
                                    string provinceName,
                                    string districtName,
                                    string wardName,
                                    string notesInfo,
                                    string zipName,
                                    string orderNotes,
                                    string paymentMethod)
        {
            var  userSession = Session[UserSession] as UserLogin;
            long userID;

            if (userSession == null)
            {
                var user = new User();
                user.Name    = firstName.Trim() + " " + lastName.Trim();
                user.Email   = emailAddress.Trim();
                user.Phone   = phoneNumber.Trim();
                user.Address = countryName.Trim() + ", " + provinceName.Trim() + ", " + districtName.Trim() + ", " + wardName.Trim();
                userID       = new UserDao().Insert(user);
            }
            else
            {
                userID = userSession.UserID;
            }
            var purchaseOrder = new PurchaseOrder();

            purchaseOrder.OrderDate = DateTime.Now;
            purchaseOrder.Status    = false;
            purchaseOrder.PayID     = int.Parse(paymentMethod);
            new OrderDao().Insert(purchaseOrder);

            var listCart = Session[CartSession] as List <CartItem>;
            var odao     = new OrderDetailsDao();
            var pdao     = new ProductDao();

            listCart.ForEach(p =>
            {
                var value      = new PurchaseOrderDetail();
                value.UserID   = userID;
                value.PoID     = purchaseOrder.PoID;
                value.ShoeID   = long.Parse(p.Product.ShoeID.ToString());
                value.Quantity = p.Quantity;
                value.Cost     = p.Quantity * p.Product.Price;
                value.Color    = pdao.GetColorName(p.Product.ColorID);
                value.Size     = decimal.Parse(p.Size.ToString());
                odao.Insert(value);
            });

            Session[CartSession] = null;

            return(View());
        }
Example #3
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreateDate  = 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 OrderDetailsDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.OrderID   = id;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);


                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/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, "New Order From OnlineShop", content);
                new MailHelper().SendMail(toEmail, "New Order From OnlineShop", content);
            }
            catch (Exception)
            {
                return(Redirect("/NotSuccess"));
            }

            return(Redirect("/Success"));
        }
Example #4
0
 public ActionResult PaymentWithCOD(Data.Models.Order orderInput)
 {
     try
     {
         var order = new Data.Models.Order()
         {
             CreatedDate     = DateTime.Now,
             PaymentMethod   = "COD",
             ShipAddress     = orderInput.ShipAddress,
             ShipEmail       = orderInput.ShipEmail,
             ShipMobile      = orderInput.ShipMobile,
             ShipDescription = orderInput.ShipDescription,
             Status          = 0,
             ShipName        = orderInput.ShipName
         };
         var insert     = new OrdersDao().Insert(order);
         var detailsDao = new OrderDetailsDao();
         if (insert)
         {
             foreach (var cart in CommonConstants.listCart)
             {
                 var orderDetail = new OrderDetails
                 {
                     ProductID = cart.Product.ID,
                     OrderID   = order.ID,
                     Price     = cart.Product.Price - cart.Product.Price * cart.Product.Discount / 100,
                     Quantity  = cart.Quantity
                 };
                 detailsDao.Insert(orderDetail);
             }
         }
         CommonConstants.listCart.Clear();
         Session.Remove("CartSession");
         return(RedirectToAction("Success", "Cart"));
     }
     catch
     {
         return(RedirectToAction("Index", "Cart"));
     }
 }
Example #5
0
 public void ReturnFalseWhenOrderDetailsIsNull()
 {
     Assert.AreEqual(false, orderDetails.Insert(null));
 }
Example #6
0
        public ActionResult PaymentWithPaypal(Data.Models.Order orderInput)
        {
            APIContext apiContext = Configuration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (String.IsNullOrEmpty(payerId))
                {
                    var profile = new WebProfile
                    {
                        name         = Guid.NewGuid().ToString(),
                        presentation = new Presentation
                        {
                            brand_name  = "ELEX Store",
                            locale_code = "US"
                        },
                        input_fields = new InputFields
                        {
                            no_shipping = 1
                        }
                    };
                    var createdProfile = profile.Create(apiContext);

                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority +
                                     "/Paypal/PaymentWithPayPal?";
                    var guid = Convert.ToString((new Random()).Next(100000));
                    baseURI += "guid=" + guid + "&webProfileId=" + createdProfile.id;
                    Session["webProfileId"] = createdProfile.id;
                    var    createdPayment    = this.CreatePayment(apiContext, baseURI + "guid=" + guid, createdProfile);
                    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;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    Session["OrderInput"] = orderInput;
                    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 webProfileId             = Session["webProfileId"].ToString();
                    Data.Models.Order orderModel = (Data.Models.Order)Session["OrderInput"];
                    try
                    {
                        var order = new Data.Models.Order()
                        {
                            CreatedDate     = DateTime.Now,
                            PaymentMethod   = "PayPal",
                            ShipAddress     = orderModel.ShipAddress,
                            ShipEmail       = orderModel.ShipEmail,
                            ShipMobile      = orderModel.ShipMobile,
                            ShipDescription = orderModel.ShipDescription,
                            Status          = 0,
                            ShipName        = orderModel.ShipName
                        };
                        var insert     = new OrdersDao().Insert(order);
                        var detailsDao = new OrderDetailsDao();
                        if (insert)
                        {
                            foreach (var cart in CommonConstants.listCart)
                            {
                                var orderDetail = new OrderDetails
                                {
                                    ProductID = cart.Product.ID,
                                    OrderID   = order.ID,
                                    Price     = cart.Product.Price - cart.Product.Price * cart.Product.Discount / 100,
                                    Quantity  = cart.Quantity
                                };
                                detailsDao.Insert(orderDetail);
                            }
                        }
                        var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                        WebProfile.Delete(apiContext, webProfileId);
                        Session.Remove("webProfileId");
                        CommonConstants.listCart.Clear();
                        Session["CartSession"] = CommonConstants.listCart;
                        if (executedPayment.state.ToLower() != "approved")
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    catch (Exception)
                    {
                        return(RedirectToAction("Index", "Cart"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Home"));
            }


            return(RedirectToAction("Success", "Cart"));
        }