Ejemplo n.º 1
0
 public ActionResult sua(Sanpham sp)
 {
     try
     {
         lt.Entry(sp).State = System.Data.Entity.EntityState.Modified;
         ViewBag.gia        = sp.Giaban;
         ViewBag.gkm        = sp.Giakhuyenmai;
         lt.SaveChanges();
         SetAlert("Sửa sản phẩm thành công", "success");
         return(RedirectToAction("hiensp", "SanPham"));
     }
     catch (Exception e)
     {
     }
     return(View());
 }
Ejemplo n.º 2
0
 public ActionResult themnh(Nhanhieu nh)
 {
     try
     {
         lt.Nhanhieux.Add(nh);
         lt.SaveChanges();
         SetAlert("Thêm nhãn hiệu thành công", "success");
         return(RedirectToAction("hiennh", "NhanHieu"));
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", "Thêm không thành công");
     }
     return(View());
 }
Ejemplo n.º 3
0
        public ActionResult dangki(Khachhang kh, FormCollection form)
        {
            try
            {
                var mk   = form["Password"];
                var nlmk = form["RePassword"];
                ViewBag.hoten = form["Hoten"];
                string hoten = ViewBag.hoten;
                ViewBag.email = form["Email"];
                string gmail = ViewBag.email;
                if (gmail.Count() == 0)
                {
                    ModelState.AddModelError("", "Vui lòng nhập gmail của bạn");
                }
                var kq = lt.Khachhangs.Where(x => x.Email == gmail).SingleOrDefault();
                if (kq != null)
                {
                    ViewBag.gt   = form["Gioitinh"];
                    ViewBag.mk   = mk;
                    ViewBag.nlmk = nlmk;
                    ViewBag.sdt  = form["Dienthoai"];
                    ViewBag.dc   = form["Diachi"];
                    ModelState.AddModelError("", "Email đã tồn tại rồi nè hihihi");
                }
                else
                {
                    ViewBag.gt   = form["Gioitinh"];
                    ViewBag.mk   = mk;
                    ViewBag.nlmk = nlmk;
                    ViewBag.sdt  = form["Dienthoai"];
                    string sdt = ViewBag.sdt;
                    if (hoten.Count() == 0)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập họ tên của bạn");
                    }
                    if (mk.Count() == 0)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập mật khẩu của bạn");
                    }
                    if (nlmk.Count() == 0)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập đúng mật khẩu xác thực của bạn");
                    }
                    if (sdt.Count() == 0)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập số điện thoại của bạn");
                    }
                    ViewBag.dc = form["Diachi"];
                    string dc = ViewBag.dc;
                    if (dc.Count() == 0)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập địa chỉ của bạn");
                    }
                    if (mk == nlmk)
                    {
                        lt.Khachhangs.Add(kh);
                        lt.SaveChanges();
                        return(RedirectToAction("Index", "TrangChu"));
                    }
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Đăng kí thất bại");
            }

            return(View());
        }
Ejemplo n.º 4
0
        public ActionResult thanhtoan(FormCollection form)
        {
            GioHang gh = (GioHang)Session["GioHang"];

            if (gh == null)
            {
                return(RedirectToAction("Index", "TrangChu"));
            }
            else
            {
                //KiemtraEmail email = new KiemtraEmail();
                DateTime ngaymuahang  = DateTime.Now;
                var      nguoimuahang = form["txtNguoiMua"];
                //IsValidEmail(nguoimuahang);

                var    tongtien = int.Parse(form["txttongtien"]);
                Hoadon hd       = new Hoadon();
                hd.MaHD         = 1;
                hd.Email        = nguoimuahang;
                hd.Ngaymua      = DateTime.Now;
                hd.Ngaygiaohang = DateTime.Now.AddDays(3);
                hd.TrigiaHD     = tongtien;

                //if (IsValidEmail(nguoimuahang) == false)
                //{
                //    ModelState.AddModelError("", "Email không đúng định dạng");
                //    return View();
                //}


                //dùng để gửi vào email
                string chiTiet = "";
                chiTiet += "<ul>";

                //thêm hóa đơn và chi tiết hóa đơn dùng transaction
                using (var dbContextTransaction = lt.Database.BeginTransaction())
                {
                    try
                    {
                        // save hoadon
                        lt.Hoadons.Add(hd);
                        lt.SaveChanges();
                        // lấy ra mahd để gán cho chitiethoadon
                        int mahd = lt.Hoadons.OrderByDescending(x => x.MaHD).Select(x => x.MaHD).Take(1).Single();
                        foreach (var item in gh.ds)
                        {
                            CT_HoaDon cthd = new CT_HoaDon();
                            cthd.MaHD    = mahd;
                            cthd.MaSP    = item.Ma;
                            cthd.Soluong = (int)item.SoLuong;
                            cthd.Dongia  = item.GiaBan;
                            lt.CT_HoaDon.Add(cthd);
                            lt.SaveChanges();
                            chiTiet += "<li>" + item.Ten + " x <font color = 'blue'><b>" + item.SoLuong + " SP </b ></font> = " + String.Format("{0:0,0} VND", item.ThanhTien) + "</li>";
                        }
                        // sau khi thanh toán thành công thì xóa giỏ hàng
                        gh.xoanguyengiohang();
                        Session["GioHang"] = null;
                        //dùng cho email
                        chiTiet += "</ul>";
                        dbContextTransaction.Commit();
                    }
                    catch (Exception e)
                    {
                        dbContextTransaction.Rollback();
                        return(RedirectToAction("Index", "TrangChu"));
                    }
                }
                GuiMail gmail     = new GuiMail();
                string  nguoinhan = form["txtNguoiMua"];
                string  kq        = gmail.SendMail(nguoinhan, nguoimuahang + " mua hàng của Tân đẹp trai", "Cám ơn mấy chú đã mua hàng của EM<br>" + chiTiet + "<br>Vui lòng chuẩn bị " +
                                                   String.Format("{0:0,0} VNĐ", tongtien) + " cho EM nhé. <br>C.U sun (*_^)", true);
                if (kq == "Successful!")
                {
                    return(RedirectToAction("ThanhCong"));
                }
                else
                {
                    return(RedirectToAction("hienloiGmail", "TrangChu"));
                }
            }
        }
Ejemplo n.º 5
0
 public int insert(Sanpham sp)
 {
     lt.Sanphams.Add(sp);
     lt.SaveChanges();
     return(sp.MaSP);
 }