public static ChiTietSanPhamModel ConvertToChiTietSanPhamModel(SanPham sanPham, int maHang, List<SanPham> danhSachSanPhamLienQuan, List<HinhAnh> danhSachHinhAnh, ThongSoKyThuat thongSoKyThuat, List<BinhLuan> danhSachBinhLuan) { return new ChiTietSanPhamModel() { MaHang = maHang, DanhSachSanPhamLienQuan = danhSachSanPhamLienQuan, MaSanPham = sanPham.MaSanPham, TenSanPham = sanPham.TenSanPham, Gia = (sanPham.Gia == null) ? 0 : float.Parse(sanPham.Gia.ToString()), AnhDaiDien = danhSachHinhAnh.FirstOrDefault(), DanhSachHinhAnh = danhSachHinhAnh, KichThuocManHinh = thongSoKyThuat.KichThuocManHinh, HeDieuHanh = thongSoKyThuat.HeDieuHanh, CPU = thongSoKyThuat.CPU, Camera = thongSoKyThuat.Camera, ThoiLuongPin = thongSoKyThuat.ThoiLuongPin, SoLuongSIM = thongSoKyThuat.SoLuongSIM, BoNhoTrong = thongSoKyThuat.BoNhoTrong, TheNho = thongSoKyThuat.TheNho, KhoiLuong = thongSoKyThuat.KhoiLuong, ChieuDai = thongSoKyThuat.ChieuDai, ChieuRong = thongSoKyThuat.ChieuRong, DoDay = thongSoKyThuat.DoDay, BinhLuanDuocThem = null, DanhSachBinhLuan = danhSachBinhLuan }; }
public static bool ThemSanPham(SanPham sanPham, int maTinhTrang) { try { sanPham.TinhTrang = db.TinhTrangs.Single(m => m.MaTinhTrang == maTinhTrang); db.SanPhams.AddObject(sanPham); return db.SaveChanges() > 0; } catch { return false; } }
public static bool SuaThongTinSanPham(SanPham sanPhamMoi) { try { SanPham sanPhamCu = db.SanPhams.SingleOrDefault(m => m.MaSanPham == sanPhamMoi.MaSanPham); if (null != sanPhamCu) { sanPhamCu.TenSanPham = sanPhamMoi.TenSanPham; sanPhamCu.MaTinhTrang = sanPhamMoi.MaTinhTrang; sanPhamCu.Gia = sanPhamMoi.Gia; db.ObjectStateManager.ChangeObjectState(sanPhamCu, System.Data.EntityState.Modified); return db.SaveChanges() > 0; } return false; } catch { return false; } }
public ActionResult AddProduct(SanPhamModel model) { if (ModelState.IsValid) { var imageFiles = Request.Files; if (null != imageFiles && imageFiles.Count > 0) { SanPham sanpham = new SanPham(); sanpham.TenSanPham = model.TenSanPham; sanpham.Gia = model.Gia; sanpham.ChiTietSanPhams.Add(new ChiTietSanPham() { MaHang = model.HangSanXuat, SoLuong = model.SoLuong, MoTaChung = model.MoTaChung, ThongSoKyThuat = new ThongSoKyThuat() }); var directoryName = Server.MapPath(String.Format("~/Images/SanPham/{0}", HangBLL.LayDanhSachHang().Single(m => m.MaHang == model.HangSanXuat).MaHang)); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } foreach (String file in imageFiles) { HttpPostedFileBase fileBase = Request.Files[file]; var fileName = Guid.NewGuid().ToString() + Path.GetExtension(fileBase.FileName); sanpham.HinhAnhs.Add(new HinhAnh() { TenFile = fileName }); var path = Path.Combine(directoryName, fileName); fileBase.SaveAs(path); } if (SanPhamBLL.ThemSanPham(sanpham, model.TinhTrang) == true) { return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Thêm sản phẩm thất bại. Vui lòng kiểm tra lại"); } } } ViewBag.HangSanXuat = new SelectList(HangBLL.LayDanhSachHang(), "MaHang", "TenHang"); ViewBag.TinhTrang = new SelectList(TinhTrangBLL.LayDanhSachTinhTrang(), "MaTinhTrang", "TenTinhTrang"); return View(model); }
/// <summary> /// Deprecated Method for adding a new object to the SanPhams EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSanPhams(SanPham sanPham) { base.AddObject("SanPhams", sanPham); }
/// <summary> /// Create a new SanPham object. /// </summary> /// <param name="maSanPham">Initial value of the MaSanPham property.</param> /// <param name="biXoa">Initial value of the BiXoa property.</param> public static SanPham CreateSanPham(global::System.Int32 maSanPham, global::System.Boolean biXoa) { SanPham sanPham = new SanPham(); sanPham.MaSanPham = maSanPham; sanPham.BiXoa = biXoa; return sanPham; }
public ActionResult Sua(SanPham model) { if (ModelState.IsValid) { } return View(model); }
public void ThemVaoGioHang(SanPham sanPham) { var goiHang = CacGoiHang.SingleOrDefault(m => m.SanPhamDuocChon.MaSanPham == sanPham.MaSanPham); if (null != goiHang) { goiHang.SoLuong++; } CacGoiHang.Add(new GoiHangModel() { SanPhamDuocChon = sanPham, SoLuong = 1 }); }