public ActionResult Create([Bind(Include = "MaSP,TenSP,Maloai,SL,Gia,Mota,Hinh_anh")] SanPham sanPham, HttpPostedFileBase img) { if (ModelState.IsValid) { LoaiSP sp = new LoaiSP(); try { if (img != null) { string fileName = System.IO.Path.GetFileName(img.FileName); string filePath = "~/IMG SANPHAM/" + fileName; img.SaveAs(Server.MapPath(filePath)); db.SanPhams.Add(new SanPham { TenSP = sanPham.TenSP, Mota = sanPham.Mota, SL = sanPham.SL, Gia = sanPham.Gia, Maloai = sanPham.Maloai, Hinh_anh = fileName }); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FileStatus = "File uploaded successfully."; } catch (Exception) { } } ViewBag.Maloai = new SelectList(db.LoaiSPs, "MaLoai", "TenLoai", sanPham.Maloai); return(View(sanPham)); }
public ActionResult Create([Bind(Include = "MaUR,UserRole1")] UserRole userRole) { if (ModelState.IsValid) { db.UserRoles.Add(userRole); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userRole)); }
public ActionResult Create([Bind(Include = "MaLoai,TenLoai")] LoaiSP loaiSP) { if (ModelState.IsValid) { db.LoaiSPs.Add(loaiSP); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiSP)); }
public ActionResult Create([Bind(Include = "MaKH,TenKH,Sdt,Diachi,TenDN,MK,MaUR")] KhachHang khachHang) { if (ModelState.IsValid) { db.KhachHangs.Add(khachHang); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaUR = new SelectList(db.UserRoles, "MaUR", "UserRole1", khachHang.MaUR); return(View(khachHang)); }
public ActionResult Create([Bind(Include = "MaDH,ThanhTien,Ngaylap,Tinhtrang,Nguoitao,MaKH,SDT,DiaChi,PhuongThucThanhToan")] DonHang donHang) { if (ModelState.IsValid) { db.DonHangs.Add(donHang); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaKH = new SelectList(db.KhachHangs, "MaKH", "TenKH", donHang.MaKH); ViewBag.PhuongThucThanhToan = new SelectList(db.PhuongThucThanhToans, "id", "PhuongThucThanhToan1", donHang.PhuongThucThanhToan); return(View(donHang)); }
public ActionResult Create([Bind(Include = "MaDH,MaSP,LoaiSP,TenSP,SL,Gia,MaChiTietDH")] ChiTietDH chiTietDH) { if (ModelState.IsValid) { db.ChiTietDHs.Add(chiTietDH); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaSP = new SelectList(db.SanPhams, "MaSP", "TenSP", chiTietDH.MaSP); ViewBag.MaDH = new SelectList(db.DonHangs, "MaDH", "Tinhtrang", chiTietDH.MaDH); return(View(chiTietDH)); }
public ActionResult Dangki(RegisterModel register) { if (ModelState.IsValid) { var kh = new KhachHang(); if (CheckUserName(register.TenDangNhap)) { ModelState.AddModelError("", "Tên Đăng Nhập đã tồn tại"); } else { kh.TenDN = register.TenDangNhap; kh.TenKH = register.TenNguoiDung; kh.MK = register.MatKhau; kh.Sdt = register.SoDienThoai; kh.Diachi = register.DiaChi; db.KhachHangs.Add(kh); db.SaveChanges(); register = new RegisterModel(); ViewBag.Success = "Đăng kí thành công"; ModelState.Clear(); } } return(View(register)); }
public ActionResult AddOrder(FormCollection fc) { int orderid = 0; cart = Session["cart"] as List <ChiTietDH>; DonHang dh = new DonHang() { MaKH = Convert.ToInt32(fc["MaKH"]), Nguoitao = fc["TenKH"], DiaChi = fc["diachi"], SDT = fc["sdt"], PhuongThucThanhToan = Convert.ToInt32(fc["PhuongThucThanhToan"]), Ngaylap = DateTime.Now, Tinhtrang = "Ổn", ThanhTien = Convert.ToDouble(fc["thanhtien"]) }; ViewBag.PhuongThucThanhToan = new SelectList(db.PhuongThucThanhToans, "id", "PhuongThucThanhToan1", dh.PhuongThucThanhToan); db.DonHangs.Add(dh); db.SaveChanges(); orderid = dh.MaDH; foreach (var item in cart) { ChiTietDH chitiet = new ChiTietDH() { MaDH = orderid, Gia = item.SanPham.Gia * item.SL, MaSP = item.SanPham.MaSP, SL = item.SL, TenSP = item.SanPham.TenSP, LoaiSP = null, }; db.ChiTietDHs.Add(chitiet); db.SaveChanges(); } Session["cart"] = null; return(RedirectToAction("OrderSuccess")); }