예제 #1
0
        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 = ""
            }
                        ));
        }
예제 #2
0
 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());
     }
 }
예제 #3
0
 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());
     }
 }
예제 #4
0
 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());
     }
 }
예제 #5
0
 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());
     }
 }
예제 #6
0
 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());
     }
 }
예제 #7
0
        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"));
        }
예제 #8
0
        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"));
        }