public ActionResult Index(int id=0)
 {
     HangSXController ctr_hangsx = new HangSXController();
     SanPhamController ctr = new SanPhamController();
     SanPham obj = ctr.get_by_id(id);
     if (obj == null)
     {
         return RedirectToAction("Index","FrontHome");
     }
     ViewBag.sanpham = obj;
     return View();
 }
 public Boolean set_default(int id)
 {
     //get hinhanh obj
     HinhAnh obj = this.get_by_id(id);
     if (obj == null || obj.sanpham == null)
     {
         return false;
     }
     //get sanpham obj
     SanPhamController ctr_sanpham=new SanPhamController(this._db);
     SanPham sanpham = ctr_sanpham.get_by_id(obj.sanpham.id);
     //get all hinhanh belong to this sanpham
     List<HinhAnh> hinhanh_list = this._db.ds_hinhanh.Where(x => x.sanpham.id == sanpham.id).ToList();
     //set all to non-default
     foreach (HinhAnh item in hinhanh_list)
     {
         item.macdinh = false;
         //set to default
         if (item.id == obj.id)
         {
             item.macdinh = true;
         }
     }
     this._db.SaveChanges();
     return true;
 }