Esempio n. 1
0
 /*Check if the note already has the tag you are going to give it - don't duplicate*/
 public static void Create(Note_Tag noteTag)
 {
     if (!CheckIfNoteHasTag(noteTag))
     {
         var db  = MyDB.GetInstance();
         var sql =
             string.Format("INSERT INTO Notes_Tags VALUES ('{0}', '{1}')", noteTag.NoteId, noteTag.TagId);
         db.ExecuteSql(sql);
     }
 }
Esempio n. 2
0
        public static bool CheckIfNoteHasTag(Note_Tag noteTag)
        {
            var db  = MyDB.GetInstance();
            var sql =
                string.Format("SELECT * FROM Notes_Tags WHERE noteId = '{0}' AND tagId = '{1}'", noteTag.NoteId, noteTag.TagId);
            var result = db.ExecuteSelectSql(sql);

            if (result.HasRows)
            {
                return(true); // true if there is a note with this tag
            }
            return(false);    //false if there is no tag with this note
        }
 public static bool AddNote_Tag(Note_Tag note_tag)
 {
     try
     {
         using (var _context = new SimpleNoteEntities())
         {
             _context.Note_Tag.Add(note_tag);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
 public static bool DeleteNote_Tag(Note_Tag note_tag)
 {
     try
     {
         using (var _context = new SimpleNoteEntities())
         {
             var note = (from u in _context.Note_Tag
                         where u.ID == note_tag.ID
                         where u.MiniTag == note_tag.MiniTag
                         select u).SingleOrDefault();
             _context.Note_Tag.Remove(note);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
        public ActionResult Create(Note note)
        {
            try
            {
                NoteDAO.Create(note);
                //get tags
                var      tagList   = note.TagList;
                char[]   delimiter = { ' ' };
                string[] tags      = tagList.Split(delimiter);

                foreach (var tag in tags)
                {
                    if (tag != null || tag != "")
                    {
                        var t = new Tag
                        {
                            Name = tag
                        };
                        TagDAO.Create(t);
                    }

                    var tagItem = TagDAO.GetTag(tag);
                    var nTag    = new Note_Tag();
                    nTag.NoteId = note.NoteId;
                    nTag.TagId  = tagItem.Id;
                    Note_TagDAO.Create(nTag);
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));

                return(View());
            }

            return(RedirectToAction("Index", "Home"));
        }