Beispiel #1
0
        public ActionResult Create([Bind(Include = "CTSP_ID,SP_ID,CTSP_TRANGTHAI,CTSP_TEN")] CHITIETSANPHAM cHITIETSANPHAM)
        {
            HINHANHSPsController hINHANHSPsController = new HINHANHSPsController();
            HINHANHSP            hINHANHSP            = new HINHANHSP();
            HttpPostedFileBase   file = Request.Files["Image"];

            if (file != null)
            {
                cHITIETSANPHAM.CTSP_TRANGTHAI = 1;
                Int32  length    = file.ContentLength;
                byte[] tempImage = new byte[length];
                file.InputStream.Read(tempImage, 0, length);
                hINHANHSP.HA_ND = tempImage;
                hINHANHSP.HA_ID = db.autottang("HinhAnhSP", "HA_ID", db.HINHANHSPs.Count()).ToString();
                hINHANHSPsController.addHA(hINHANHSP);
            }
            if (ModelState.IsValid)
            {
                db.CHITIETSANPHAMs.Add(cHITIETSANPHAM);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SP_ID = new SelectList(db.SANPHAMs, "SP_ID", "SP_TEN", cHITIETSANPHAM.SP_ID);
            return(View(cHITIETSANPHAM));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "SP_ID,KM_ID,GIA_ID,NSX_ID,DSP_ID,SP_TEN,SP_CNMANGHINH,SP_DOPHANGIAI,SP_MANHINH,SP_CAMERASAU,SP_CAMERATRUOC,SP_HEDIEUHANH,SP_RAM,SP_ROM,SP_DUNGLUONGPIN,SP_SOSIM,SP_MOTA,SP_NGAYTAO,SP_THOIGIANBH")] SANPHAM sANPHAM)
        {
            HINHANHSPsController hINHANHSPsController = new HINHANHSPsController();
            HINHANHSP            hINHANHSP            = new HINHANHSP();
            HttpPostedFileBase   file = Request.Files["Image"];
            string SP_ID = Request["SP_ID"].ToString().Replace(" ", "_");

            SANPHAM sp = db.SANPHAMs.Find(SP_ID);

            if (sp != null)
            {
                ModelState.AddModelError("", "Mã sản phẩm đã tồn tại !");
            }
            else
            if (ModelState.IsValid)
            {
                db.SANPHAMs.Add(sANPHAM);
                db.SaveChanges();
                if (file != null)
                {
                    Int32  length    = file.ContentLength;
                    byte[] tempImage = new byte[length];
                    file.InputStream.Read(tempImage, 0, length);
                    hINHANHSP.HA_ND = tempImage;
                    hINHANHSP.HA_ID = db.autottang("HinhAnhSP", "HA_ID", db.HINHANHSPs.Count()).ToString();
                    hINHANHSP.SP_ID = sANPHAM.SP_ID;
                    hINHANHSPsController.addHA(hINHANHSP);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.DSP_ID = new SelectList(db.DONGSANPHAMs, "DSP_ID", "DSP_TEN", sANPHAM.DSP_ID);
            ViewBag.GIA_ID = new SelectList(db.GIASPs, "GIA_ID", "GIA_ID", sANPHAM.GIA_ID);
            ViewBag.KM_ID  = new SelectList(db.KHUYENMAIs, "KM_ID", "KM_TEN", sANPHAM.KM_ID);
            ViewBag.NSX_ID = new SelectList(db.NHASANXUATs, "NSX_ID", "NSX_TEN", sANPHAM.NSX_ID);
            return(View(sANPHAM));
        }