Example #1
0
        public ActionResult Delete(int id)
        {
            var sp = SanPhamDAL.createSanPhamDAL();

            try
            {
                //SanPham emp = db.SanPhams.Where(x => x.Id == id).FirstOrDefault<SanPham>();
                //db.SanPhams.Remove(emp);
                //db.SaveChanges();
                sp.deleteSanPhamx(id);

                //using (ApplicationDbContext db = new ApplicationDbContext())
                //{
                //    SanPham emp = db.SanPhams.Where(x => x.Id == id).FirstOrDefault<SanPham>();
                //    db.SanPhams.Remove(emp);
                //    db.SaveChanges();
                //}

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", sp.getAllSanPham()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public void SelectByDanhMuc()
        {
            SanPhamDAL spDAL = new SanPhamDAL();

            spDAL._sanPham = this._sanPham;
            KetQua         = spDAL.SelectByDanhMuc();
        }
Example #3
0
        //GET : Details MenuItem
        public ActionResult Detail(int id)
        {
            var     sp      = SanPhamDAL.createSanPhamDAL();
            SanPham sanPham = sp.detailSanPham(id);

            //SanPham sanPham = db.SanPhams.Where(p => p.Id == id).SingleOrDefault();
            ViewBag.sanPham = sanPham;

            ViewBag.CategoryList = GetCategory();
            ViewBag.HangList     = GetHang();

            //if (id == null)
            //{
            //    return HttpNotFound();
            //}

            //if (model == null)
            //{
            //    return HttpNotFound();
            //}

            //var model = sp.getSanPhamById(id);

            bool exist;

            //var userId = User.Identity.GetUserId<string>();

            //exist = db.FavouriteSanPhams.Any(p => p.ProductId == id);
            exist = sp.checkSanPhamExistsInFavouriteById(id);

            ViewBag.inFavorite = exist;

            return(View(sanPham));
        }
Example #4
0
        public void Update()
        {
            SanPhamDAL updateSanPham = new SanPhamDAL();

            updateSanPham._sanPham = this._sanPham;
            updateSanPham.Update();
        }
Example #5
0
        public void Insert()
        {
            SanPhamDAL insertSanPham = new SanPhamDAL();

            insertSanPham._sanPham = this._sanPham;
            insertSanPham.Insert();
        }
Example #6
0
        public void SelectHinhSanPhamById()
        {
            SanPhamDAL selectHinhSanPhamById = new SanPhamDAL();

            selectHinhSanPhamById._sanPham = this._sanPham;
            KetQua = selectHinhSanPhamById.SelectHinhSanPham();
        }
 // hàm khởi tạo
 public SanPhamBUS()
 {
     rd    = new Random();
     spDAL = new SanPhamDAL();
     // tạo ta mã với 3 số và 1 kí tự in hoa
     ma = rd.Next(100, 999).ToString() + Convert.ToString((char)rd.Next(65, 90));
 }
Example #8
0
        public void Delete()
        {
            SanPhamDAL deleteSanPham = new SanPhamDAL();

            deleteSanPham._sanPham = this._sanPham;
            deleteSanPham.Delete();
            deleteSanPham.DeleteHinhSanPham();
        }
Example #9
0
        public ActionResult ViewAll()
        {
            var sp    = SanPhamDAL.createSanPhamDAL();
            var model = sp.getAllSanPham();

            //return View(GetAllSanPham());
            return(View(model));
        }
        public ActionResult Index()
        {
            var nhomsp = NhomSanPhamDAL.createNhomSanPhamDAL();
            var hang   = HangDAL.createHangDAL();
            var sp     = SanPhamDAL.createSanPhamDAL();

            ViewBag.NhomSP  = nhomsp.getAllNhomSP();
            ViewBag.Hang    = hang.getAllHang();
            ViewBag.SanPham = sp.getAllSanPham();
            return(View(ViewBag));
        }
Example #11
0
        // GET: Cart

        public ActionResult Index()
        {
            var cart = Session[CartSession];
            var sp   = SanPhamDAL.createSanPhamDAL();

            ViewBag.SanPham = sp.getAllSanPham();
            var list = new List <CartItem>();

            if (cart != null)
            {
                list = (List <CartItem>)cart;
            }
            return(View(list));
        }
Example #12
0
        public ActionResult AddOrEdit(SanPham sanPham)
        {
            var sp = SanPhamDAL.createSanPhamDAL();

            try
            {
                if (sanPham.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(sanPham.ImageUpload.FileName);
                    string extension = Path.GetExtension(sanPham.ImageUpload.FileName);
                    fileName          = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    sanPham.ImagePath = "~/ProductImg/" + fileName;
                    sanPham.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/ProductImg/"), fileName));
                }

                if (sanPham.Id == 0)
                {
                    //db.SanPhams.Add(sanPham);
                    //db.SaveChanges();
                    sp.insertSanPham(sanPham);
                }
                else
                {
                    //db.Entry(sanPham).State = EntityState.Modified;
                    //db.SaveChanges();
                    sp.updateSanPham(sanPham);
                }

                //using (ApplicationDbContext db = new ApplicationDbContext())
                //{
                //    if (sanPham.Id == 0)
                //    {
                //        db.SanPhams.Add(sanPham);
                //        db.SaveChanges();
                //    }
                //    else
                //    {
                //        db.Entry(sanPham).State = EntityState.Modified;
                //        db.SaveChanges();

                //    }
                //}

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", sp.getAllSanPham()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Example #13
0
        public ActionResult AddItem(int productId, int quantity)
        {
            var sp      = SanPhamDAL.createSanPhamDAL();
            var product = sp.detailSanPham(productId);
            //var product = new SanPhamDAL().detailSanPham(productId);
            var cart = Session[CartSession];

            if (cart != null)
            {
                var list = (List <CartItem>)cart;
                if (list.Exists(x => x.SanPham.Id == productId))
                {
                    foreach (var item in list)
                    {
                        if (item.SanPham.Id == productId)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }
                else
                {
                    //tạo mới đối tượng cart item
                    var item = new CartItem();
                    item.SanPham  = product;
                    item.Quantity = quantity;
                    list.Add(item);
                }
                //Gán vào session
                Session[CartSession] = list;
            }
            else
            {
                //tạo mới đối tượng cart item
                var item = new CartItem();
                item.SanPham  = product;
                item.Quantity = quantity;
                var list = new List <CartItem>();
                list.Add(item);

                //Gán vào session
                Session[CartSession] = list;
            }
            return(RedirectToAction("Index"));
        }
Example #14
0
        public ActionResult AddOrEdit(int id = 0)
        {
            var     sp  = SanPhamDAL.createSanPhamDAL();
            SanPham sp1 = new SanPham();

            ViewBag.CategoryList = GetCategory();
            ViewBag.HangList     = GetHang();
            if (id != 0)
            {
                //using (ApplicationDbContext db = new ApplicationDbContext())
                //{
                //    sp = db.SanPhams.Where(x => x.Id == id).FirstOrDefault<SanPham>();
                //}
                sp1 = sp.getSanPhamByProductId(id);
                //var a = spx.getSanPhamByProductId(id);
            }
            return(View(sp1));
        }
Example #15
0
        public void SelectById()
        {
            SanPhamDAL spDAL = new SanPhamDAL();

            spDAL._sanPham = this._sanPham;
            KetQua         = spDAL.SelectById();
            GridView gv = new GridView();

            gv.DataSource = KetQua;
            gv.DataBind();
            _sanPham.TenSanPham  = gv.Rows[0].Cells[1].Text.ToString();
            _sanPham.MoTaSanPham = gv.Rows[0].Cells[4].Text.ToString();
            _sanPham.GiaSanPham  = Convert.ToInt32(gv.Rows[0].Cells[5].Text.ToString());
            _sanPham.IdSanPham   = int.Parse(gv.Rows[0].Cells[0].Text.ToString());
            _sanPham.DanhMucSanPham.TenDanhMucSanPham = gv.Rows[0].Cells[2].Text.ToString();
            _sanPham.IdHinhSanPham    = int.Parse(gv.Rows[0].Cells[3].Text.ToString());
            _sanPham.IdDanhMucSanPham = int.Parse(gv.Rows[0].Cells[6].Text.ToString());
        }
Example #16
0
        public ActionResult FavouriteSanPham()
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(Json(new { result = -1, message = "Vui lòng đăng nhập để thực hiện chức năng này" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                string userID        = User.Identity.GetUserId <string>();
                int    productID     = Convert.ToInt32(Request.Form["sanPham"]);
                var    sanphamfavDAL = SanPhamDAL.createSanPhamDAL();
                //kiểm tra sản phẩm tồn tại trong danh sách yêu thích ko
                Favor = new ContextAddFavor(null);
                if (sanphamfavDAL.checkSanPhamExistsInFavourite(productID, userID))
                {
                    //sanphamfavDAL.deleteFavouriteSanPham(productID,username);

                    Favor.TransitionTo(new RemoveFavor());
                    Favor.Favor(productID, userID);

                    return(Json(new
                    {
                        result = 1,
                        imgsrc = "/Assets/image/icon/chuaThich.png",
                        message = "Xóa sản phẩm khỏi danh sách yêu thích thành công"
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    Favor.TransitionTo(new AddFavor());
                    Favor.Favor(productID, userID);
                    return(Json(new
                    {
                        result = 1,
                        imgsrc = "/Assets/image/icon/daThich.png",
                        message = "Thêm bài hát vào danh sách yêu thích thành công"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
        }
 public SanPhamBUS()
 {
     bdal = new SanPhamDAL();
 }
Example #18
0
        public void SelectAll()
        {
            SanPhamDAL spDAL = new SanPhamDAL();

            KetQua = spDAL.SelectAll();
        }
Example #19
0
        public void Search(string keyword)
        {
            SanPhamDAL searchSanPham = new SanPhamDAL();

            KetQua = searchSanPham.Search(keyword);
        }
Example #20
0
        public void SelectTop10()
        {
            SanPhamDAL selectTop10SanPham = new SanPhamDAL();

            KetQua = selectTop10SanPham.SelectTop10();
        }