Example #1
0
 //更新圖片
 public static void Update(Rio_Pic pic)
 {
     using (Entities db = new Entities())
     {
         db.Entry(pic).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #2
0
 //新增圖片
 public static void Insert(Rio_Pic pic)
 {
     using (Entities db = new Entities())
     {
         db.Rio_Pic.Add(pic);
         db.SaveChanges();
     }
 }
Example #3
0
        //刪除圖片
        public static void Delete(Rio_Pic pic)
        {
            using (Entities db = new Entities())
            {
                db.Entry(pic).State = System.Data.Entity.EntityState.Modified;
                pic.IsDelete        = true;
                db.SaveChanges();

                AlbumJoinPicModel.deleteJoinAlbumByPic(pic.SN);                         //刪除相簿與圖片關聯
                List <Rio_Album> albumList = AlbumModel.getAlbumByFrontCoverSN(pic.SN); //取得所有使用該圖片當封面的相簿
                foreach (var item in albumList)
                {
                    int       FronCoverSN = AlbumJoinPicModel.getJoinAlbumFirst(item.SN);//取得該相簿的第一個圖片當作封面
                    Rio_Album album       = db.Rio_Album.Find(item.SN);
                    album.FrontCoverSN = FronCoverSN;
                    AlbumModel.Update(album);//更新相簿封面
                }
            }
        }