Esempio n. 1
0
        public ActionResult SPBanChay()
        {
            SanPhamModel         sp     = new SanPhamModel();
            IQueryable <SanPham> splist = sp.SPBanChay(7);

            if (splist.Any())
            {
                return(PartialView("_BestSellerPartial", splist.ToList()));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public ActionResult SuaThongSoKT(string masp)
        {
            SanPhamModel spm = new SanPhamModel();

            if (spm.GetTSKT(masp).ToList().Count == 0)
            {
                ThongSoKyThuat ts = new ThongSoKyThuat();
                ts.MaSP = masp;
                List <ThongSoKyThuat> lst = new List <ThongSoKyThuat>();
                lst.Add(ts);
                return(View("ThemThongSoKT", lst));
            }
            return(View("SuaThongSoKT", spm.GetTSKT(masp).ToList()));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public ActionResult SuaThongSoKT(int masp)
        {
            var spm = new SanPhamModel();

            if (spm.GetTSKT(masp).ToList().Count == 0)
            {
                var ts = new ThongSoKyThuat();
                ts.SanPhamId = masp;
                var lst = new List <ThongSoKyThuat>();
                lst.Add(ts);
                return(View("ThemThongSoKT", lst));
            }
            return(View("SuaThongSoKT", spm.GetTSKT(masp).ToList()));
        }
Esempio n. 5
0
        public ActionResult DeleteSP(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SanPhamModel spm = new SanPhamModel();

            DeleteAnh(spm.FindById(id).AnhDaiDien);
            DeleteAnh(spm.FindById(id).AnhNen);
            DeleteAnh(spm.FindById(id).AnhKhac);
            spm.DeleteSP(id);
            return(TimSP(null, null, null));
        }
Esempio n. 6
0
 internal bool UpdateTinhTrang(int madh, int?tt)
 {
     if (tt == null)
     {
         return(false);
     }
     try
     {
         var db = new MainContext();
         var dh = db.DonHangKHs.Find(madh);
         if (dh.TinhTrangDH == 4 || dh.TinhTrangDH == 3)
         {
             return(false);
         }
         if (dh.TinhTrangDH == 1)
         {
             if (tt == 2 || tt == 3)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     var spm = new SanPhamModel();
                     spm.UpdateSL(item.SanPhamId, item.SoLuong, false);
                 }
             }
         }
         if (dh.TinhTrangDH == 2)
         {
             if (tt == 4)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     var spm = new SanPhamModel();
                     spm.UpdateSL(item.SanPhamId, item.SoLuong, true);
                 }
             }
             if (tt == 1)
             {
                 return(false);
             }
         }
         var query = "update DonHangKH set TinhTrangDH = " + tt + " where Id ='" + madh + "'";
         db.Database.ExecuteSqlCommand(query);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 7
0
 public SanPhamModel UpdateItem([FromBody] SanPhamModel model)
 {
     if (model.Hinhanh != null)
     {
         var arrData = model.Hinhanh.Split(';');
         if (arrData.Length == 3)
         {
             var savePath = $@"assets/images/{arrData[0]}";
             model.Hinhanh = $"{savePath}";
             SaveFileFromBase64String(savePath, arrData[2]);
         }
     }
     _itemBusiness.Update(model);
     return(model);
 }
Esempio n. 8
0
 public SanPhamModel UpdateSanPham([FromBody] SanPhamModel model)
 {
     if (model.item_image != null)
     {
         var arrData = model.item_image.Split(';');
         if (arrData.Length == 3)
         {
             var savePath = $@"{arrData[0]}";
             model.item_image = $"{savePath}";
             SaveFileFromBase64String(savePath, arrData[2]);
         }
     }
     _itemBusiness.Update(model);
     return(model);
 }
Esempio n. 9
0
        public ActionResult SanPham()
        {
            var session = (DoAn.Common.Session.UserLogin)Session[DoAn.Common.Constants.USER_SESSION];

            if (session != null)
            {
                var model = new SanPhamModel();
                model.SelectMaLoai = new SelectList(db.LoaiSanPhams, "Id", "TenLoaiSanPham", 0);
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult CreateSanPhamChinh(SanPhamModel model)
        {
            SanPham sanpham = new SanPham();

            sanpham.TenSanPham    = model.Ten;
            sanpham.MaLoaiSanPham = model.MaLoai;
            sanpham.GiaBan        = model.GiaBan;
            sanpham.KhuyenMai     = model.GiaBan;
            sanpham.Anh           = model.Anh;
            sanpham.MoTa          = model.MoTa;
            var dao = new ProductDao();

            dao.Insert(sanpham);
            return(RedirectToAction("SanPhamChinh", "SanPhamAdmin"));
        }
Esempio n. 11
0
        public ActionResult SPMoiNhap(int?skip)
        {
            var sp      = new SanPhamModel();
            var skipnum = (skip ?? 0);
            var splist  = sp.SPMoiNhap();

            splist = splist.OrderBy(r => r.Id).Skip(skipnum).Take(4);
            if (splist.Any())
            {
                return(PartialView("_ProductTabLoadMorePartial", splist));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 12
0
 public SanPhamModel CreateSanPham([FromBody] SanPhamModel model)
 {
     if (model.item_image != null)
     {
         var arrData = model.item_image.Split(';');
         if (arrData.Length == 3)
         {
             var savePath = $@"assets/images/{arrData[0]}";
             model.item_image = $"{savePath}";
             SaveFileFromBase64String(savePath, arrData[2]);
         }
     }
     model.item_id = Guid.NewGuid().ToString();
     _itemBusiness.Create(model);
     return(model);
 }
Esempio n. 13
0
        public ActionResult EditSP([Bind(Include = "Id,TenSP,LoaiSpId,Id,XuatXu,GiaGoc,MoTa,SoLuong,isnew,ishot")] SanPham sanpham, HttpPostedFileBase ad, HttpPostedFileBase an, HttpPostedFileBase ak)
        {
            var spm = new SanPhamModel();

            if (ModelState.IsValid)
            {
                spm.EditSP(sanpham);
                UploadAnh(ad, sanpham.Id + "1");
                UploadAnh(an, sanpham.Id + "2");
                UploadAnh(ak, sanpham.Id + "3");
                return(RedirectToAction("SanPham"));
            }
            ViewBag.HangSX = new SelectList(spm.GetAllHangSX(), "Id", "TenHang", sanpham.HangSxId);
            ViewBag.LoaiSP = new SelectList(spm.GetAllLoaiSP(), "Id", "TenLoai", sanpham.LoaiSpId);
            return(View(sanpham));
        }
 public ActionResult MultibleDel(List <string> lstdel)
 {
     if (lstdel == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     foreach (var item in lstdel)
     {
         SanPhamModel spm = new SanPhamModel();
         DeleteAnh(spm.FindById(item).AnhDaiDien);
         DeleteAnh(spm.FindById(item).AnhNen);
         DeleteAnh(spm.FindById(item).AnhKhac);
         spm.DeleteSP(item);
     }
     return(TimSP(null, null, null));
 }
        public ActionResult EditSP([Bind(Include = "MaSP,TenSP,LoaiSP,HangSX,XuatXu,GiaGoc,MoTa,SoLuong,isnew,ishot,GioiThieu,ThongSoKyThuat")] SanPham sanpham, HttpPostedFileBase ad, HttpPostedFileBase an, HttpPostedFileBase ak)
        {
            SanPhamModel spm = new SanPhamModel();

            if (ModelState.IsValid)
            {
                spm.EditSP(sanpham);
                UploadAnh(ad, sanpham.MaSP + "1");
                UploadAnh(an, sanpham.MaSP + "2");
                UploadAnh(ak, sanpham.MaSP + "3");
                return(RedirectToAction("SanPham"));
            }
            ViewBag.HangSX = new SelectList(spm.GetAllHangSX(), "HangSX", "TenHang", sanpham.HangSX);
            ViewBag.LoaiSP = new SelectList(spm.GetAllLoaiSP(), "MaLoai", "TenLoai", sanpham.LoaiSP);
            return(View(sanpham));
        }
Esempio n. 16
0
        public ActionResult SPKhuyenMai(int?skip)
        {
            SanPhamModel         sp      = new SanPhamModel();
            int                  skipnum = (skip ?? 0);
            IQueryable <SanPham> splist  = sp.SPKhuyenMai();

            splist = splist.OrderBy(r => r.MaSP).Skip(skipnum).Take(4);
            if (splist.Any())
            {
                return(PartialView("_ProductTabLoadMorePartial", splist));
            }
            else
            {
                return(null);
            }
        }
        // edit tên sản phẩm lỗi
        public ActionResult EditNameSP()
        {
            SanPhamModel spm = new SanPhamModel();

            using (TextFieldParser parser = new TextFieldParser(Server.MapPath("~/data/findmasp.csv")))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                while (!parser.EndOfData)
                {
                    var      MaSP   = "";
                    string[] values = parser.ReadFields();
                    if (values[0].Contains("socot"))
                    {
                        continue;
                    }
                    //Xu ly hang san xuat
                    if (values[1].Length == 2)
                    {
                        MaSP = "000" + values[1];
                    }
                    else if (values[1].Length == 3)
                    {
                        MaSP = "00" + values[1];
                    }
                    else if (values[1].Length == 3)
                    {
                        MaSP = "00" + values[1];
                    }
                    else if (values[1].Length == 4)
                    {
                        MaSP = "0" + values[1];
                    }
                    else if (values[1].Length == 5)
                    {
                        MaSP = values[1];
                    }
                    //Create SanPham
                    SanPham sp = new SanPham();
                    sp.MaSP  = MaSP;
                    sp.TenSP = values[2];

                    spm.EditNameSP(sp);
                }
            }
            return(RedirectToAction("SanPham"));
        }
Esempio n. 18
0
        public ActionResult Index(int?page, string key = null, int?maloai = null)
        {
            ViewBag.Key = key;
            var list = db.SanPhams.Where(x => x.MaLoaiSanPham != 1 && x.MaLoaiSanPham != 12 && x.MaLoaiSanPham != 13 && x.MaLoaiSanPham != 14).ToList();

            if (key != null)
            {
                if (maloai == null)
                {
                    list = list.Where(x => x.TenSanPham.Contains(key)).OrderBy(s => s.GiaBan).ToList();
                }
                else
                {
                    list = list.Where(x => x.TenSanPham.Contains(key) && x.MaLoaiSanPham == maloai).OrderBy(s => s.GiaBan).ToList();
                }
            }
            else
            {
                if (maloai == null)
                {
                }
                else
                {
                    list = list.Where(x => x.MaLoaiSanPham == maloai).OrderBy(s => s.GiaBan).ToList();
                }
            }
            int pageSize   = 16;
            int pageNumber = (page ?? 1);

            ViewBag.Page = pageNumber;
            var model = new List <SanPhamModel>();

            foreach (var item in list)
            {
                var itemmodel = new SanPhamModel();
                itemmodel.Id            = item.Id;
                itemmodel.Ten           = item.TenSanPham;
                itemmodel.GiaBan        = String.Format("{0:0,0}", item.GiaBan) + "đ";
                itemmodel.KhuyenMaiShow = String.Format("{0:0,0}", item.KhuyenMai) + "đ";
                itemmodel.Anh           = item.Anh;
                itemmodel.PhanTramKM    = (item.GiaBan * 100 - item.KhuyenMai * 100) / item.GiaBan + "%";
                model.Add(itemmodel);
            }

            return(View(model.ToPagedList(pageNumber, pageSize)));
        }
Esempio n. 19
0
        public ActionResult ThemThongSoKT(List <ThongSoKyThuat> lstkt)
        {
            if (lstkt.Count == 0)
            {
                return(RedirectToAction("SanPham"));
            }
            var spm = new SanPhamModel();

            foreach (var item in lstkt)
            {
                if (!string.IsNullOrEmpty(item.ThuocTinh))
                {
                    spm.ThemTSKT(item);
                }
            }
            return(RedirectToAction("SanPham"));
        }
Esempio n. 20
0
        public JsonResult List(string txtSearch, int?page)
        {
            var list = db.SanPhams.Where(x => x.MaLoaiSanPham != 12 && x.MaLoaiSanPham != 13 && x.MaLoaiSanPham != 14).OrderByDescending(x => x.Id).ToList();

            int pageSize = 10;

            if (!String.IsNullOrEmpty(txtSearch))
            {
                ViewBag.txtSearch = txtSearch;
                list = list.Where(x => x.MaLoaiSanPham != 12 && x.MaLoaiSanPham != 13 && x.MaLoaiSanPham != 14 && x.TenSanPham.Contains(txtSearch)).OrderByDescending(x => x.Id).ToList();
            }
            var data = new List <SanPhamModel>();
            int i    = 0;

            foreach (var item in list)
            {
                i++;
                var itemmodel = new SanPhamModel();
                itemmodel.STT     = i;
                itemmodel.Id      = item.Id;
                itemmodel.Ten     = item.TenSanPham;
                itemmodel.GiaBan  = String.Format("{0:0,0}", item.GiaBan);
                itemmodel.Anh     = item.Anh;
                itemmodel.TenLoai = new CategoryDao().getById(item.MaLoaiSanPham).TenLoaiSanPham;
                data.Add(itemmodel);
            }
            if (page > 0)
            {
                page = page;
            }
            else
            {
                page = 1;
            }
            int start = (int)(page - 1) * pageSize;

            ViewBag.pageCurrent = page;
            int   totalPage    = data.Count();
            float totalNumsize = (totalPage / (float)pageSize);
            int   numSize      = (int)Math.Ceiling(totalNumsize);

            ViewBag.numSize = numSize;
            var datamodel = data.Skip(start).Take(pageSize);

            return(Json(new { data = datamodel, pageCurrent = page, numSize = numSize }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(SanPhamModel sanPham)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/api/");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <SanPhamModel>("updateproduct", sanPham);
                postTask.Wait();
                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(sanPham));
        }
Esempio n. 22
0
        public ActionResult EditSP(int spId)
        {
            if (spId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var spm = new SanPhamModel();
            var sp  = spm.FindById(spId);

            if (sp == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HangSX = new SelectList(spm.GetAllHangSX().ToList(), "Id", "TenHang", sp.HangSxId);
            ViewBag.LoaiSP = new SelectList(spm.GetAllLoaiSP().ToList(), "Id", "TenLoai", sp.LoaiSpId);
            return(View(sp));
        }
Esempio n. 23
0
 public SanPhamModel UpdateSP([FromBody] SanPhamModel model)
 {
     if (model.image != null)
     {
         var arrData = model.image.Split(';');
         if (arrData.Length == 3)
         {
             var savePath  = $@"assets/Upload/SanPham/{arrData[0]}";
             var savePathh = $@"assets/Upload/SanPham/{arrData[0]}";
             model.image = $"{savePath}";
             SaveFileFromBase64String(savePath, arrData[2]);
             SaveFileFromBase64(savePathh, arrData[2]);
         }
     }
     sanpham.Update(model);
     return(model);
 }
        public ActionResult EditSP(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SanPhamModel spm = new SanPhamModel();
            SanPham      sp  = spm.FindById(id);

            if (sp == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HangSX = new SelectList(spm.GetAllHangSX().ToList(), "HangSX", "TenHang", sp.HangSX);
            ViewBag.LoaiSP = new SelectList(spm.GetAllLoaiSP().ToList(), "MaLoai", "TenLoai", sp.LoaiSP);
            return(View(sp));
        }
        public ActionResult Create(SanPhamModel sanPham)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <SanPhamModel>("api/create_product", sanPham);
                postTask.Wait();
                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            ModelState.AddModelError(string.Empty, "Lỗi khởi tạo.");
            return(View(sanPham));
        }
        public void AddNew(SanPhamModel modelsp)
        {
            SANPHAM sp = new SANPHAM();

            sp.MaSP    = modelsp.MaSP;
            sp.MaNSX   = modelsp.MaNSX;
            sp.MaLoai  = modelsp.MaLoai;
            sp.TenSP   = modelsp.TenSP;
            sp.MoTa    = modelsp.MoTa;
            sp.Gia     = modelsp.Gia;
            sp.SoLuong = modelsp.SoLuong;
            sp.Size    = modelsp.Size;
            sp.XuatXu  = modelsp.XuatXu;
            sp.DacTinh = modelsp.DacTinh;
            sp.Hinh    = modelsp.Hinh;

            db.SANPHAM.Add(sp);
            db.SaveChanges();
        }
        public ActionResult AddDataLazada()
        {
            SanPhamModel spm = new SanPhamModel();

            using (TextFieldParser parser = new TextFieldParser(Server.MapPath("~/data/database-lazada.csv")))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                while (!parser.EndOfData)
                {
                    string[] values = parser.ReadFields();
                    if (values[0].Contains("Link"))
                    {
                        continue;
                    }
                    //Xu ly hang san xuat

                    //Create SanPham
                    SanPham sp = new SanPham();
                    sp.TenSP = values[1];

                    sp.HangSX  = values[2];
                    sp.LoaiSP  = values[3];
                    sp.XuatXu  = "Việt Nam";
                    sp.GiaGoc  = decimal.Parse(values[4]);
                    sp.GiaTien = decimal.Parse(values[4]);

                    //IEnumerable<string> words = values[4].Split().Take(30);
                    //sp.GioiThieu = words.ToString();
                    //sp.MoTa = values[4];
                    sp.SoLuong = 20;
                    sp.ishot   = false;
                    sp.isnew   = false;

                    string masp = spm.ThemSP(sp);
                    DownloadAnh(values[5], masp + "1");
                    DownloadAnh(values[6], masp + "2");
                    DownloadAnh(values[7], masp + "3");
                }
            }
            return(RedirectToAction("SanPham"));
        }
Esempio n. 28
0
        public ActionResult GetListBook()
        {
            List <SANPHAM> model = new SanPhamDao().getListSanPham();

            List <SanPhamModel> listProduct = new List <SanPhamModel>();

            foreach (SANPHAM item in model)
            {
                List <HINHANH> images = new SanPhamDao().getListImages(item.MASANPHAM);
                string         chuongtrinhkhuyenmai = "";
                var            giaban   = new SanPhamDao().getGiaBan(item.MASANPHAM);
                var            gia      = item.DONGIA;
                var            ctkm     = new SanPhamDao().getCTKM(item.MASANPHAM);
                int            phanTram = 0;
                if (ctkm != null)
                {
                    phanTram             = (int)ctkm.MUCGIAMGIA;
                    chuongtrinhkhuyenmai = ctkm.TENCHUONGTRINHKHUYENMAI;
                }
                if (giaban != null)
                {
                    gia = giaban.DONGIABAN;
                }
                var sp = new SanPhamModel
                {
                    TENSANPHAM           = item.TENSANPHAM,
                    MASANPHAM            = item.MASANPHAM,
                    DONGIA               = gia,
                    GIABAN               = gia - gia * phanTram / 100,
                    GHICHU               = System.Web.HttpUtility.HtmlDecode(item.GHICHU),
                    CHUONGTRINHKHUYENMAI = chuongtrinhkhuyenmai,
                    LUOTXEM              = item.LUOTXEM,
                    PhanTram             = phanTram,
                };
                if (images.Count > 0)
                {
                    sp.LINKHINHANH = images[0].LINKHINHANH;
                }
                listProduct.Add(sp);
            }
            return(Json(listProduct, JsonRequestBehavior.AllowGet));
        }
Esempio n. 29
0
        public ActionResult ThemSP([Bind(Include = "TenSP,LoaiSpId,Id,XuatXu,GiaGoc,MoTa,SoLuong,isnew,ishot")] SanPham sanpham, HttpPostedFileBase ad, HttpPostedFileBase an, HttpPostedFileBase ak)
        {
            var spm = new SanPhamModel();

            if (ModelState.IsValid)
            {
                var masp = spm.ThemSP(sanpham);
                UploadAnh(ad, masp + "1");
                UploadAnh(an, masp + "2");
                UploadAnh(ak, masp + "3");
                var ts = new ThongSoKyThuat();
                ts.SanPhamId = masp;
                var lst = new List <ThongSoKyThuat>();
                lst.Add(ts);
                return(View("ThemThongSoKT", lst));
            }
            ViewBag.HangSX = new SelectList(spm.GetAllHangSX(), "Id", "TenHang", sanpham.HangSxId);
            ViewBag.LoaiSP = new SelectList(spm.GetAllLoaiSP(), "Id", "TenLoai", sanpham.LoaiSpId);
            return(View("SanPham", sanpham));
        }
        public ActionResult Edit(int id)
        {
            IEnumerable <SanPhamModel> sanPhams = null;
            SanPhamModel sanPham = new SanPhamModel();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/");
                //HTTP GET
                var responseTask = client.GetAsync("api/getallproduct");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <List <SanPhamModel> >();
                    readTask.Wait();

                    sanPhams = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    sanPhams = Enumerable.Empty <SanPhamModel>();

                    ModelState.AddModelError(string.Empty, "Lỗi server.");
                }


                foreach (var i in sanPhams)
                {
                    if (i.id == id)
                    {
                        sanPham = i;
                        break;
                    }
                }
            }
            return(View(sanPham));
        }