Esempio n. 1
0
        public ActionResult Payment(string name, string phone, string address, string email)
        {
            var tran = new Transaction();

            tran.userName    = name;
            tran.userPhone   = phone;
            tran.userAddress = address;
            tran.userMail    = email;

            try
            {
                var id       = new TransactionDao().Insert(tran);
                var cart     = (List <CartItem>)Session[CartSession];
                var orderDao = new OrderDao();
                foreach (var item in cart)
                {
                    var order = new Oder();
                    order.productId = item.Product.productId;
                    order.tranId    = id;
                    order.price     = item.Product.price;
                    order.quatity   = item.Quantity;
                    order.size      = item.Size;
                    order.createDay = DateTime.Now;
                    orderDao.Insert(order);
                }
            }
            catch (Exception ex)
            {
                return(Redirect("/loi-thanh-toan"));
            }


            return(Redirect("/hoan-thanh"));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutOder(int id, Oder oder)
        {
            if (id != oder.Id)
            {
                return(BadRequest());
            }

            _context.Entry(oder).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Status,CustomerID,ShipName,ShipMobile,ShipAddress,ShipEmail,CreatedDate")] Oder oder)
        {
            if (id != oder.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(oder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OderExists(oder.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(oder));
        }
Esempio n. 4
0
        public static int addOder(ModelView.OderView item)
        {
            db = new ShopOnlineEntities();
            try
            {
                Oder od = new Oder
                {
                    CustAddress = item.CustAddress,

                    CustEmail = item.CustEmail,
                    CustName  = item.CustName,
                    CustPhone = item.CustPhone,
                    DayCreate = DateTime.Now,
                    IDU       = item.IDU,
                    Zipcode   = "Hihi"
                };
                db.Oders.Add(od);
                db.SaveChanges();
                return(od.id);
            }
            catch (Exception)
            {
                throw;
            }
            return(0);
        }
Esempio n. 5
0
        public async Task <ActionResult <Oder> > PostOder(Oder oder)
        {
            _context.oders.Add(oder);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOder", new { id = oder.Id }, oder));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,OderDate,UserId,Status,TotalPrice")] Oder oder)
        {
            if (id != oder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(oder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OderExists(oder.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.users, "ID", "Address", oder.UserId);
            return(View(oder));
        }
Esempio n. 7
0
        public bool XoaOder(Oder od)
        {
            string[] parem  = { "@MaOder" };
            object[] values = { od.MaOder };
            string   query  = "Delete from tblOder where MaOder=@MaOder";

            return(db.ExecuteNonQueryPara(query, parem, values));
        }
Esempio n. 8
0
        public bool ChuyenBan(Oder od)
        {
            string[] param  = { "@MaOder", "@MaBan" };
            object[] values = { od.MaOder, od.MaBan };
            string   query  = "Update tblOder set MaBan=@MaBan where MaOder=@MaOder";

            return(db.ExecuteNonQueryPara(query, param, values));
        }
Esempio n. 9
0
 private void OnEnable()
 {
     Instance = this;
     idVatPhamUnlock();
     showOder();
     checkBan = true;
     check    = false;
 }
Esempio n. 10
0
        public bool ThemOder(Oder od)
        {
            string[] param  = { "@MaBan", "@MaOder", "@MaNV", "@Ngay" };
            object[] values = { od.MaBan, od.MaOder, od.MaNV, od.Ngay };
            string   query  = "Insert into tblOder(MaOder, MaBan,MaNV,Ngay) values(@MaOder,@MaBan,@MaNV,@Ngay)";

            return(db.ExecuteNonQueryPara(query, param, values));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("ID,Status,CustomerID,ShipName,ShipMobile,ShipAddress,ShipEmail,CreatedDate")] Oder oder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(oder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(oder));
        }
        public async Task <IActionResult> Create([Bind("Id,OderDate,UserId,Status,TotalPrice")] Oder oder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(oder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.users, "ID", "Address", oder.UserId);
            return(View(oder));
        }
Esempio n. 13
0
        public ActionResult Getbyid(string id)
        {
            var  data = db.Oders.First(u => u.id == id);
            Oder oder = new Oder();

            oder.id            = data.id;
            oder.total         = data.total;
            oder.priceShip     = data.priceShip;
            oder.status        = data.status;
            oder.noteSiteAdmin = data.noteSiteAdmin;
            return(Json(oder, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
 public bool Insert(Oder order)
 {
     try
     {
         db.Oders.Add(order);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 15
0
        public bool Update(Oder entity)
        {
            try
            {
                var order = db.Oders.Find(entity.oderId);
                order.quatity     = entity.quatity;
                order.size        = order.size;
                order.statusOrder = order.statusOrder;

                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 16
0
 public ActionResult Update(Oder model)
 {
     try
     {
         var loginInfo = ClassExten.GetCokies();
         var data      = db.Oders.First(u => u.id.Equals(model.id));
         data.status        = model.status;
         data.noteSiteAdmin = model.noteSiteAdmin;
         data.updateBy      = loginInfo.Id;
         data.updateDate    = DateTime.Now;
         db.SaveChanges();
         return(Json(new { ok = true, mess = "" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new { ok = false, mess = "" }, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 17
0
        public ActionResult Edit(Oder order)
        {
            if (ModelState.IsValid)
            {
                var dao    = new OrderDao();
                var result = dao.Update(order);

                if (result)
                {
                    return(RedirectToAction("Index", "Order"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập sản phẩm không thành công!!!");
                }
            }
            return(View("Index"));
        }
Esempio n. 18
0
        public ActionResult xacNhanDonHang(Oder model)
        {
            try
            {
                string lang      = ClassExten.GetLangSite();
                var    loginInfo = ClassExten.GetCokies();

                var data = db.Oders.First(u => u.id.Equals(model.id));
                data.status     = ClassExten.Bill_Status.DaMuaHang;
                data.updateDate = DateTime.Now;
                data.updateBy   = loginInfo.Id;
                db.SaveChanges();
                return(Json(new { ok = true, mess = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { ok = false, mess = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 19
0
        public IActionResult ThanhToan(string shipName, int mobile, string address, string email)
        {
            var model = _context.loais.ToList();

            ViewBag.model = model;

            var oder = new Oder();

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

            try
            {
                var id   = Insert(oder);
                var cart = SessionHelper.Get <List <Item> >(HttpContext.Session, "cart");
                foreach (var item in cart)
                {
                    var oderDetail = new OderDetail();
                    oderDetail.MaHH     = item.Product.MaHH;
                    oderDetail.OderID   = id;
                    oderDetail.Gia      = item.Product.DonGia;
                    oderDetail.Quantity = item.Quantity;
                    Insert1(oderDetail);

                    var hanghoas = _context.HangHoas.Where(x => x.MaHH == item.Product.MaHH).First();


                    hanghoas.DaMua += item.Quantity;
                    _context.Update(hanghoas);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            SessionHelper.Set(HttpContext.Session, "cart", "");
            return(View("HoanThanh", ViewBag.model));
        }
Esempio n. 20
0
        // Adding products to oders
        public bool addOder(clsOders c)
        {
            var newItm = new Oder
            {
                UserID          = c.id,
                FurID           = c.furID,
                Quantity        = c.quant,
                Dates           = DateTime.Now.Date,
                Status          = "Pending",
                ReferenceNumber = c.refNum
            };

            db.Oders.InsertOnSubmit(newItm);
            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                return(false);
            }
        }
Esempio n. 21
0
        public async Task <IActionResult> Mua(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.products
                          .Include(p => p.Brand)
                          .Include(p => p.Category)
                          .FirstOrDefaultAsync(m => m.ID == id);

            if (product == null)
            {
                return(NotFound());
            }
            Oder       oder       = new Oder();
            OderDetail oderDetail = new OderDetail();

            oder.OderDate   = DateTime.Now;
            oder.Status     = true;
            oder.TotalPrice = product.Price;
            oder.UserId     = HttpContext.Session.GetInt32("userId");
            _context.Add(oder);
            _context.SaveChanges();
            oderDetail.Quantity  = 1;
            oderDetail.price     = product.Price;
            oderDetail.OderId    = oder.Id;
            oderDetail.ProductId = product.ID;
            _context.Add(oderDetail);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));

            //return View(product);
        }
Esempio n. 22
0
 public bool ChuyenBan(Oder od)
 {
     return(oder.ChuyenBan(od));
 }
Esempio n. 23
0
 public bool XoaOder(Oder od)
 {
     return(oder.XoaOder(od));
 }
Esempio n. 24
0
        public async Task <IActionResult> ThanhToan(string shipName, string address)
        {
            var model = _context.loais.ToList();

            ViewBag.model = model;

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user.PhoneNumber == null)
            {
                ViewBag.NoPhoneNumber = "You dont have Phone Number. Pleave add your Phone Number in Manage Account.";
                return(View());
            }

            var cart = SessionHelper.Get <List <Item> >(HttpContext.Session, "cart");

            var oder = new Oder();

            oder.ID           = DateTime.Now.Ticks;
            oder.CreatedDate  = DateTime.Now;
            oder.CustomerID   = user.Id;
            oder.ShipName     = shipName;
            oder.ShipAddress  = address;
            oder.ShipMobile   = user.PhoneNumber;
            oder.ShipEmail    = user.Email;
            oder.CheckOutType = "Normal";

            var subTotal = cart.Sum(item => (item.Product.DonGia - item.Product.DonGia * item.Product.GiamGia / 100) * item.Quantity);

            oder.Total = Math.Round(subTotal, 0);
            _orderId   = oder.ID;


            try
            {
                var id = Insert(oder);
                foreach (var item in cart)
                {
                    var oderDetail = new OderDetail();
                    oderDetail.MaHH     = item.Product.MaHH;
                    oderDetail.OderID   = id;
                    oderDetail.Gia      = item.Product.DonGia;
                    oderDetail.Quantity = item.Quantity;
                    Insert1(oderDetail);

                    var hanghoas = _context.HangHoas.Where(x => x.MaHH == item.Product.MaHH).First();


                    hanghoas.DaMua += item.Quantity;
                    _context.Update(hanghoas);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(View("ThatBai"));
            }

            oder.Status = true;
            _context.Update(oder);
            _context.SaveChanges();

            return(View("HoanThanh"));
        }
Esempio n. 25
0
        //dat hang
        public ActionResult Dathang(Customer model)
        {
            ShoppingCartViewModel shoppCart;
            var cartGet = ClassExten.GetCokiesCart();

            if (cartGet == null)
            {
                return(Json(new { ok = 2, mess = "Lỗi không tìm thấy giỏ hàng" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                shoppCart = cartGet;
            }

            model.id     = Guid.NewGuid().ToString();
            model.active = true;
            model.type   = 1;
            Config conf;

            if (ConfigModel.listConfig == null)
            {
                ConfigModel.listConfig = db.Configs.ToList();
            }
            conf = ConfigModel.listConfig.FirstOrDefault();

            string host = Request.Url.Host;
            Oder   or   = new Oder();
            Oderdt dt;
            var    content = "<p><b>Danh sách sản phẩm đơn hàng:</b></p>";
            string cssth   = "style='padding-top:12px;padding-bottom:12px;text-align:left; background-color: #4CAF50;color: white; padding: 8px; '";
            string csstd   = "style='border: 1px solid #ddd; padding: 8px; '";
            var    list    = shoppCart;

            if (list.CartItems.Count > 0)
            {
                try
                {
                    content += "<table style='border-collapse: collapse; width: 100%'>";
                    content += "<tr>";
                    content += "<th " + cssth + ">Sản phẩm</th>";
                    content += "<th " + cssth + ">Số lượng</th>";
                    content += "<th " + cssth + ">Giá</th>";
                    content += "<th " + cssth + ">Tổng tiền</th>";
                    content += "</tr>";
                    string email = model.email;

                    var cus = db.Customers.FirstOrDefault(u => u.email == email);

                    or.createDate = DateTime.Now;
                    or.id         = Guid.NewGuid().ToString();

                    or.total = list.CartTotal + conf.priceShip;
                    // or.noteSite = model.noteSite;
                    or.noteSite   = string.Empty;
                    or.status     = ClassExten.Bill_Status.MoiTao;
                    or.priceShip  = conf.priceShip;
                    or.createDate = DateTime.Now;
                    if (cus != null)
                    {
                        or.cusId = cus.id;
                    }
                    else
                    {
                        db.Customers.Add(model);
                        or.cusId = model.id;
                    }
                    db.Oders.Add(or);

                    var    hostUrl    = Request.Url.Host;
                    string title      = "Thông tin đơn hàng tại " + hostUrl;
                    string titleAdmin = "Thông tin đơn hàng từ khách: " + model.fullName + " tại " + hostUrl;
                    for (int i = 0; i < list.CartItems.Count; i++)
                    {
                        dt            = new Oderdt();
                        dt.id         = Guid.NewGuid().ToString();
                        dt.oderId     = or.id;
                        dt.proId      = list.CartItems[i].productId;
                        dt.quantity   = list.CartItems[i].count;
                        dt.priceNow   = list.CartItems[i].price;
                        dt.priceCount = list.CartItems[i].price * list.CartItems[i].count;

                        content += "<tr>";
                        content += "<td " + csstd + "><a href='http://" + hostUrl + "/chi-tiet/" + list.CartItems[i].key + "' title='" + list.CartItems[i].productName + "'>" + list.CartItems[i].productName + "</a></td>";
                        content += "<td " + csstd + ">" + list.CartItems[i].count + "</td>";
                        content += "<td " + csstd + ">" + list.CartItems[i].price.ToString("N0") + "</td>";
                        content += "<td " + csstd + ">" + dt.priceCount.Value.ToString("N0") + "</td>";
                        content += "</tr>";
                        db.Oderdts.Add(dt);
                    }
                    db.SaveChanges();

                    if (Request.Cookies["cartNTS"] != null)
                    {
                        var c = new HttpCookie("cartNTS");
                        c.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(c);
                    }

                    content += "</table>";
                    switch (conf.typeSendMail)
                    {
                    case 2:
                    {
                        //Chỉ gửi Admin
                        ClassExten.SendMail(conf.email_Inbox, conf.email_Send, conf.emailPass, conf.mail_Port.Value, titleAdmin, content);
                    }
                    break;

                    case 3:
                    {
                        //Chỉ gửi cho khách
                        ClassExten.SendMail(model.email, conf.email_Send, conf.emailPass, conf.mail_Port.Value, title, content);
                    }
                    break;

                    case 4:
                    {
                        //gửi full
                        ClassExten.SendMail(model.email, conf.email_Send, conf.emailPass, conf.mail_Port.Value, title, content);
                        ClassExten.SendMail(conf.email_Inbox, conf.email_Send, conf.emailPass, conf.mail_Port.Value, titleAdmin, content);
                    }
                    break;

                    default:
                        break;
                    }


                    return(Json(new { ok = 1, mess = "" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception c)
                {
                    return(Json(new { ok = 0, mess = "" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { ok = 2, mess = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 26
0
        public async Task <IActionResult> ThanhToanPaypal()
        {
            var model = _context.loais.ToList();

            ViewBag.model = model;

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var environment = new SandboxEnvironment(_clientId, _secretKey);
            var client      = new PayPalHttpClient(environment);

            #region Create Paypal Order
            var cart     = SessionHelper.Get <List <Item> >(HttpContext.Session, "cart");
            var itemList = new ItemList()
            {
                Items = new List <item>()
            };
            //var total = Math.Round(cart.Sum(item => (item.Product.DonGia * item.Quantity) - ((item.Product.GiamGia) * (item.Product.DonGia)) / 100) / tyGiaUSD, 2);
            var total = cart.Sum(item => Math.Round(Math.Round(item.Product.DonGia / tyGiaUSD, 2) - Math.Round(Math.Round(item.Product.DonGia / tyGiaUSD, 2) * item.Product.GiamGia / 100, 2), 2) * item.Quantity);
            var giam  = Math.Round(cart.Sum(item => Math.Round(Math.Round(item.Product.DonGia / tyGiaUSD, 2) * item.Quantity * item.Product.GiamGia / 100, 2)), 2);
            //var total = Math.Round(sub - giam, 2);
            foreach (var item in cart)
            {
                itemList.Items.Add(new item()
                {
                    Name     = item.Product.TenHH,
                    Currency = "USD",
                    Price    = Math.Round(Math.Round(item.Product.DonGia / tyGiaUSD, 2) - Math.Round(Math.Round(item.Product.DonGia / tyGiaUSD, 2) * item.Product.GiamGia / 100, 2), 2).ToString(),
                    Quantity = item.Quantity.ToString(),
                    Sku      = "sku",
                    Tax      = "0"
                });
            }
            #endregion


            var paypalOrderId = DateTime.Now.Ticks;
            var hostname      = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";
            var payment       = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = total.ToString(),
                            Currency = "USD",
                            Details  = new AmountDetails
                            {
                                Tax      = "0",
                                Shipping = "0",
                                Subtotal = total.ToString()
                            }
                        },
                        ItemList      = itemList,
                        Description   = $"Invoice #{paypalOrderId}",
                        InvoiceNumber = paypalOrderId.ToString(),
                        Payee         = new Payee()
                        {
                            Email      = _email,
                            MerchantId = _merchantId
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = $"{hostname}/cart/that-bai",
                    ReturnUrl = $"{hostname}/cart/paypal-hoan-thanh"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            #region Insert Order to Database
            var oder = new Oder();
            oder.ID           = paypalOrderId;
            oder.ShipAddress  = "Paypal User";
            oder.ShipName     = "Paypal User";
            oder.ShipMobile   = "Paypal User";
            oder.ShipEmail    = "Paypal User";
            oder.CheckOutType = "Paypal";
            oder.CustomerID   = user.Id;
            oder.CreatedDate  = DateTime.Now;

            var subTotal = cart.Sum(item => (item.Product.DonGia - item.Product.DonGia * item.Product.GiamGia / 100) * item.Quantity);

            oder.Total = Math.Round(subTotal, 0);

            _orderId = oder.ID;
            SessionHelper.Set(HttpContext.Session, "orderId", _orderId);

            try
            {
                var id = Insert(oder);
                foreach (var item in cart)
                {
                    var oderDetail = new OderDetail();
                    oderDetail.MaHH     = item.Product.MaHH;
                    oderDetail.OderID   = id;
                    oderDetail.Gia      = item.Product.DonGia;
                    oderDetail.Quantity = item.Quantity;
                    Insert1(oderDetail);

                    var hanghoas = _context.HangHoas.Where(x => x.MaHH == item.Product.MaHH).First();

                    hanghoas.DaMua += item.Quantity;
                    _context.Update(hanghoas);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(View("ThatBai"));
            }
            #endregion
            PaymentCreateRequest request = new PaymentCreateRequest();
            request.RequestBody(payment);

            try
            {
                var response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                var    links             = result.Links.GetEnumerator();
                string paypalRedirectUrl = null;
                while (links.MoveNext())
                {
                    LinkDescriptionObject lnk = links.Current;
                    if (lnk.Rel.ToLower().Trim().Equals("approval_url"))
                    {
                        paypalRedirectUrl = lnk.Href;
                    }
                }

                return(Redirect(paypalRedirectUrl));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();

                return(Redirect("/cart/that-bai"));
            }
        }
Esempio n. 27
0
        public async Task <IActionResult> ThanhToanVnPay()
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var hostname = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

            var oder = new Oder();

            oder.ID           = DateTime.Now.Ticks;
            oder.ShipName     = "VNPay User";
            oder.ShipMobile   = "VNPay User";
            oder.ShipAddress  = "VNPay User";
            oder.ShipEmail    = "VNPay User";
            oder.CustomerID   = user.Id;
            oder.CreatedDate  = DateTime.Now;
            oder.CheckOutType = "VNPay";

            var cart     = SessionHelper.Get <List <Item> >(HttpContext.Session, "cart");
            var subTotal = cart.Sum(item => (item.Product.DonGia - item.Product.DonGia * item.Product.GiamGia / 100) * item.Quantity);

            oder.Total = Math.Round(subTotal);

            try
            {
                var id = Insert(oder);
                foreach (var item in cart)
                {
                    var oderDetail = new OderDetail();
                    oderDetail.MaHH     = item.Product.MaHH;
                    oderDetail.OderID   = id;
                    oderDetail.Gia      = item.Product.DonGia;
                    oderDetail.Quantity = item.Quantity;
                    Insert1(oderDetail);

                    var hanghoas = _context.HangHoas.Where(x => x.MaHH == item.Product.MaHH).First();

                    hanghoas.DaMua += item.Quantity;
                    _context.Update(hanghoas);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(View("ThatBai"));
            }

            var oderInfo = "";

            foreach (var item in cart)
            {
                var itemGiamGia = item.Product.DonGia * item.Product.GiamGia / 100;
                var itemGia     = Math.Round((item.Product.DonGia - itemGiamGia) * item.Quantity, 0);
                oderInfo = oderInfo + item.Quantity.ToString() + " " + item.Product.TenHH + " " + itemGia.ToString() + "VND; ";
            }

            if (oderInfo.Length > 0)
            {
                oderInfo = oderInfo.Remove(oderInfo.Length - 2, 2);
            }


            _vnPayLibrary.AddRequestData("vnp_Version", "2.0.0");
            _vnPayLibrary.AddRequestData("vnp_Command", "pay");
            _vnPayLibrary.AddRequestData("vnp_TmnCode", _tmnCode);
            _vnPayLibrary.AddRequestData("vnp_Amount", (oder.Total * 100).ToString());
            _vnPayLibrary.AddRequestData("vnp_BankCode", "");
            _vnPayLibrary.AddRequestData("vnp_CreateDate", oder.CreatedDate.ToString("yyyyMMddHHmmss"));
            _vnPayLibrary.AddRequestData("vnp_CurrCode", "VND");
            _vnPayLibrary.AddRequestData("vnp_IpAddr", _utils.GetIpAddress());
            _vnPayLibrary.AddRequestData("vnp_Locale", "vn");
            _vnPayLibrary.AddRequestData("vnp_OrderInfo", oderInfo);
            _vnPayLibrary.AddRequestData("vnp_OrderType", "130001"); //default value: other
            _vnPayLibrary.AddRequestData("vnp_ReturnUrl", $"{hostname}/cart/ket-qua-vnpay");
            _vnPayLibrary.AddRequestData("vnp_TxnRef", oder.ID.ToString());

            string paymentUrl = _vnPayLibrary.CreateRequestUrl(_url, _hashSecret);

            return(Redirect(paymentUrl));
        }
Esempio n. 28
0
 public bool ThemOder(Oder od)
 {
     return(oder.ThemOder(od));
 }
Esempio n. 29
0
 public int Insert(Oder oder)
 {
     _context.Oders.Add(oder);
     _context.SaveChanges();
     return(oder.ID);
 }