public ActionResult ThemSP([Bind(Include = "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)
            {
                string masp = spm.ThemSP(sanpham);
                UploadAnh(ad, masp + "1");
                UploadAnh(an, masp + "2");
                UploadAnh(ak, 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", sanpham));
        }
        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"));
        }
Beispiel #3
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 AddData()
        {
            SanPhamModel spm = new SanPhamModel();

            using (TextFieldParser parser = new TextFieldParser(Server.MapPath("~/data/database-dongho.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
                    string hsx = "";
                    if (values[2].Equals("Samsung"))
                    {
                        hsx = "30312";
                    }
                    else if (values[2].Equals("Apple"))
                    {
                        hsx = "52018";
                    }
                    else if (values[2].Equals("Huawei"))
                    {
                        hsx = "07203";
                    }
                    else if (values[2].Equals("Xiaomi"))
                    {
                        hsx = "35225";
                    }
                    else if (values[2].Equals("Garmin"))
                    {
                        hsx = "57235";
                    }
                    else if (values[2].Equals("Fitbit"))
                    {
                        hsx = "26062";
                    }
                    else if (values[2].Equals("Zeblaze"))
                    {
                        hsx = "87146";
                    }
                    else if (values[2].Equals("Sinophy"))
                    {
                        hsx = "87146";
                    }
                    else
                    {
                        hsx = values[2].Substring(0, 5).ToUpper();
                    }
                    //Create SanPham
                    SanPham sp = new SanPham();
                    sp.TenSP   = values[1];
                    sp.LoaiSP  = "70443";
                    sp.HangSX  = hsx;
                    sp.XuatXu  = "Việt Nam";
                    sp.GiaGoc  = decimal.Parse(values[3]);
                    sp.GiaTien = decimal.Parse(values[3]);

                    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[5], masp + "2");
                    DownloadAnh(values[5], masp + "3");
                }
            }
            return(RedirectToAction("SanPham"));
        }