//function ssave order when order success!
        public void saveOrder(Morder order, string paymentMethod, int StatusPayment, string ordercode)
        {
            var cart = Session[SessionCart];
            var list = new List <Cart_item>();

            if (cart != null)
            {
                list = (List <Cart_item>)cart;
            }

            if (ModelState.IsValid)
            {
                order.code   = ordercode;
                order.userid = 1;
                order.deliveryPaymentMethod = paymentMethod;
                order.StatusPayment         = StatusPayment;
                order.created_ate           = DateTime.Now;
                order.updated_by            = 1;
                order.updated_at            = DateTime.Now;
                order.updated_by            = 1;
                order.status     = 2;
                order.exportdate = DateTime.Now;
                db.Orders.Add(order);
                db.SaveChanges();
                Session["OrderId"] = ordercode;
                ViewBag.name       = order.deliveryname;
                ViewBag.email      = order.deliveryemail;
                ViewBag.address    = order.deliveryaddress;
                ViewBag.code       = order.code;
                ViewBag.phone      = order.deliveryphone;
                Mordersdetail orderdetail = new Mordersdetail();

                foreach (var item in list)
                {
                    float price = 0;
                    int   sale  = (int)item.product.pricesale;
                    if (sale > 0)
                    {
                        price = (float)item.product.price - (int)item.product.price / 100 * (int)sale * item.quantity;
                    }
                    else
                    {
                        price = (float)item.product.price * (int)item.quantity;
                    }
                    orderdetail.orderid   = order.ID;
                    orderdetail.productid = item.product.ID;
                    orderdetail.priceSale = (int)item.product.pricesale;
                    orderdetail.price     = item.product.price;
                    orderdetail.quantity  = item.quantity;
                    orderdetail.amount    = price;

                    db.Ordersdetails.Add(orderdetail);
                    db.SaveChanges();
                    var updatedProduct = db.Products.Find(item.product.ID);
                    db.Products.Attach(updatedProduct);
                    db.Entry(updatedProduct).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
        public ActionResult Retrash(int id)
        {
            Morder morder = db.Orders.Find(id);

            db.Entry(morder).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("Khôi phục thành công", "success");
            return(RedirectToAction("trash"));
        }
        public ActionResult deleteTrash(int id)
        {
            Morder morder = db.Orders.Find(id);

            db.Orders.Remove(morder);
            db.SaveChanges();
            Message.set_flash("Đã xóa vĩnh viễn 1 Đơn hàng", "success");
            return(RedirectToAction("trash"));
        }
        //status
        public ActionResult Status(int id)
        {
            Morder morder = db.Orders.Find(id);

            db.Entry(morder).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("Thay đổi trang thái thành công", "success");
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult Retrash(int id)
        {
            Morder morder = db.Orders.Find(id);

            morder.status          = 2;
            morder.updated_at      = DateTime.Now;
            morder.updated_by      = int.Parse(Session["Admin_id"].ToString());
            db.Entry(morder).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("Khôi phục thành công", "success");
            return(RedirectToAction("trash"));
        }
示例#6
0
        //status
        public ActionResult Status(int id)
        {
            Morder morder = db.Orders.Find(id);

            morder.status          = (morder.status == 1) ? 2 : 1;
            morder.updated_at      = DateTime.Now;
            morder.updated_by      = int.Parse(Session["Admin_id"].ToString());
            db.Entry(morder).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("Thay đổi trang thái thành công", "success");
            return(RedirectToAction("Index"));
        }
示例#7
0
        /// <summary>
        /// 根据ID获取一个订单model
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Morder GetOrderInfroById(string id)
        {
            Morder morder = null;

            try
            {
                morder = new OrderService().GetOrderInfoById(id);
            }
            catch (Exception ex)
            {
            }

            return(morder != null ? morder : new Morder());
        }
        public ActionResult formCheckOut(FormCollection f)
        {
            //Muser user = (Muser)Session[Common.CommonConstants.CUSTOMER_SESSION];
            var    tenKH    = f["deliveryname"];
            var    SDT      = f["deliveryphone"];
            var    email    = f["deliveryemail"];
            var    diaChi   = f["deliveryaddress"];
            var    TongTien = f["sumOrder"];
            Morder order    = new Morder();

            order.deliveryname    = tenKH;
            order.deliveryphone   = SDT;
            order.deliveryemail   = email;
            order.deliveryaddress = diaChi;
            order.updated_at      = DateTime.Today;
            db.Orders.Add(order);
            db.SaveChanges();
            var cart  = Session[SessionCart];
            var list1 = new List <Cart_item>();

            if (cart != null)
            {
                list1 = (List <Cart_item>)cart;
            }
            var orderid = db.Orders.OrderByDescending(m => m.ID).ToList()[0].ID;

            foreach (var item in list1)
            {
                Mordersdetail detail = new Mordersdetail();
                detail.orderid   = orderid;
                detail.productid = item.product.ID;
                detail.price     = item.product.price;
                detail.quantity  = item.quantity;
                detail.priceSale = item.product.pricesale;
                detail.amount    = (detail.price * (100 - detail.priceSale) / 100) * detail.quantity;
                db.Ordersdetails.Add(detail);
                db.SaveChanges();
            }
            return(View("OrderComplete"));
        }
示例#9
0
        public ActionResult Index(Morder order)
        {
            Random rand          = new Random((int)DateTime.Now.Ticks);
            int    numIterations = 0;

            numIterations = rand.Next(1, 100000);
            DateTime time = DateTime.Now;

            string orderCode      = numIterations + "" + time;
            string sumOrder       = Request["sumOrder"];
            string payment_method = Request["option_payment"];

            // Neu Ship COde
            if (payment_method.Equals("COD"))
            {
                // cap nhat thong tin sau khi dat hang thanh cong

                saveOrder(order, "COD", 2, orderCode);
                var cart = Session[SessionCart];
                var list = new List <Cart_item>();
                ViewBag.cart           = (List <Cart_item>)cart;
                Session["SessionCart"] = null;
                var listProductOrder = db.Orderdetails.Where(m => m.orderid == order.ID);
                return(View("payment"));
            }
            //Neu Thanh toan MOMO
            else if (payment_method.Equals("MOMO"))
            {
                //request params need to request to MoMo system
                string endpoint    = momoInfo.endpoint;
                string partnerCode = momoInfo.partnerCode;
                string accessKey   = momoInfo.accessKey;
                string serectkey   = momoInfo.serectkey;
                string orderInfo   = momoInfo.orderInfo;
                string returnUrl   = momoInfo.returnUrl;
                string notifyurl   = momoInfo.notifyurl;

                string amount    = sumOrder;
                string orderid   = Guid.NewGuid().ToString();
                string requestId = Guid.NewGuid().ToString();
                string extraData = "";

                //Before sign HMAC SHA256 signature
                string rawHash = "partnerCode=" +
                                 partnerCode + "&accessKey=" +
                                 accessKey + "&requestId=" +
                                 requestId + "&amount=" +
                                 amount + "&orderId=" +
                                 orderid + "&orderInfo=" +
                                 orderInfo + "&returnUrl=" +
                                 returnUrl + "&notifyUrl=" +
                                 notifyurl + "&extraData=" +
                                 extraData;

                log.Debug("rawHash = " + rawHash);

                MoMoSecurity crypto = new MoMoSecurity();
                //sign signature SHA256
                string signature = crypto.signSHA256(rawHash, serectkey);
                log.Debug("Signature = " + signature);

                //build body json request
                JObject message = new JObject
                {
                    { "partnerCode", partnerCode },
                    { "accessKey", accessKey },
                    { "requestId", requestId },
                    { "amount", amount },
                    { "orderId", orderid },
                    { "orderInfo", orderInfo },
                    { "returnUrl", returnUrl },
                    { "notifyUrl", notifyurl },
                    { "extraData", extraData },
                    { "requestType", "captureMoMoWallet" },
                    { "signature", signature }
                };
                log.Debug("Json request to MoMo: " + message.ToString());
                string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
                JObject jmessage         = JObject.Parse(responseFromMomo);

                saveOrder(order, "Cổng thanh toán MOMO", 2, orderid);
                return(Redirect(jmessage.GetValue("payUrl").ToString()));
            }
            //Neu Thanh toan Ngan Luong
            else if (payment_method.Equals("NL"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "Cổng thanh toán Ngân Lượng", 2, orderCode);
                    // chuyen sang trang ngan luong
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            //Neu Thanh Toán ATM online
            else if (payment_method.Equals("ATM_ONLINE"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "ATM Online qua ngân lượng", 2, orderCode);
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            return(View("payment"));
        }
示例#10
0
        public async Task <ActionResult> Index(Morder order)
        {
            var cart = Session[SessionCart];
            var list = new List <Cart_item>();

            if (cart != null)
            {
                list = (List <Cart_item>)cart;
            }
            Random rand = new Random((int)DateTime.Now.Ticks);
            int    RandomNumber;

            RandomNumber = rand.Next(100, 100000);
            if (ModelState.IsValid)
            {
                order.code        = RandomNumber;
                order.userid      = 1;
                order.created_ate = DateTime.Now;
                order.updated_by  = 1;
                order.updated_at  = DateTime.Now;
                order.status      = 2;
                order.exportdate  = DateTime.Now;
                db.Orders.Add(order);
                db.SaveChanges();

                ViewBag.name    = order.deliveryname;
                ViewBag.email   = order.deliveryemail;
                ViewBag.address = order.deliveryaddress;
                ViewBag.code    = order.code;
                ViewBag.phone   = order.deliveryphone;
                Mordersdetail orderdetail = new Mordersdetail();

                foreach (var item in list)
                {
                    float price = 0;
                    int   sale  = (int)item.product.pricesale;
                    if (sale > 0)
                    {
                        price = (float)item.product.price - (int)item.product.price / 100 * (int)sale * item.quantity;
                    }
                    else
                    {
                        price = (float)item.product.price * (int)item.quantity;
                    }
                    orderdetail.orderid   = order.ID;
                    orderdetail.productid = item.product.ID;
                    orderdetail.priceSale = (int)item.product.pricesale;
                    orderdetail.price     = item.product.price;
                    orderdetail.quantity  = item.quantity;
                    orderdetail.amount    = price;

                    db.Orderdetails.Add(orderdetail);
                    await db.SaveChangesAsync();

                    //ViewBag.sump = list.Sum((Func<Cart_item, int>)(m => (int)m.product.price * (int) m.quantity));
                    // change number product
                    var updatedProduct = db.Products.Find(item.product.ID);
                    updatedProduct.catid      = item.product.catid;
                    updatedProduct.Submenu    = item.product.Submenu;
                    updatedProduct.name       = item.product.name;
                    updatedProduct.slug       = item.product.slug;
                    updatedProduct.img        = item.product.img;
                    updatedProduct.detail     = item.product.detail;
                    updatedProduct.number     = (int)updatedProduct.number - (int)item.quantity;
                    updatedProduct.price      = item.product.price;
                    updatedProduct.pricesale  = item.product.pricesale;
                    updatedProduct.metakey    = item.product.metakey;
                    updatedProduct.metadesc   = item.product.metadesc;
                    updatedProduct.created_by = item.product.created_by;
                    updatedProduct.created_at = item.product.created_at;
                    updatedProduct.updated_by = item.product.updated_by;
                    updatedProduct.updated_at = item.product.updated_at;
                    updatedProduct.status     = item.product.status;
                    db.Products.Attach(updatedProduct);
                    db.Entry(updatedProduct).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
                ViewBag.cart           = (List <Cart_item>)cart;
                Session["SessionCart"] = null;
                var listProductOrder = db.Orderdetails.Where(m => m.orderid == order.ID);
                return(View("payment", listProductOrder.ToList()));
            }
            ViewBag.error = "Đặt hàng thất bại";
            return(View("index"));
        }
示例#11
0
        public ActionResult Index(Morder order)
        {
            Random rand          = new Random((int)DateTime.Now.Ticks);
            int    numIterations = 0;

            numIterations = rand.Next(1, 100000);
            DateTime time = DateTime.Now;

            string orderCode      = numIterations + "" + time;
            string sumOrder       = Request["sumOrder"];
            string payment_method = Request["option_payment"];

            // Neu Ship COde
            if (payment_method.Equals("COD"))
            {
                // cap nhat thong tin sau khi dat hang thanh cong

                saveOrder(order, "COD", 2, orderCode);
                var cart = Session[SessionCart];
                var list = new List <Cart_item>();
                ViewBag.cart           = (List <Cart_item>)cart;
                Session["SessionCart"] = null;
                var listProductOrder = db.Orderdetails.Where(m => m.orderid == order.ID);
                return(View("payment"));
            }
            //Neu Thanh toan Ngan Luong
            else if (payment_method.Equals("NL"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = ShopCayCanh.nganluonAPI.nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "Cổng thanh toán Ngân Lượng", 2, orderCode);
                    // chuyen sang trang ngan luong
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            //Neu Thanh Toán ATM online
            else if (payment_method.Equals("ATM_ONLINE"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "ATM Online qua ngân lượng", 2, orderCode);
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            return(View("payment"));
        }