Example #1
0
        private static void RemoveTag(OmeopautaContext db, DBAppunto appunto, DBTag dbTag)
        {
            //cancello la tupla per il n-n
            //DBAppuntiTag dbApp = db.AppuntiTag.FirstOrDefault<DBAppuntiTag>(
            //    t => t.Appunto.ID == appunto.ID && t.Tag.Tag == dbTag.Tag);
            DBAppuntiTag dbApp = appunto.Tags.FirstOrDefault<DBAppuntiTag>( t =>  t.Tag.Tag == dbTag.Tag);
            db.AppuntiTag.Remove(dbApp);

            if (dbTag != null)
            {
                //decremento
                dbTag.ContUsed--;
                if (dbTag.ContUsed == 0)                //cancello se non ci sono piu tag
                    db.Tags.Remove(dbTag);
            }
        }
Example #2
0
        private static void AddTag(OmeopautaContext db, string strTag, DBAppunto appunto, DBTag dbTag)
        {
            if (dbTag == null)
                dbTag = db.Tags.Add(new DBTag() {
                    ContUsed = 1,
                    Tag = strTag
                });
            else
                dbTag.ContUsed++;

            db.AppuntiTag.Add(new DBAppuntiTag()
            {
                Appunto = appunto,
                Tag = dbTag
            });
        }