Beispiel #1
0
        public ActionResult Create(CreateSlideFormModel model)
        {
            if (ModelState.IsValid)
            {
                var slide = new SLIDE();
                slide.IDSlide = model.IDSlide;
                slide.Sapxep  = model.Sapxep;
                slide.Link    = model.Link;
                slide.NgayTao = DateTime.Now;

                if (model.SlideImage != null)
                {
                    var fileName = model.SlideImage.FileName;
                    var link     = "/uploads/" + fileName;
                    var real     = Server.MapPath("~" + link);
                    model.SlideImage.SaveAs(real);
                    slide.Anh = link;
                }
                try
                {
                    db.SLIDEs.Add(slide);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("save_error", "Lỗi khi lưu" + ex.Message);
                    return(View(model));
                }
                return(RedirectToAction("Index", "Slide"));
            }
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Create(CreateAccountListFormModel model)
        {
            if (ModelState.IsValid)
            {
                var account = new NGUOIDUNG();
                account.IDNguoiDung    = model.IDNguoiDung;
                account.TaiKhoan       = model.TaiKhoan;
                account.MatKhau        = model.MatKhau;
                account.NhapLaiMatKhau = model.NhapLaiMatKhau;
                account.Ten            = model.Ten;
                account.SDT            = model.SDT;
                account.DiaChi         = model.DiaChi;
                account.Email          = model.Email;

                try
                {
                    db.NGUOIDUNGs.Add(account);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("save_error", "Lỗi khi lưu" + ex.Message);
                    return(View(model));
                }

                return(RedirectToAction("Index", "AccountList"));
            }

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Create(CreateCategoryProductFormModel model)
        {
            if (ModelState.IsValid)
            {
                var category = new DANHMUC();
                category.MaDM    = model.MaDM;
                category.TenDM   = model.TenDM;
                category.Ngaytao = DateTime.Now;

                try
                {
                    db.DANHMUCs.Add(category);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("save_error", "Lỗi khi lưu: " + ex.Message);
                    return(View(model));
                }

                return(RedirectToAction("Index", "CategoryProduct"));
            }

            return(View(model));
        }
Beispiel #4
0
        public ActionResult CheckOut(FormCollection collection)
        {
            // Thêm đơn hàng
            DONHANG         dh = new DONHANG();
            NGUOIDUNG       kh = (NGUOIDUNG)Session["TaiKhoan"];
            List <ShopCart> sc = GetShopCart();

            dh.IDNguoiDung = kh.IDNguoiDung;
            dh.NgayDatHang = DateTime.Now;
            var ngaygiao = String.Format("{0:mm/dd/yyy}", collection["NgayGiaoHang"]);

            dh.NgayGiaoHang = DateTime.Parse(ngaygiao);
            dh.TrangThai    = false;
            db.DONHANGs.Add(dh);
            db.SaveChanges();

            //thêm chi tiết đơn hàng
            foreach (var item in sc)
            {
                CHITIETDONHANG ctdh = new CHITIETDONHANG();
                ctdh.MaDH     = dh.MaDH;
                ctdh.MaSP     = item.iMaSP;
                ctdh.SoLuong  = item.iSoLuong;
                ctdh.TongTien = (decimal)item.dThanhTien;
                db.CHITIETDONHANGs.Add(ctdh);
            }
            db.SaveChanges();
            Session["ShopCart"] = null;
            return(RedirectToAction("ConfirmOrder", "ShopCart"));
        }
 public ActionResult Register(NGUOIDUNG user)
 {
     if (ModelState.IsValid)
     {
         var checkAccout = db.NGUOIDUNGs.FirstOrDefault(s => s.TaiKhoan == user.TaiKhoan);
         var checkEmail  = db.NGUOIDUNGs.FirstOrDefault(s => s.Email == user.Email);
         if (checkEmail != null)
         {
             ViewBag.error1 = "Email này đã tồn tại!";
         }
         if (checkAccout == null)
         {
             db.Configuration.ValidateOnSaveEnabled = false;
             db.NGUOIDUNGs.Add(user);
             db.SaveChanges();
             return(RedirectToAction("Login", "User"));
         }
         else
         {
             ViewBag.error = "Tên tài khoản này đã tồn tại!";
             return(View());
         }
     }
     return(View());
 }
        public ActionResult Create(CreateProductFormModel model)
        {
            if (ModelState.IsValid)
            {
                var sp = new SANPHAM();
                sp.MaSP  = model.MaSP;
                sp.TenSP = model.TenSP;
                //sp.Anh = model.Anh;
                sp.MoTa       = model.MoTa;
                sp.ChiTiet    = model.ChiTiet;
                sp.SoLuong    = model.SoLuong;
                sp.NgayDangSP = DateTime.Now;
                sp.MaDM       = model.MaDM;
                //try
                //{
                //    sp.TopHot = DateTime.ParseExact(model.TopHot, "dd/MM/yyyy", null);
                //}
                //catch { }

                sp.MaDM = model.MaDM;
                if (model.ProductImage != null)
                {
                    var fileName = model.ProductImage.FileName;
                    var link     = "/uploads/" + fileName;
                    var real     = Server.MapPath("~" + link);
                    model.ProductImage.SaveAs(real);

                    sp.Anh = link;
                }
                try
                {
                    db.SANPHAMs.Add(sp);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("save_error", "Lỗi khi lưu" + ex.Message);
                    return(View(model));
                }
                return(RedirectToAction("Index", "Product"));
            }
            return(View(model));
        }
Beispiel #7
0
        public ActionResult Delete(DeleteContactFormModel model)
        {
            var lienhe = db.LIENHEs.FirstOrDefault(m => m.ID == model.IDLienHe);

            if (lienhe == null)
            {
                return(RedirectToAction("Index", "Contact"));
            }

            db.LIENHEs.Remove(lienhe);

            db.SaveChanges();

            return(RedirectToAction("Index", "Contact"));
        }
 public ActionResult Index(LIENHE lienhe)
 {
     //ModelState.IsValid cho biết nếu bất kỳ lỗi mô hình đã được thêm vào ModelState.
     if (ModelState.IsValid)
     {
         //Lưu lời nhắn
         LIENHE lh = new LIENHE();
         lh.Ten       = lienhe.Ten;
         lh.SDT       = lienhe.SDT;
         lh.Email     = lienhe.Email;
         lh.NoiDung   = lienhe.NoiDung;
         lh.NgayLH    = DateTime.Now;
         lh.TrangThai = false;
         db.LIENHEs.Add(lh);
         db.SaveChanges();
         ViewBag.suscess = "Gửi lời nhắn thành công";
     }
     return(View());
 }
 public ActionResult Edit(EditOrderFormModel model)
 {
     if (ModelState.IsValid)
     {
         var donhang = db.DONHANGs.FirstOrDefault(m => m.MaDH == model.MaDH);
         if (donhang != null)
         {
             donhang.MaDH      = model.MaDH;
             donhang.TrangThai = model.TrangThai;
             try
             {
                 donhang.NgayGiaoHang = DateTime.ParseExact(model.NgayGiaoHang, "dd/MM/yyyy", null);
             }
             catch { }
             //donhang.NgayGiaoHang = model.NgayGiaoHang;
             donhang.IDNguoiDung = model.IDNguoiDung;
             db.SaveChanges();
         }
         return(RedirectToAction("Index", "Order"));
     }
     return(View(model));
 }