Exemplo n.º 1
0
        public ActionResult ThongTinTaiKhoan(KhachHangModel model)
        {
            if (!ModelState.IsValid)
            {
                var session   = (DoAn.Common.Session.UserLogin)Session[DoAn.Common.Constants.USER_SESSION];
                var khachhang = db.KhachHangs.Find(session.UserId);
                khachhang.HoTen  = model.HoTen;
                khachhang.DiaChi = model.DiaChi;
                khachhang.SDT    = model.SDT;
                db.SaveChanges();

                var viewmodel = new KhachHangModel();
                viewmodel.Id             = khachhang.Id;
                viewmodel.HoTen          = khachhang.HoTen;
                viewmodel.Email          = khachhang.Email;
                viewmodel.SDT            = khachhang.SDT;
                viewmodel.DiaChi         = khachhang.DiaChi;
                viewmodel.UserName       = khachhang.TenDangNhap;
                ViewBag.ThongTinTaiKhoan = "Bạn đã thay đổi thông tin thành công";
                return(View(viewmodel));
            }
            else
            {
                var viewmodel = new KhachHangModel();
                viewmodel.Id             = model.Id;
                viewmodel.HoTen          = model.HoTen;
                viewmodel.Email          = model.Email;
                viewmodel.SDT            = model.SDT;
                viewmodel.DiaChi         = model.DiaChi;
                viewmodel.UserName       = model.TenDangNhap;
                ViewBag.ThongTinTaiKhoan = "Bạn đã thay đổi thông tin thành công";
                return(View(viewmodel));
            }
        }
Exemplo n.º 2
0
        public ActionResult QuenMatKhau(Models.Model.NguoiDung.KhachHangModel model)
        {
            var dao = new DoAn.Models.Dao.NguoiDung.KhachHangDao();

            if (dao.CheckEmail(model.Email, model.TenDangNhap))
            {
                try
                {
                    string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/resetpassword.html"));
                    content = content.Replace("{{CustomerName}}", model.TenDangNhap);
                    content = content.Replace("{{Password}}", "@123456");
                    //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                    new MailHelper().SendMail(model.Email, "Đổi mật khẩu từ Estore", content);
                    var khachhang = dao.getKhachHang(model.Email, model.TenDangNhap);
                    var customer  = db.KhachHangs.Find(khachhang.Id);
                    customer.MatKhau = DoAn.Common.Function.Encrytor.MD5Hash("@123456");
                    db.SaveChanges();
                    ViewBag.DoiMatKhau = "Mật khẩu bạn đã được gửi đến gmail, mời bạn kiểm tra email";
                }

                catch
                {
                    ViewBag.Error = "Email bạn nhập không hợp lệ";
                }
            }
            else
            {
                ViewBag.SaiEmail = "Tên đăng nhập và email không khớp";
            }

            return(View());
        }
Exemplo n.º 3
0
        public int AddKhuyenMai(KhuyenMaiModel km)
        {
            var khuyenmai = new DoAn.Models.EF.KhuyenMai();

            khuyenmai.NgayBatDau   = km.NgayBatDau;
            khuyenmai.NgayKetThuc  = km.NgayKetThuc;
            khuyenmai.TenKhuyenMai = km.Ten;
            khuyenmai.MoTa         = km.MoTa;
            khuyenmai.PhanTram     = km.PhanTram;
            db.KhuyenMais.Add(khuyenmai);

            var motamodel = km.MoTa;

            string[] lstloaisp = motamodel.Split(',');
            foreach (var itemlsp in lstloaisp)
            {
                var maloaisp   = Convert.ToInt32(itemlsp);
                var lstsanpham = db.SanPhams.Where(x => x.MaLoaiSanPham == maloaisp).ToList();
                foreach (var item in lstsanpham)
                {
                    var sanpham = db.SanPhams.Find(item.Id);
                    sanpham.KhuyenMai = sanpham.GiaBan - sanpham.GiaBan * khuyenmai.PhanTram / 100;
                    db.SaveChanges();
                }
            }


            db.SaveChanges();
            return(khuyenmai.Id);
        }
Exemplo n.º 4
0
        public ActionResult EditDuyet(string mahdb)
        {
            var hoadonban = db.HoaDonBans.Find(mahdb);

            hoadonban.Duyet = 1;
            db.SaveChanges();
            return(RedirectToAction("Index", "HoaDonBanAdmin"));
        }
Exemplo n.º 5
0
        public int Add(LoaiSanPham loaisp)
        {
            var nhomsp = new LoaiSanPham();

            nhomsp.TenLoaiSanPham = loaisp.TenLoaiSanPham;
            db.LoaiSanPhams.Add(nhomsp);
            db.SaveChanges();
            return(nhomsp.Id);
        }
Exemplo n.º 6
0
        public int UpdateDuyet(HoaDonBanModel model)
        {
            var hoadon = db.HoaDonBans.Find(model.Id);

            hoadon.MaChiNhanh = model.MaChiNhanh;
            hoadon.Duyet      = 1;
            db.SaveChanges();
            return(1);
        }
        public ActionResult EditChiNhanh(ChiNhanhModel model)
        {
            var chinhanh = db.ChiNhanhs.Find(model.Id);

            chinhanh.TenChiNhanh = model.TenChiNhanh;
            chinhanh.DiaChi      = model.DiaChi;
            chinhanh.GhiChu      = model.GhiChu;
            db.SaveChanges();
            return(RedirectToAction("Index", "ChiNhanhAdmin"));
        }
Exemplo n.º 8
0
        public ActionResult CreateDonViTinh(DonViTinhModel model)
        {
            var donvitinh = new DonViTinh();

            donvitinh.TenDonViTinh = model.TenDonViTinh;

            db.DonViTinhs.Add(donvitinh);
            db.SaveChanges();
            return(RedirectToAction("Index", "DonViTinhAdmin"));
        }
Exemplo n.º 9
0
        public int AddNguyenLieu(NguyenLieu nl)
        {
            var nguyenlieu = new NguyenLieu();

            nguyenlieu.TenNguyenLieu = nl.TenNguyenLieu;
            nguyenlieu.DonViTinh     = nl.DonViTinh;
            db.NguyenLieux.Add(nguyenlieu);
            db.SaveChanges();
            return(nguyenlieu.Id);
        }
Exemplo n.º 10
0
        public void Update(int makhachhang, string hoten, string diachi, string sdt, string email)
        {
            var khachhang = db.KhachHangs.FirstOrDefault(x => x.Id == makhachhang);

            khachhang.HoTen  = hoten;
            khachhang.DiaChi = diachi;
            khachhang.SDT    = sdt;
            khachhang.Email  = email;
            db.SaveChanges();
        }
Exemplo n.º 11
0
        public ActionResult CreateChucVu(ChucVuModel model)
        {
            var chucvu = new ChucVu();

            chucvu.TenChucVu = model.TenChucVu;
            chucvu.Luong     = model.Luong;
            db.ChucVus.Add(chucvu);
            db.SaveChanges();
            return(RedirectToAction("Index", "ChucVuAdmin"));
        }
        public ActionResult CreateNguyenLieu(NguyenLieuModel model)
        {
            var nguyenlieu = new NguyenLieu();

            nguyenlieu.TenNguyenLieu = model.TenNguyenLieu;

            db.NguyenLieux.Add(nguyenlieu);
            db.SaveChanges();
            return(RedirectToAction("Index", "NguyenLieuAdmin"));
        }
        public ActionResult EditProductChinh(SanPhamModel model)
        {
            SanPham book = db.SanPhams.FirstOrDefault(x => x.Id == model.Id);

            book.TenSanPham    = model.Ten;
            book.MaLoaiSanPham = model.MaLoai;
            book.GiaBan        = model.GiaBan;
            book.Anh           = model.Anh;
            db.SaveChanges();
            return(RedirectToAction("SanPhamChinh", "SanPhamAdmin"));
        }
Exemplo n.º 14
0
        public int AddChiNhanh(ChiNhanhModel cn)
        {
            var chinhanh = new ChiNhanh();

            chinhanh.TenChiNhanh = cn.TenChiNhanh;
            chinhanh.DiaChi      = cn.DiaChi;
            chinhanh.Lat         = cn.Lat;
            chinhanh.Lng         = cn.Lng;
            db.ChiNhanhs.Add(chinhanh);
            db.SaveChanges();
            return(chinhanh.Id);
        }
Exemplo n.º 15
0
        public ActionResult ThongTinTaiKhoan(KhachHangModel model)
        {
            var session   = (ChuoiCuaHangTraSua.Common.UserLogin)Session[ChuoiCuaHangTraSua.Common.Constants.USER_SESSION];
            var khachhang = db.KhachHangs.Find(session.UserId);

            khachhang.HoTen  = model.HoTen;
            khachhang.DiaChi = model.DiaChi;
            khachhang.SDT    = model.SDT;
            db.SaveChanges();
            ViewBag.ThongTinTaiKhoan = "Bạn đã thay đổi thông tin thành công";
            return(View());
        }
Exemplo n.º 16
0
        public int AddNhanVien(NhanVienModel nv)
        {
            var nhanvien = new DoAn.Models.EF.NhanVien();

            nhanvien.TenDangNhap = nv.TenDangNhap;
            nhanvien.HoTen       = nv.HoTen;
            nhanvien.MaChiNhanh  = nv.MaChiNhanh;
            nhanvien.MaChucVu    = 3;
            nhanvien.MatKhau     = DoAn.Common.Function.Encrytor.MD5Hash("123456");
            db.NhanViens.Add(nhanvien);
            db.SaveChanges();
            return(nhanvien.Id);
        }
Exemplo n.º 17
0
        public ActionResult CreateNhanVien(NhanVienModel model)
        {
            var nhanvien = new ChuoiCuaHangTraSua.Models.EF.NhanVien();

            nhanvien.HoTen       = model.HoTen;
            nhanvien.TenDangNhap = model.TenDangNhap;
            nhanvien.MatKhau     = ChuoiCuaHangTraSua.Common.Encrytor.MD5Hash("123456");
            nhanvien.MaChucVu    = model.MaChucVu;
            nhanvien.MaChiNhanh  = model.MaChiNhanh;
            db.NhanViens.Add(nhanvien);
            db.SaveChanges();
            return(RedirectToAction("Index", "NhanVienAdmin"));
        }
Exemplo n.º 18
0
        public int AddSanPham(SanPhamModel sp)
        {
            var sanpham = new SanPham();
            var convert = new DoAn.Common.Function.ConvertMoney();

            sanpham.TenSanPham    = sp.Ten;
            sanpham.MaLoaiSanPham = sp.MaLoai;
            sanpham.GiaBan        = convert.ConvertTien(sp.GiaBan);
            sanpham.KhuyenMai     = sanpham.GiaBan;
            sanpham.Anh           = sp.Anh;
            db.SanPhams.Add(sanpham);
            db.SaveChanges();
            return(sanpham.Id);
        }
Exemplo n.º 19
0
        public int AddBaoCaoChiNhanh(BaoCaoQuanLyModel bccn, int?machinhanh)
        {
            var baocaochinhanh = new BaoCaoChiNhanh();

            baocaochinhanh.MaChiNhanh = machinhanh;
            DateTime now = DateTime.Now;

            baocaochinhanh.NgayBaoCao = now;
            baocaochinhanh.SoLuongBan = this.layTongSoLuong(now, machinhanh);
            baocaochinhanh.DoanhThu   = this.layDoanhThu(now, machinhanh);
            baocaochinhanh.GhiChu     = bccn.GhiChu;
            db.BaoCaoChiNhanhs.Add(baocaochinhanh);
            db.SaveChanges();
            return(baocaochinhanh.MaBaoCao);
        }
Exemplo n.º 20
0
        public ActionResult DeleteCart(int productid, int sanphamthu)
        {
            var session = (DoAn.Common.Session.UserLogin)Session[DoAn.Common.Constants.USER_SESSION];

            if (session != null)
            {
                var userid = session.UserId;
                var list   = new CartDao().layDSSP(productid, userid, sanphamthu);
                int?spthu  = 0;
                foreach (var item in list)
                {
                    new CartDao().Delete(item.Id);
                    spthu = item.SanPhamThu;
                }
                var listconlai = new CartDao().GetProductsByIdUser(userid);
                foreach (var item in listconlai)
                {
                    if (spthu < item.SanPhamThu)
                    {
                        var sanpham_giohang = db.GioHangs.Find(item.Id);
                        sanpham_giohang.SanPhamThu = item.SanPhamThu - 1;
                        db.SaveChanges();
                    }
                }
                var session_sanphamthu = (Common.Session.SanPhamThuSession)Session[Common.Constants.SANPHAMTHU_SESSION];
                var sp_thu             = new Common.Session.SanPhamThuSession();
                sp_thu.SanPham_Thu = session_sanphamthu.SanPham_Thu - 1;
                Session.Add(Common.Constants.SANPHAMTHU_SESSION, sp_thu);
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult SuaPhanHoi(int?maphanhoi)
        {
            var phanhoi = db.PhanHois.Find(maphanhoi);

            phanhoi.DaXem = 1;
            db.SaveChanges();
            return(RedirectToAction("Index", "PhanHoiAdmin"));
        }
Exemplo n.º 22
0
        public int Update(int?maphanhoi)
        {
            var phanhoi = db.PhanHois.Find(maphanhoi);

            phanhoi.DaXem = 1;
            db.SaveChanges();
            return(phanhoi.Id);
        }
Exemplo n.º 23
0
        public ActionResult CreateHDN(HoaDonNhapModel model)
        {
            var session_hdn = (ChuoiCuaHangTraSua.Common.MaHoaDonNhap)Session[ChuoiCuaHangTraSua.Common.Constants.MAHDN_SESSION];
            var hoadonnhap  = new HoaDonNhap();

            hoadonnhap.Id         = session_hdn.Id;
            hoadonnhap.MaNCC      = model.MaNhaCungCap;
            hoadonnhap.MaNhanVien = 3;
            DateTime now = DateTime.Now;

            hoadonnhap.NgayNhap  = now;
            hoadonnhap.TongTien  = db.ChiTietHDNs.Where(x => x.MaHDN == session_hdn.Id).Sum(x => x.ThanhTien);
            hoadonnhap.ChietKhau = new ChuoiCuaHangTraSua.Common.ConvertMoney().ConvertTien(model.ChietKhau);
            db.HoaDonNhaps.Add(hoadonnhap);
            db.SaveChanges();
            return(RedirectToAction("Index", "HoaDonNhapAdmin"));
        }
Exemplo n.º 24
0
        public int Delete(int makhachhang)
        {
            var khachhang = db.KhachHangs.Find(makhachhang);

            db.KhachHangs.Remove(khachhang);
            db.SaveChanges();
            return(khachhang.Id);
        }
        public ActionResult DeleteKhachHang(int?userid)
        {
            var khachhang = db.KhachHangs.Find(userid);

            db.KhachHangs.Remove(khachhang);
            db.SaveChanges();
            return(RedirectToAction("Index", "KhachHangAdmin"));
        }
Exemplo n.º 26
0
        public ActionResult EditNhomSanPham(NhomSanPhamModel model)
        {
            var nhomsp = db.LoaiSanPhams.Find(model.Id);

            nhomsp.TenLoaiSanPham = model.Ten;
            nhomsp.SanPhamChinh   = model.SPChinhPhu;
            db.SaveChanges();
            return(RedirectToAction("Index", "NhomSanPhamAdmin"));
        }
Exemplo n.º 27
0
        public ActionResult ThongTinTaiKhoan(NhanVienModel model)
        {
            if (!ModelState.IsValid)
            {
                var nhanvien = db.NhanViens.Find(model.Id);
                nhanvien.HoTen  = model.HoTen;
                nhanvien.DiaChi = model.DiaChi;
                nhanvien.SDT    = model.SDT;
                db.SaveChanges();

                var viewmodel = new NhanVienModel();
                viewmodel.TenDangNhap = model.TenDangNhap;
                viewmodel.Id          = model.Id;
                viewmodel.DiaChi      = model.DiaChi;
                viewmodel.HoTen       = model.HoTen;
                viewmodel.SDT         = model.SDT;


                viewmodel.Luong       = db.ChucVus.FirstOrDefault(x => x.Id == nhanvien.MaChucVu).Luong;
                viewmodel.TenDangNhap = nhanvien.TenDangNhap;
                viewmodel.TenChucVu   = db.ChucVus.FirstOrDefault(x => x.Id == nhanvien.MaChucVu).TenChucVu;
                viewmodel.TenChiNhanh = db.ChiNhanhs.FirstOrDefault(x => x.Id == nhanvien.MaChiNhanh).TenChiNhanh;

                ViewBag.Success = "Bạn đã thay đổi thông tin thành công";
                return(View(viewmodel));
            }
            else
            {
                var nhanvien  = db.NhanViens.Find(model.Id);
                var viewmodel = new NhanVienModel();
                viewmodel.Id          = model.Id;
                viewmodel.DiaChi      = model.DiaChi;
                viewmodel.HoTen       = model.HoTen;
                viewmodel.SDT         = model.SDT;
                viewmodel.Luong       = db.ChucVus.FirstOrDefault(x => x.Id == nhanvien.MaChucVu).Luong;
                viewmodel.TenDangNhap = nhanvien.TenDangNhap;
                viewmodel.TenChucVu   = db.ChucVus.FirstOrDefault(x => x.Id == nhanvien.MaChucVu).TenChucVu;
                viewmodel.TenChiNhanh = db.ChiNhanhs.FirstOrDefault(x => x.Id == nhanvien.MaChiNhanh).TenChiNhanh;
                return(View(viewmodel));
            }
        }
Exemplo n.º 28
0
        public ActionResult CreateKhuyenMai(KhuyenMaiModel model)
        {
            var khuyenmai   = new KhuyenMai();
            var makhuyenmai = new RandomId().MaNgauNhien_SoChu(5);

            khuyenmai.Id              = makhuyenmai;
            khuyenmai.TenKhuyenMai    = model.Ten;
            khuyenmai.PhanTram        = model.PhanTram;
            khuyenmai.MaLoaiKhuyenMai = model.MaLoaiKhuyenMai;
            khuyenmai.NgayBatDau      = model.NgayBatDau;
            khuyenmai.NgayKetThuc     = model.NgayKetThuc;
            khuyenmai.Status          = 1;

            var listloaisanpham = Request.Form["listlspdc"];

            if (listloaisanpham != "")
            {
                string[] listlsp = listloaisanpham.Split(',');
                foreach (var item in listlsp)
                {
                    var maloaisp = int.Parse(item);
                    var listsp   = db.SanPhams.Where(x => x.MaLoaiSanPham == maloaisp).ToList();
                    foreach (var itemsp in listsp)
                    {
                        var product = db.SanPhams.Find(itemsp.Id);
                        product.KhuyenMai = product.GiaBan - (product.GiaBan * model.PhanTram / 100);
                        db.SaveChanges();
                    }
                }
            }
            else
            {
            }
            khuyenmai.MoTa = listloaisanpham;



            db.KhuyenMais.Add(khuyenmai);
            db.SaveChanges();
            return(RedirectToAction("Index", "KhuyenMaiAdmin"));
        }
        public ActionResult DoiMatKhau(KhachHangModel model)
        {
            var session = (ChuoiCuaHangTraSua.Common.UserLogin)Session[ChuoiCuaHangTraSua.Common.Constants.USER_SESSION];

            if (session != null)
            {
                var khachhang = db.KhachHangs.Find(session.UserId);
                khachhang.MatKhau = ChuoiCuaHangTraSua.Common.Encrytor.MD5Hash(model.MatKhau);
                db.SaveChanges();
                ViewBag.DoiMatKhau = "Bạn đã đổi mật khẩu thành công";
            }

            return(View());
        }
        public ActionResult DoiMatKhau(NhanVienModel model)
        {
            var session = (ChuoiCuaHangTraSua.Common.NhanVienLogin)Session[ChuoiCuaHangTraSua.Common.Constants.NHANVIEN_SESSION];

            if (session != null)
            {
                var nhanvien = db.NhanViens.Find(session.UserId);
                nhanvien.MatKhau = ChuoiCuaHangTraSua.Common.Encrytor.MD5Hash(model.MatKhau);
                db.SaveChanges();
                ViewBag.DoiMatKhau = "Bạn đã đổi mật khẩu thành công";
            }

            return(View());
        }