public ActionResult DatHang(FormCollection collection)
        {
            //Them Don hang
            HoaDon         ddh = new HoaDon();
            Account        kh  = (Account)Session["Taikhoan"];
            List <Giohang> gh  = Laygiohang();

            ddh.makh    = kh.makh;
            ddh.ngaydat = DateTime.Now;
            var ngaysuat = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]);

            ddh.ngaysuat          = DateTime.Parse(ngaysuat);
            ddh.tinhtranggiaohang = false;
            ddh.dathanhtoan       = false;
            //data.HoaDons.InsertOnSubmit(ddh);
            //data.SubmitChanges();
            //Them chi tiet don hang

            foreach (var item in gh)
            {
                CTHoaDon ctdh = new CTHoaDon();
                ctdh.ma       = ddh.ma;
                ctdh.maHoaDon = item.iMahang;
                ctdh.soluong  = item.iSoluong;
                //ctdh.gia = (decimal)item.dDongia;
                //data.CTHoaDons.InsertOnSubmit(ctdh);
            }
            data.SaveChanges();
            Session["Giohang"] = null;
            return(RedirectToAction("Xacnhandonhang", "Giohang"));
        }
        public ActionResult Register([Bind(Include = "MaND,TenND,MatKhau,Email,SoDienThoai,DiaChi")] RegisterModel user)
        {
            WEBEntities1   db  = new WEBEntities1();
            ValidationUser val = new ValidationUser();

            NguoiDung nd = new NguoiDung();

            //nd.MaND = user.MaND;
            nd.TenND       = user.TenND;
            nd.MatKhau     = Encryptor.MD5Hash(user.MatKhau);
            nd.Email       = user.Email;
            nd.SoDienThoai = user.SoDienThoai;
            nd.DiaChi      = user.DiaChi;


            if (ModelState.IsValid)
            {
                if (!val.checkUser(user.TenND) || !val.checkEmail(user.Email))
                {
                    db.NguoiDungs.Add(nd);
                    db.SaveChanges();
                    //FormsAuthentication.RedirectFromLoginPage(user.TenND, false);
                    return(RedirectToAction("Register"));
                }
                else
                {
                    ModelState.AddModelError("Register", "Invalid user or password");
                }
            }
            return(View("Fail"));
        }
Ejemplo n.º 3
0
 public ActionResult ThemmoiHang(SanPham hang, HttpPostedFileBase fileUpload)
 {
     //Dua du lieu vao dropdownload
     ViewBag.maDanhMuc    = new SelectList(db.DanhMucs.ToList().OrderBy(n => n.ten), "ma", "ten");
     ViewBag.maThuongHieu = new SelectList(db.thuongHieux.ToList().OrderBy(n => n.ten), "ma", "ten");
     //Kiem tra duong dan file
     if (fileUpload == null)
     {
         ViewBag.Thongbao = "Vui lòng chọn ảnh";
         return(View());
     }
     //Them vao CSDL
     else
     {
         if (ModelState.IsValid)
         {
             //Luu ten fie, luu y bo sung thu vien using System.IO;
             var fileName = Path.GetFileName(fileUpload.FileName);
             //Luu duong dan cua file
             var path = Path.Combine(Server.MapPath("~/image_product"), fileName);
             //Kiem tra hình anh ton tai chua?
             if (System.IO.File.Exists(path))
             {
                 ViewBag.Thongbao = "Hình ảnh đã tồn tại";
             }
             else
             {
                 //Luu hinh anh vao duong dan
                 fileUpload.SaveAs(path);
             }
             hang.hinh = fileName;
             //Luu vao CSDL
             db.SanPhams.Add(hang);
             db.SaveChanges();
         }
         return(RedirectToAction("SanPham", "Admin"));
     }
 }
Ejemplo n.º 4
0
        public ActionResult Dangky(FormCollection collection, Account kh)
        {
            // Gán các giá t? ngý?i dùng nh?p li?u cho các bi?n
            var Mail   = collection["mail"];
            var Mk     = collection["mk"];
            var Hoten  = collection["hoten"];
            var Diachi = collection["diachi"];
            var Sdt    = collection["sdt"];

            if (String.IsNullOrEmpty(Hoten))
            {
                ViewData["Loi1"] = "Họ tên khách hàng không được để trống";
            }
            else if (String.IsNullOrEmpty(Hoten))
            {
                ViewData["Loi2"] = "Phải nhập Tên Đăng Nhập";
            }
            else if (String.IsNullOrEmpty(Mk))
            {
                ViewData["Loi3"] = "Phải Nhập Mật Khẩu";
            }



            if (String.IsNullOrEmpty(Mail))
            {
                ViewData["Loi5"] = "Email không được đăng kí";
            }

            if (String.IsNullOrEmpty(Sdt))
            {
                ViewData["Loi6"] = "Phải nhập số điện thoại";
            }
            else
            {
                //Gán giá tr? cho ð?i tý?ng ðý?c t?o m?i (kh)
                kh.mail   = Mail;
                kh.mk     = Mk;
                kh.hoten  = Hoten;
                kh.diachi = Diachi;
                kh.sdt    = Sdt;
                db.Accounts.Add(kh);
                db.SaveChanges();
                return(RedirectToAction("Dangnhap"));
            }
            return(this.Dangky());
        }
        public ActionResult DangKi(FormCollection collection, Account acc)
        {
            string mail = collection["txtEmail"].ToString();
            string mk   = collection["txtPassWord"].ToString();
            string ht   = collection["txtFullName"].ToString();
            string dc   = collection["txtDiaChi"].ToString();
            string sdt  = collection["txtPhone"].ToString();
            bool   gt   = true;

            acc.mail   = mail;
            acc.mk     = mk;
            acc.hoten  = ht;
            acc.diachi = dc;
            acc.sdt    = sdt;

            db.Accounts.Add(acc);
            db.SaveChanges();
            //LỖi

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
 public long Insert(NguoiDung entity)
 {
     db.NguoiDungs.Add(entity);
     db.SaveChanges();
     return(entity.MaND);
 }
Ejemplo n.º 7
0
        public ActionResult OrderNow(CartModel cart1)
        {
            WEBEntities1   db   = new WEBEntities1();
            HoaDon         HD   = new HoaDon();
            ThongTinHoaDon TTHD = new ThongTinHoaDon();
            String         b;

            b = Session["LogedMaND"].ToString();

            long a;

            a = Convert.ToInt64(b);

            HD.NgayLap = DateTime.Now;
            HD.MaND    = a;
            HD.DiaChi  = cart1.DiaChi;

            String a1;
            String a2;
            String a3;
            String aMaHD = "0";

            a1 = HD.NgayLap.ToString();
            a2 = HD.MaND.ToString();
            a3 = HD.DiaChi.ToString();


            string studentName;

            if (ModelState.IsValid)
            {
                db.HoaDons.Add(HD);
                db.SaveChanges();

                //using (var ctx = new WEBEntities1())
                //{
                //    //Get student name of string type
                //    studentName = ctx.Database.SqlQuery<string>("Select MaHD from HoaDon where MaND = "+a2+",NgayLap ='"+a1+"'").FirstOrDefault<string>();
                // }
                HoaDon a5;
                using (var ctx = new WEBEntities1())
                {
                    List <HoaDon> listHD = (from hd in db.HoaDons select hd).ToList <HoaDon>();
                    a5 = listHD.Last();
                }

                foreach (Item item in (List <Item>)Session["cart"])
                {
                    TTHD.MaSP    = item.Sanpham.MaSP;
                    TTHD.SoLuong = item.Quantity;
                    TTHD.Gia     = item.Sanpham.Gia;
                    TTHD.MaHD    = a5.MaHD;
                    if (ModelState.IsValid)
                    {
                        db.ThongTinHoaDons.Add(TTHD);
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View("Fail", "User"));
            }
        }