示例#1
0
文件: DBCtrl.cs 项目: b4p3p/omeopauta
        /// <summary>
        /// Aggiunge le immagini di un appunto
        /// </summary>
        internal static void AddImages(List<DBImage> listImage, DBAppunto appunto)
        {
            using (OmeopautaContext db = new OmeopautaContext())
            {
                db.Appunti.Attach(appunto);

                foreach (DBImage item in listImage)
                {
                    item.Appunto = appunto;
                    if (item.ID == 0)               //aggiungo le nuove immagini
                    {
                        moveImage(item, appunto);
                        db.Images.Add(item);
                    }
                }
                db.SaveChanges();
            }
        }
示例#2
0
文件: DBCtrl.cs 项目: b4p3p/omeopauta
        internal static void DeleteImages(ImageGallery[] images)
        {
            using (OmeopautaContext db = new OmeopautaContext())
            {
                foreach (ImageGallery item in images)
                {
                    if (item.DBImg.ID == 0) continue;
                    db.Images.Attach(item.DBImg);
                    db.Images.Remove(item.DBImg);
                    if (item.DBImg.tmpPath == null)
                    {
                        item.DeleteImage();
                    }

                }
                db.SaveChanges();
            }
        }
示例#3
0
文件: DBCtrl.cs 项目: b4p3p/omeopauta
        internal static void InsertOrUpdate(DBAppunto appunto)
        {
            using (OmeopautaContext db = new OmeopautaContext())
            {
                DBAppunto old = db.Appunti.FirstOrDefault<DBAppunto>(a => a.ID == appunto.ID);

                if ( old == null )  //aggiungo l'appunto
                {
                    db.Appunti.Add(appunto);
                    UpdateTags(db, appunto, null);
                }
                else                // modifico quello esistente
                {
                    string[] oldTags = null;

                    //stacco l'appunto di test
                    db.Entry(old).State = EntityState.Detached;

                    oldTags = GetTags(db, old);
                    db.Appunti.Attach(appunto);
                    db.Entry(appunto).State = EntityState.Modified;
                    UpdateTags(db, appunto, oldTags);
                }

                db.SaveChanges();
            }
        }
示例#4
0
文件: DBCtrl.cs 项目: b4p3p/omeopauta
 /// <summary>
 /// Rimuove un appunto e le sue immagini
 /// </summary>
 /// <param name="appunti"></param>
 internal static void DeleteAppunto(List<DBAppunto> appunti)
 {
     using (OmeopautaContext db = new OmeopautaContext())
     {
         foreach (DBAppunto item in appunti)
         {
             db.Appunti.Attach(item);
             DeleteDBImages(db, item.Images);
             RemoveTagsFrom(db, item);
             db.Appunti.Remove(item);
         }
         db.SaveChanges();
     }
 }