Example #1
0
        public void InsertSP(SanPham model)
        {
            int maxIdSP = db.SanPhams.Select(x => x.MaSP).Max();

            model.MaSP     = maxIdSP + 1;
            model.SLTon    = 0;
            model.SoLanMua = 0;
            db.SanPhams.Add(model);
            db.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "MaNguoiDung,HoTen,TaiKhoan,MatKhau,DiaChi,Email,SDT,MaLND,GioiTinh,HinhAnh")] NguoiDung nguoiDung)
        {
            if (ModelState.IsValid)
            {
                db.NguoiDungs.Add(nguoiDung);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaLND = new SelectList(db.LoaiNguoiDungs, "MaLND", "TenLoaiND", nguoiDung.MaLND);
            return(View(nguoiDung));
        }
Example #3
0
        public ActionResult ThanhToan(DonDatHang ddh)
        {
            var listGH = (List <GioHangModel>)Session["GIOHANG"];
            var item   = db.DonDatHangs.Find(ddh.MaDDH);

            item.DiaChiGiao  = ddh.DiaChiGiao;
            item.MaTrangThai = 1;
            item.NgayDat     = DateTime.Now;
            db.SaveChanges();


            //chua fix dk
            //foreach(var a in listGH)
            //{
            //    SanPham sp = db.SanPhams.Find(a.MaSP);
            //    sp.SLTon -= a.SoLuong;
            //    sp.SoLanMua += a.SoLuong;

            //    db.SaveChanges();
            //}



            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(NguoiDung nguoiDung)
        {
            if (ModelState.IsValid)
            {
                var ndDAO = new NguoiDungDAO();


                var nd = db.NguoiDungs.Find(nguoiDung.MaNguoiDung);

                if (nguoiDung.UploadHinhAnh != null)
                {
                    string fileName = Path.GetFileName(nguoiDung.UploadHinhAnh.FileName);
                    string filePath = "~/Assets/Admin/img/" + fileName;
                    nguoiDung.UploadHinhAnh.SaveAs(Server.MapPath(filePath));

                    nd.HinhAnh = fileName;
                }

                ndDAO.Edit(nguoiDung);
                db.SaveChanges();

                return(RedirectToAction("Profile"));
            }
            return(View(nguoiDung));
        }
Example #5
0
        public void InsertAdmin(SignupModel nd)
        {
            NguoiDung nguoiDung = new NguoiDung();
            int       maxID     = db.NguoiDungs.Select(x => x.MaNguoiDung).Max();

            nguoiDung.MaNguoiDung = maxID + 1;
            nguoiDung.HoTen       = nd.HoTen;
            nguoiDung.TaiKhoan    = nd.TaiKhoan;
            nguoiDung.MatKhau     = nd.MatKhau;
            nguoiDung.DiaChi      = nd.DiaChi;
            nguoiDung.Email       = nd.Email;
            nguoiDung.SDT         = nd.SDT;
            nguoiDung.MaLND       = 1;
            nguoiDung.GioiTinh    = nd.GioiTinh;
            nguoiDung.NgaySinh    = nd.NgaySinh;
            nguoiDung.HinhAnh     = "icon-profile-cgv.png";

            db.NguoiDungs.Add(nguoiDung);
            db.SaveChanges();
        }
Example #6
0
        public void deleteGH(int idSP, int idDDH, List <GioHangModel> gh)
        {
            var ctDDH = db.ChiTietDonDatHangs.SingleOrDefault(x => x.MaSP == idSP && x.MaDDH == idDDH);
            var ddh   = db.DonDatHangs.Find(idDDH);

            if (gh.Count == 1)
            {
                db.ChiTietDonDatHangs.Remove(ctDDH);
                db.SaveChanges();
                db.DonDatHangs.Remove(ddh);
            }
            else
            {
                db.ChiTietDonDatHangs.Remove(ctDDH);
            }

            db.SaveChanges();
        }