public Boolean edit(HinhAnh kt)
 {
     if (this.is_exist(kt.id))
     {
         HinhAnh obj = this.get_by_id(kt.id);
         obj.duongdan = kt.duongdan;
         db.SaveChanges();
         return true;
     }
     return false;
 }
        public List<HinhAnh> upload(HttpServerUtilityBase server_context, HttpFileCollectionBase file_list)
        {
            Debug.WriteLine("file count: "+file_list.Count);
            List<HinhAnh> re=new List<HinhAnh>();
            //pre setting
            int max_width_height = 300;
            String relative_directory = "~/_Upload/HinhAnh/";
            //
            String server_path = "";
            String server_path_thumb = "";
            foreach (string file_name in file_list)
            {
                Debug.WriteLine("file name: " + file_name);
                HttpPostedFileBase hpf = file_list[file_name];
                String random_prefix = TextLibrary.GetSHA1HashData(DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString()).Substring(0,5);
                server_path = server_context.MapPath(Path.Combine(relative_directory, random_prefix + Path.GetFileName(hpf.FileName)));

                server_path_thumb = server_context.MapPath(Path.Combine(relative_directory, "_thumb_" + random_prefix + Path.GetFileName(hpf.FileName)));
                if (hpf.ContentLength == 0)
                {
                    continue;
                }
                HinhAnh hinhanh = new HinhAnh();
                //save origin
                    hpf.SaveAs(server_path);
                    hinhanh.duongdan = random_prefix+hpf.FileName;
                //save thumb
                    Image imgOriginal = Image.FromFile(server_path);
                    Image hinhanh_thumb = ImageLibrary.ScaleBySize(imgOriginal, max_width_height);
                    imgOriginal.Dispose();
                    hinhanh_thumb.Save(server_path_thumb);
                    hinhanh_thumb.Dispose();
                    hinhanh.duongdan_thumb = "_thumb_" + random_prefix+hpf.FileName;
                //add to re
                    re.Add(hinhanh);
                Debug.WriteLine("uploaded: " + server_path);
                Debug.WriteLine("uploaded: " + server_path_thumb);
            }
            return re;
        }
 public int add(HinhAnh dt)
 {
     db.ds_hinhanh.Add(dt);
     db.SaveChanges();
     return db.ds_hinhanh.Max(x => x.id);
 }
 //method
 public HinhAnh _get_hinhanh_macdinh()
 {
     HinhAnh re= this.ds_hinhanh.Where(x => x.macdinh == true).FirstOrDefault();
     if (re == null)
     {
         re = new HinhAnh();
         re.duongdan = "default_no_image.jpg";
         re.duongdan_thumb = "_thumb_default_no_image.jpg";
         re.macdinh = true;
         re.sanpham = this;
     }
     return re;
 }