public JsonResult ThanhToan(string SDT, string diachi, string yeucau) { Acount acount = (Acount)Session["Login"]; DONHANG a = new DONHANG(); a.MA = 0; a.DIACHI = diachi; a.YEUCAUGIAOHANG = yeucau; a.SDT = SDT; a.TAIKHOANID = acount.ID; a.TRANGTHAI = 0; // Đang giao hàng Shop_MVC_Context db = new Shop_MVC_Context(); db.DONHANGs.Add(a); try { db.SaveChanges(); Cart cart = (Cart)Session["Cart"]; string err = ""; a.TONGTIEN = 0; foreach (CHITIETDONHANG item in cart.ListItem) { item.DONHANGID = a.ID; a.TONGTIEN += new MatHangService().Find((int)item.MATHANGID, ref err).GIA *item.SOLUONG; db.CHITIETDONHANGs.Add(item); } a.TONGTIEN += a.TONGTIEN / 10; /// VAT db.SaveChanges(); cart.ListItem.Clear(); } catch (Exception ex) { return(Json(new { ok = false, exception = ex.Message })); } return(Json(new { ok = true, exception = "" } )); }
public LOAISANPHAM Add(LOAISANPHAM entity, ref string err) { try { dataContext.LOAISANPHAMs.Add(entity); dataContext.SaveChanges(); return(entity); } catch (Exception ex) { err = ex.Message; return(new LOAISANPHAM()); } }
public MATHANG Add(MATHANG entity, ref string err) { try { dataContext.MATHANGs.Add(entity); dataContext.SaveChanges(); return(entity); } catch (Exception ex) { err = ex.Message; return(new MATHANG()); } }
public TAIKHOAN Add(TAIKHOAN entity, ref string err) { try { dataContext.TAIKHOANs.Add(entity); dataContext.SaveChanges(); return(entity); } catch (Exception ex) { err = ex.Message; return(new TAIKHOAN()); } }
public NHASANXUAT Add(NHASANXUAT entity, ref string err) { try { dataContext.NHASANXUATs.Add(entity); dataContext.SaveChanges(); return(entity); } catch (Exception ex) { err = ex.Message; return(new NHASANXUAT()); } }
public ANHSP Add(ANHSP entity, ref string err) { try { dataContext.ANHSPs.Add(entity); dataContext.SaveChanges(); return(entity); } catch (Exception ex) { err = ex.Message; return(new ANHSP()); } }
public ActionResult ThemSanPham(string TenSanPham, string MaSanPham, int NhaSanXuatID, int LoaiSanPhamID, double GiaSanPham, string ChiTietSanPham, HttpPostedFileBase Anh) { ViewBag.ThongBao = "Thành công"; /// thêm mặt hàng MATHANG mh = new MATHANG(); mh.TEN = TenSanPham; mh.MA = MaSanPham; mh.NHASANXUATID = NhaSanXuatID; mh.LOAISANPHAMID = LoaiSanPhamID; mh.GIA = GiaSanPham; mh.CHITET = ChiTietSanPham; mh.KHUYENMAI = 0; Shop_MVC_Context db = new Shop_MVC_Context(); db.MATHANGs.Add(mh); try { /// thêm ảnh sản phẩm db.SaveChanges(); if (Anh.ContentLength > 0) { var fileName = "product" + mh.ID + ".png"; string j = Path.Combine( Server.MapPath("~/Content/Client/images/product/"), fileName); Anh.SaveAs(j); ANHSP a = new ANHSP(); a.SRC = "/Content/Client/images/product/" + fileName; a.MATHANGID = mh.ID; db.ANHSPs.Add(a); db.SaveChanges(); } } catch { ViewBag.ThongBao = "Thêm sản phẩm không thành công"; } return(View("TrangThaiThemSanPham")); }
public ActionResult SuaSanPham(int id, string TenSanPham, string MaSanPham, int NhaSanXuatID, int LoaiSanPhamID, double GiaSanPham, string ChiTietSanPham, HttpPostedFileBase Anh) { ViewBag.ThongBao = "Sửa thông tin sản phẩm Thành công"; Shop_MVC_Context db = new Shop_MVC_Context(); /// thêm mặt hàng MATHANG mh = db.MATHANGs.Where(p => p.ID == id).FirstOrDefault(); mh.TEN = TenSanPham; mh.MA = MaSanPham; mh.NHASANXUATID = NhaSanXuatID; mh.LOAISANPHAMID = LoaiSanPhamID; mh.GIA = GiaSanPham; mh.CHITET = ChiTietSanPham; mh.KHUYENMAI = 0; try { /// thêm ảnh sản phẩm db.SaveChanges(); if (Anh != null) { var fileName = "product" + mh.ID + ".png"; string j = Path.Combine( Server.MapPath("~/Content/Client/images/product/"), fileName); Anh.SaveAs(j); ANHSP a = db.ANHSPs.Where(p => p.MATHANGID == mh.ID).FirstOrDefault(); a.SRC = "/Content/Client/images/product/" + fileName; a.MATHANGID = mh.ID; db.SaveChanges(); } } catch { ViewBag.ThongBao = "Sửa thông tin sản phẩm thất bại"; } return(View("TrangThaiThemSanPham")); }