public ActionResult ThongTinKhachHang(string txtName, string txtPhone, string txtAddress, string txtEmail) { //Tạo và lấy thông tin của order var od = new DONHANG(); DonHangDAO ODAO = new DonHangDAO(); long idorder = 0; od.NgayTao = DateTime.Now; od.TenKhachHang = txtName; od.DiaChiKhachHang = txtAddress; od.DienThoaiKhachHang = txtPhone; od.EmailKhachHang = txtEmail; od.TrangThai = 0; try { idorder = ODAO.Insert(od); //Thêm order vào chi tiết var list = (List <CartItem>)Session[CartSession];; if (list != null) { foreach (var item in list) { CHITIETDONHANG od1 = new CHITIETDONHANG(); CoDAO ccc = new CoDAO(); od1.IDDonHang = idorder; od1.IDCo = ccc.LayIDCoGiayTheoIDSPVaCo(item.Product.ID, item.CoGiay); od1.SoLuong = item.Quantity; int giatien = 0; if (item.Product.GiaKhuyenMai != null && item.Product.GiaKhuyenMai > 0) { giatien = (int.Parse(item.Product.GiaKhuyenMai.Value.ToString()) * item.Quantity); } else { giatien = (int.Parse(item.Product.Gia.Value.ToString()) * item.Quantity); } od1.Gia = giatien; ChiTietDonHangDAO ODDAO = new ChiTietDonHangDAO(); ODDAO.Add(od1); } } } catch (Exception) { throw; } return(Redirect("/GioHang/XemLaiDonHang?idorder=" + idorder + "")); }
public ActionResult ThemSanPham(SANPHAM sp, string cogiay_soluong) { try { if (ModelState.IsValid) { if (cogiay_soluong == "") { SetAlert("Thêm sản phẩm thất bại. Vui lòng nhập đủ trường dữ liệu!", "canhbao"); } else { var DAO = new SanPhamDAO(); sp.Metatitle = RewriteURL.RewriteUrl(sp.TenSP); sp.NguoiTao = UserInfo.UserID; sp.NgayTao = DateTime.Now; sp.TrangThai = 0; sp.LuotXem = 0; long idsp = DAO.Insert(sp); //Lấy ra tất cả các cỡ+số lượng string[] mangco = cogiay_soluong.Split(' '); //Với mỗi cỡ và số lượng đó tách riêng cỡ và số lượng vào 1 mảng for (int i = 0; i < mangco.Length; i++) { string[] mangs = mangco[i].Split(','); int co = int.Parse(mangs[0].ToString()); int sl = int.Parse(mangs[1].ToString()); //Thêm cỡ mới vào bảng cỡ CoDAO cDAO = new CoDAO(); COGIAY cogiay = new COGIAY(); cogiay.IDSP = idsp; cogiay.SoLuong = sl; cogiay.Co = co; cDAO.ThemCo(cogiay); } SetAlert("Thêm sản phẩm thành công", "thanhcong"); } } } catch (Exception) { SetAlert("Thêm sản phẩm thất bại", "canhbao"); } return(RedirectToAction("ChoDuyet", "QuanLySanPham")); }
public ActionResult ChiTiet(long id) { var dao = new ChiTietDonHangDAO(); var dao1 = new DonHangDAO(); int?tongtien = 0; //Lấy danh sách chi tiết đơn hàng trong chi tiết theo ID của đơn hàng var listOrder = dao.GetListByIDOrder(id); //Lấy ra thông tin khách hàng ViewBag.vbcs = dao1.ViewByID(id); //lấy danh sách sản phẩm trong đơn hàng đó List <OrderViewModel> lpr = new List <OrderViewModel>(); foreach (var item in listOrder) { var od = new OrderViewModel(); var pr = new SanPhamDAO().getInfoByIDCo(long.Parse(item.IDCo.ToString())); //LẤy cỡ giày của bản ghi theo ID cỡ string cogiayxxx = new CoDAO().ViewByID(long.Parse(item.IDCo.ToString())).Co.ToString(); od.productAvatar = pr.AnhDaiDien; od.productID = pr.ID; od.productMetatitle = pr.Metatitle; od.productName = pr.TenSP; od.cogiay = int.Parse(cogiayxxx); od.productPrice = int.Parse(item.Gia.Value.ToString()) / item.SoLuong; od.productQuantity = item.SoLuong; tongtien = int.Parse(item.Gia.Value.ToString()); lpr.Add(od); } ViewBag.vb_tongtien = tongtien; return(View(lpr)); }