public ActionResult Create(QuangCao quangcaos)
 {
     data.QuangCaos.InsertOnSubmit(quangcaos);
     data.SubmitChanges();
     ViewBag.ThongBao = "SUCCESS";
     return(View());
 }
 public ActionResult Edit(int id, BinhLuan binhluans)
 {
     binhluans = (from s in data.BinhLuans where s.MaBL == id select s).FirstOrDefault();
     TryUpdateModel(binhluans);
     data.SubmitChanges();
     return(RedirectToAction("Index"));
 }
        public ActionResult DatHang(FormCollection collection)
        {
            //Them Don hang
            HoaDon    ddh = new HoaDon();
            KhachHang kh  = (KhachHang)Session["Taikhoan"];
            List <GioHangdViewModel> gh = LayGioHang();

            ddh.MaKH           = kh.MaKH;
            ddh.DiaChiGiaoHang = kh.DiaChi;
            ddh.NgayLapHD      = DateTime.Now;
            ddh.TrangThai      = false;
            ddh.GhiChu         = collection["GhiChu"];
            data.HoaDons.InsertOnSubmit(ddh);
            data.SubmitChanges();
            //Them chi tiet don hang
            foreach (var item in gh)
            {
                ChiTietHoaDon ctdh = new ChiTietHoaDon();
                ctdh.MaHD    = ddh.MaHD;
                ctdh.MaSP    = item.MaSP;
                ctdh.TenSP   = (item.MaSP + " - " + item.TenSP);
                ctdh.SoLuong = item.SoLuong;
                ctdh.DonGia  = (int)item.DonGia;
                data.ChiTietHoaDons.InsertOnSubmit(ctdh);
            }
            data.SubmitChanges();
            Session["Giohang"] = null;
            return(RedirectToAction("Xacnhandonhang", "Giohang"));
        }
Beispiel #4
0
 public ActionResult Edit(int id, KhachHang khachhang)
 {
     khachhang = (from s in data.KhachHangs where s.MaKH == id select s).FirstOrDefault();
     UpdateModel(khachhang);
     data.SubmitChanges();
     return(View());
 }
 public ActionResult Create(LoaiSanPham loaisanphams)
 {
     data.LoaiSanPhams.InsertOnSubmit(loaisanphams);
     data.SubmitChanges();
     ViewBag.ThongBao = "SUCCESS";
     return(this.Create());
 }
Beispiel #6
0
 public ActionResult Edit(int id, HoaDon hoadon)
 {
     hoadon = (from s in data.HoaDons
               where s.MaHD == id
               select s).FirstOrDefault();
     UpdateModel(hoadon);
     data.SubmitChanges();
     ViewBag.ThongBao = "SUCCESS";
     return(View());
 }
Beispiel #7
0
 public bool CreateAdmin(QuanTriVien _admin)
 {
     try
     {
         admin.QuanTriViens.InsertOnSubmit(_admin);
         admin.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public ActionResult Create(Hang hangs, HttpPostedFileBase fileUpload)
 {
     if (String.IsNullOrEmpty(hangs.TenH))
     {
         ViewBag.ThongBao = "Chưa nhập";
     }
     else
     {
         try
         {
             if (fileUpload == null)
             {
                 ViewBag.Thongbao = "Chọn ảnh";
             }
             //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("~/images/hang/anhbia"), fileName);
                     //Kiem tra hình anh ton tai chua?
                     if (System.IO.File.Exists(path))
                     {
                         ViewBag.Thongbao = "Thông tin có vấn đề";
                     }
                     else
                     {
                         //Luu hinh anh vao duong dan
                         fileUpload.SaveAs(path);
                     }
                     //Luu vao CSDL
                     hangs.AnhBia = "images/hang/anhbia/" + fileName;
                     data.Hangs.InsertOnSubmit(hangs);
                     data.SubmitChanges();
                     ViewBag.Thongbao = "SUCCESS";
                 }
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             ViewBag.ThongBao = "Lỗi nhập Hãng(vd: SamSung,HP... không lớn hơn 50 ký tự)";
         }
     }
     return(this.Create());
 }
Beispiel #9
0
        public void DeleteSize(int id)
        {
            var sanphamsizes = data.SanPhams
                               .Join(data.SanPhamSizes,
                                     post => post.MaSP,
                                     metal => metal.MaSP,
                                     (post, metal) => new { SanPham = post, SanPhamSize = metal })
                               .Where(postAndMeta => postAndMeta.SanPham.MaSP == id);

            foreach (var item in sanphamsizes)
            {
                data.SanPhamSizes.DeleteOnSubmit(item.SanPhamSize);
            }
            data.SubmitChanges();
        }
        public void DeleteHinhAnh(int id)
        {
            var hinhanhs = data.SanPhams
                           .Join(data.HinhAnhs,
                                 post => post.MaSP,
                                 metal => metal.MaSP,
                                 (post, metal) => new { SanPham = post, HinhAnh = metal })
                           .Where(postAndMeta => postAndMeta.SanPham.MaSP == id);

            foreach (var item in hinhanhs)
            {
                data.HinhAnhs.DeleteOnSubmit(item.HinhAnh);
            }
            data.SubmitChanges();
        }
Beispiel #11
0
 public ActionResult DangKy(ViewModels.RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var dao = new ViewModels.RegisterViewModel();
         if (dao.CheckUsername(model.TenDangNhap))
         {
             ViewBag.ThongBao = "Tên đăng nhập đã tồn tại";
         }
         if (dao.CheckUsername(model.TenDangNhap) == false)
         {
             var customer = new KhachHang();
             customer.HoTen       = model.HoTen;
             customer.TenDangNhap = model.TenDangNhap;
             customer.MatKhau     = model.MatKhau;
             customer.DiaChi      = model.DiaChi;
             customer.SoDienThoai = model.SoDienThoai;
             customer.Email       = model.Email;
             data.KhachHangs.InsertOnSubmit(customer);
             data.SubmitChanges();
             ViewBag.ThongBao = "Đăng ký thành công";
             return(View());
         }
     }
     return(View(model));
 }
Beispiel #12
0
        public ActionResult Dangky(FormCollection collection, KhachHang kh)
        {
            // Gán các giá tị người dùng nhập liệu cho các biến
            var tendangnhap    = collection["TenDangnhap"];
            var matkhau        = collection["MatKhau"];
            var nhaplaimatkhau = collection["NhapLaiMatkhau"];
            var hoten          = collection["HoTen"];
            var diachi         = collection["Diachi"];
            var email          = collection["Email"];
            var sodienthoai    = collection["SoDienthoai"];

            if (String.IsNullOrEmpty(hoten))
            {
                ViewData["hoten"] = "Họ tên khách hàng không được để trống";
            }
            else if (String.IsNullOrEmpty(tendangnhap))
            {
                ViewData["tendangnhap"] = "Phải nhập tên đăng nhập";
            }
            else if (String.IsNullOrEmpty(matkhau))
            {
                ViewData["matkhau"] = "Phải nhập mật khẩu";
            }
            else if (String.IsNullOrEmpty(nhaplaimatkhau))
            {
                ViewData["nhaplaimatkhau"] = "Phải nhập lại mật khẩu";
            }

            if (String.IsNullOrEmpty(email))
            {
                ViewData["email"] = "Email không được bỏ trống";
            }

            if (String.IsNullOrEmpty(sodienthoai))
            {
                ViewData["sodienthoai"] = "Phải nhập điện thoai";
            }
            else
            {
                //Gán giá trị cho đối tượng được tạo mới (kh)
                kh.TenDangNhap = tendangnhap;
                kh.MatKhau     = matkhau;
                kh.HoTen       = hoten;
                kh.DiaChi      = diachi;
                kh.Email       = email;
                kh.SoDienThoai = sodienthoai;
                data.KhachHangs.InsertOnSubmit(kh);
                data.SubmitChanges();
                return(RedirectToAction("DangNhap"));
            }
            return(this.DangKy());
        }
Beispiel #13
0
 public ActionResult Create(BoSuuTap bosuutaps)
 {
     data.BoSuuTaps.InsertOnSubmit(bosuutaps);
     if (String.IsNullOrEmpty(bosuutaps.TenBST))
     {
         ViewBag.ThongBao = "Chưa nhập";
     }
     else
     {
         try
         {
             data.SubmitChanges();
             ViewBag.ThongBao = "SUCCESS";
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             ViewBag.ThongBao = "Lỗi nhập size(vd: xxl... không lớn hơn 3 chữ cái)";
         }
     }
     return(this.Create());
 }
Beispiel #14
0
        public ActionResult Create(BinhLuan binhluans)
        {
            var       product = new dbShopQuanAoDataContext();
            KhachHang kh      = (KhachHang)Session["Taikhoan"];

            binhluans.MaKH = kh.MaKH;
            DateTime date = DateTime.Now;

            binhluans.NgayBL = date;
            data.BinhLuans.InsertOnSubmit(binhluans);
            data.SubmitChanges();
            return(RedirectToAction("Details", "ShopQuanAo", new { id = binhluans.MaSP }));
        }
Beispiel #15
0
        public bool EditCustomer(KhachHang _customer)
        {
            try
            {
                var entity = customer.KhachHangs.Where(kh => kh.MaKH == _customer.MaKH).FirstOrDefault();
                entity.HoTen       = _customer.HoTen;
                entity.TenDangNhap = _customer.TenDangNhap;
                entity.MatKhau     = _customer.MatKhau;
                entity.DiaChi      = _customer.DiaChi;
                entity.SoDienThoai = _customer.SoDienThoai;
                entity.Email       = _customer.Email;
                customer.SubmitChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
 // GET: Test
 public ActionResult Index()
 {
     data.SanPhamSizes.InsertOnSubmit(
         new SanPhamSize {
         MaSP = 2057, MaS = 2,
     }
         );
     data.SanPhamSizes.InsertOnSubmit(
         new SanPhamSize {
         MaSP = 2057, MaS = 3,
     }
         );
     data.SanPhamSizes.InsertOnSubmit(
         new SanPhamSize {
         MaSP = 2057, MaS = 4,
     }
         );
     data.SubmitChanges();
     return(View());
 }
Beispiel #17
0
        public ActionResult Index(ChangeProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var session   = (KhachHang)Session["Taikhoan"];
                var khachhang = data.KhachHangs.Where(kh => kh.MaKH == session.MaKH).FirstOrDefault();
                try
                {
                    if (session != null)
                    {
                        var entity = new KhachHang();
                        entity.MaKH        = session.MaKH;
                        entity.HoTen       = model.HoTen;
                        entity.TenDangNhap = model.TenDangNhap;
                        entity.DiaChi      = model.DiaChi;
                        entity.SoDienThoai = model.SoDienThoai;
                        entity.Email       = model.Email;
                        if (model.ExPassword != null)
                        {
                            if (session.MatKhau.Equals(model.ExPassword))
                            {
                                entity.MatKhau = model.ConfirmPassword.ToString();
                            }
                            else
                            {
                                ModelState.AddModelError("", "Nhập sai mật khẩu");
                            }
                        }
                        new ChangeProfileViewModel().EditCustomer(entity);
                        TryUpdateModel(khachhang);
                        data.SubmitChanges();
                    }
                }
                catch
                {
                }
            }

            return(View(model));
        }
Beispiel #18
0
        public ActionResult Create(ThemSanPhamViewModel viewModel, HttpPostedFileBase fileUpload, HttpPostedFileBase[] files)
        {
            //Dua du lieu vao dropdownload
            ViewBag.MaL   = new SelectList(data.LoaiSanPhams.ToList().OrderBy(n => n.TenLoai), "MaL", "TenLoai");
            ViewBag.MaBST = new SelectList(data.BoSuuTaps.ToList().OrderBy(n => n.TenBST), "MaBST", "TenBST");
            // Tao san pham moi lay thong tin tu san pham user da nhap
            var sanpham = new SanPham
            {
                TenSP        = viewModel.TenSP,
                GiaKhuyenMai = viewModel.GiaKhuyenMai,
                GiaBan       = viewModel.GiaBan,
                GioiTinh     = viewModel.GioiTinh,
                MaL          = viewModel.MaL,
                MaBST        = viewModel.MaBST,
                SoLuong      = viewModel.SoLuong,
                ThongTin     = viewModel.ThongTin,
                ngayNhapHang = viewModel.ngayNhapHang,
                AnhBia       = viewModel.AnhBia
            };

            //Kiem tra duong dan file

            if (fileUpload == null)
            {
                ViewBag.Thongbao = "Thông tin có vấn đề";
            }
            //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("~/images/anhbia"), fileName);
                    //Kiem tra hình anh ton tai chua?
                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.Thongbao = "Thông tin có vấn đề";
                    }
                    else
                    {
                        //Luu hinh anh vao duong dan
                        fileUpload.SaveAs(path);
                    }
                    //Luu vao CSDL
                    sanpham.AnhBia = "images/anhbia/" + fileName;
                    data.SanPhams.InsertOnSubmit(sanpham);
                    data.SubmitChanges();
                }
            }
            //Them HinhAnh1
            if (ModelState.IsValid)
            {   //iterating through multiple file collection
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/images/hinhanh"), fileName);
                        file.SaveAs(path);
                        data.HinhAnhs.InsertOnSubmit(new HinhAnh {
                            MaSP = sanpham.MaSP, TenHinhAnh = "images/hinhanh/" + fileName
                        });
                        ViewBag.UploadStatus = files.Count().ToString() + " files uploaded successfully.";
                        data.SubmitChanges();
                    }
                    else if (file == null)
                    {
                        ViewData["hinhanh"] = "Phải chọn hình ảnh";
                    }
                }
            }
            //Kiểm tra đã select chưa
            if (viewModel.SelectedSizes[0] == 0)
            {
                ViewBag.Thongbao = "Thông tin có vấn đề";
            }
            // Tien hanh them thong tin vao bang SanPhamSize
            else
            {
                for (int i = 0; i < viewModel.SelectedSizes.Count(); i++)
                {
                    data.SanPhamSizes.InsertOnSubmit(new SanPhamSize {
                        MaSP = sanpham.MaSP, MaS = viewModel.SelectedSizes[i]
                    });
                    data.SubmitChanges();
                }
            }
            ViewBag.ThongBao = "SUCCESS";
            return(this.Create());
        }