public ActionResult Submit() { SanPham_ChiTietController ctr = new SanPham_ChiTietController(); int chitietsp_id = TextLibrary.ToInt(Request["sanpham_chitietsp_id"]); int soluong = TextLibrary.ToInt(Request["sanpham_soluong"]); SanPham_ChiTiet obj = ctr.get_by_id(chitietsp_id); if (obj == null || soluong>obj.tonkho) { return RedirectToAction("Index","FrontHome"); } //new chi tiet don hang ChiTiet_DonHang chitiet_donhang = new ChiTiet_DonHang(); chitiet_donhang.sanpham_chitiet = obj; chitiet_donhang.soluong = soluong; chitiet_donhang.dongia = obj.sanpham.gia; //call add to cart this._giohang._add_to_cart(chitiet_donhang); //save to session this._save_cart_to_session(); return RedirectToAction("Index","FrontCart"); }
private DonHang _Clone() { DonHang obj = new DonHang(); obj.id = this.id; obj.kh_diachi = this.kh_diachi; obj.kh_email = this.kh_email; obj.kh_sdt = this.kh_sdt; obj.kh_ten = this.kh_ten; obj.ngay = this.ngay; obj.tongtien = this.tongtien; obj.active = this.active; obj.dagiaohang = this.dagiaohang; ChiTiet_DonHang tmp; SanPham_ChiTietController ctr_ = new SanPham_ChiTietController(this._ctr._db); foreach (var item in this.ds_chitiet_donhang) { tmp = new ChiTiet_DonHang(); tmp.dongia = item.dongia; tmp.id = item.id; tmp.soluong = item.soluong; tmp.sanpham_chitiet = ctr_.get_by_id(item.sanpham_chitiet.id); obj.ds_chitiet_donhang.Add(tmp); } return obj; }
public List<string> _update_cart(int chitietsp_id = 0, int chitietsp_soluong = 0) { List<string> validate = new List<string>(); ChiTiet_DonHang obj = this.ds_chitiet_donhang.Where(x => x.sanpham_chitiet.id == chitietsp_id).FirstOrDefault(); if (obj == null) { validate.Add("no_exist_fail"); return validate; } SanPham_ChiTietController ctr = new SanPham_ChiTietController(); SanPham_ChiTiet in_system = ctr.get_by_id(chitietsp_id); if (in_system.tonkho < chitietsp_soluong || chitietsp_soluong<=0) { validate.Add(chitietsp_id+ "_soluong_fail"); this.ds_chitiet_donhang.Where(x => x.sanpham_chitiet.id == chitietsp_id).FirstOrDefault().soluong = in_system.tonkho; return validate; } obj.soluong = chitietsp_soluong; return validate; }