Example #1
0
        public ActionResult themSP(FormCollection c, HttpPostedFileBase fileUpLoad)
        {
            try
            {
                tblThietBi sp = new tblThietBi();
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(c["txtName"]))
                    {
                        setAlert("Tên Sản Phẩm Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    sp.TenTB = c["txtName"];
                    if (string.IsNullOrEmpty(c["txtHH"]))
                    {
                        setAlert("Nhãn Hiệu Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    sp.NhanHieu = c["txtHH"];
                    if (string.IsNullOrEmpty(c["txtMoTa"]))
                    {
                        setAlert("Mô Tả Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    sp.ThongTinMoTa = c["txtMoTa"];
                    sp.MaLoai       = int.Parse(c["LoaiThietBi"]);
                    sp.MaNCC        = int.Parse(c["NhaCungCap"]);
                    sp.MaNhomTB     = int.Parse(c["NhomThietBi"]);
                    //var fileName = "";
                    //if (fileUpLoad != null)
                    //{
                    //    fileName = Path.GetFileName(fileUpLoad.FileName);
                    //    var x = fileName;
                    //    int y = x.IndexOf(".");
                    //    var z = x.Substring(0,y);
                    //    fileName = x + "," + x + "," + x + "," + x + "," + x;
                    //    var path = Path.Combine(Server.MapPath("~/Content/hinh"), x);
                    //    fileUpLoad.SaveAs(path);
                    //}
                    sp.HinhAnhChung = "LGGRAM_1,LGGRAM_2,LGGRAM_3,LGGRAM_4,LGGRAM_5";

                    tx.tblThietBi.Add(sp);
                    tx.SaveChanges();

                    //add vo chi tiet
                    tblChiTietThietBi ct = new tblChiTietThietBi();
                    ct.MaTB    = sp.MaTB;
                    ct.SoLuong = 0;
                    ct.GiaTien = 0;
                    if (string.IsNullOrEmpty(c["txtCPU"]))
                    {
                        setAlert("CPU Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.CPU = c["txtCPU"];
                    if (string.IsNullOrEmpty(c["txtRAM"]))
                    {
                        setAlert("RAM Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.RAM = c["txtRAM"];
                    if (string.IsNullOrEmpty(c["txtOCung"]))
                    {
                        setAlert("Ổ Cứng Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.OCung = c["txtOCung"];
                    if (string.IsNullOrEmpty(c["txtManHinh"]))
                    {
                        setAlert("Màn Hình Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.ManHinh = c["txtManHinh"];
                    if (string.IsNullOrEmpty(c["txtDoHoa"]))
                    {
                        setAlert("Đồ Họa Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.DoHoa = c["txtDoHoa"];
                    if (string.IsNullOrEmpty(c["txtPin"]))
                    {
                        setAlert("Pin Không Được Để Trống", "warning");
                        return(RedirectToAction("themSP"));
                    }
                    ct.Pin  = c["txtPin"];
                    ct.Khac = c["txtKhac"];
                    tx.tblChiTietThietBi.Add(ct);
                    tx.SaveChanges();
                }
                setAlert("Thêm Sản Phẩm Thành Công", "success");
                return(RedirectToAction("sanpham"));
            }
            catch
            {
                setAlert("Error", "error");
                return(RedirectToAction("sanpham"));
            }
        }