/// <summary> /// Save note to collection /// and data storage /// </summary> /// <param name="id">Id</param> /// <param name="note">Note</param> public QuickNote SaveNote(string id, string note) { var qnote = new QuickNote { Id = Guid.NewGuid(), Author = author, Note = note }; var idx = Notes.FindIndex(n => n.Id.ToString() == id); if (idx >= 0) qnote.Id = Notes[idx].Id; BlogService.SaveQuickNote(qnote); Blog.CurrentInstance.Cache.Remove(cacheKey); return qnote; }
/// <summary> /// Save quick note /// </summary> /// <param name="note">Quick note</param> public override void SaveQuickNote(QuickNote note) { var fileName = Path.Combine(this.Folder, notesFileName); var notes = FillQuickNotes(note.Author) ?? new List<QuickNote>(); int idx = -1; for (int index = 0; index < notes.Count; index++) { var n = notes[index]; if (n.Id == note.Id) { idx = index; break; } } if (idx >= 0) notes.RemoveAt(idx); notes.Insert(0, note); using (var writer = new XmlTextWriter(fileName, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.Indentation = 4; writer.WriteStartDocument(true); writer.WriteStartElement("QuickNotes"); foreach (var n in notes) { writer.WriteStartElement("item"); writer.WriteAttributeString("id", n.Id.ToString()); writer.WriteAttributeString("blogid", Blog.CurrentInstance.Id.ToString()); writer.WriteAttributeString("note", n.Note); writer.WriteAttributeString("author", n.Author); writer.WriteEndElement(); } writer.WriteEndElement(); } }
/// <summary> /// Fill quick notes /// </summary> /// <param name="userId">User ID</param> /// <returns>List of user notes</returns> public override List<QuickNote> FillQuickNotes(string userId) { var notes = new List<QuickNote>(); using (var conn = this.CreateConnection()) { if (conn.HasConnection) { using (var cmd = conn.CreateTextCommand(string.Format("SELECT NoteId, Note, Updated FROM {0}QuickNotes where UserName = '******' and BlogId = '{2}'", tablePrefix, userId, Blog.CurrentInstance.Id.ToString()))) { using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var n = new QuickNote() { Id = rdr.GetGuid(0), Author = userId, Note = rdr.GetString(1), Updated = rdr.GetDateTime(2) }; notes.Add(n); } } } } } return notes; }
/// <summary> /// Save quick note /// </summary> /// <param name="note">Quick note</param> public override void SaveQuickNote(QuickNote note) { using (var conn = this.CreateConnection()) { if (conn.HasConnection) { var sqlQuery = string.Format("select count(*) from {0}QuickNotes where NoteId = {1}noteid", this.tablePrefix, this.parmPrefix); object cnt; using (var cmd = conn.CreateTextCommand(sqlQuery)) { var p = cmd.Parameters; p.Add(conn.CreateParameter(FormatParamName("noteid"), note.Id)); cnt = cmd.ExecuteScalar(); } if (int.Parse(cnt.ToString()) > 0) sqlQuery = string.Format("update {0}QuickNotes set Note = {1}note, updated = {1}updated where NoteId = {1}noteid", this.tablePrefix, this.parmPrefix); else sqlQuery = string.Format("insert into {0}QuickNotes (NoteId, BlogId, UserName, Note, Updated) values ({1}noteid, {1}blogid, {1}username, {1}note, {1}updated)", this.tablePrefix, this.parmPrefix); using (var cmd = conn.CreateTextCommand(sqlQuery)) { var p = cmd.Parameters; p.Add(conn.CreateParameter(FormatParamName("noteid"), note.Id)); p.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString())); p.Add(conn.CreateParameter(FormatParamName("username"), note.Author)); p.Add(conn.CreateParameter(FormatParamName("note"), note.Note)); p.Add(conn.CreateParameter(FormatParamName("updated"), DateTime.Now.AddHours(-BlogSettings.Instance.Timezone))); cmd.ExecuteNonQuery(); } } } }