public async Task <ApiResult <NoteSummary> > ModifyAsync(T parm) { var res = new ApiResult <NoteSummary>(); try { parm.user_id = Config.userid(); parm.updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); NoteSummary summary = new NoteSummary(); var asyncResult = Db.Ado.UseTranAsync(() => { Db.Updateable(parm).ExecuteCommand(); //更新所属分类笔记表 summary = CreateSummary(parm); //生成总结说明 Db.Updateable(summary).IgnoreColumns(ignoreAllNullColumns: true) .Where(it => it.note_category == summary.note_category && it.note_id == summary.note_id).ExecuteCommand();//更新笔记总结表 }); asyncResult.Wait(); var time = summary.note_time; summary.note_time = time.Substring(11); res.data = summary; } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error + ex.Message; } return(await Task.Run(() => res)); }
public async Task SaveNote(Note note) { if (note == null) { throw new ArgumentNullException("note"); } if (string.IsNullOrWhiteSpace(note.UserId)) { throw new ArgumentException("The note provided didn't have a user ID assigned"); } Guid noteId = note.NoteId ?? Guid.NewGuid(); string noteObjectKey = GetNoteObjectKey(note.UserId, noteId); try { PutObjectRequest putRequest = new PutObjectRequest { BucketName = _s3Settings.BucketName, Key = noteObjectKey, StorageClass = S3StorageClass.Standard, CannedACL = S3CannedACL.Private, ContentType = "application/json", ContentBody = JsonConvert.SerializeObject(note) }; PutObjectResponse response = await _s3Client.PutObjectAsync(putRequest); // Save data in cache. _cache.SetString(noteObjectKey, JsonConvert.SerializeObject(note), _cacheEntryOptions); // Update summary List <NoteSummary> notes = await GetNoteList(note.UserId); NoteSummary oldNote = notes.Where(n => n.NoteId == noteId).SingleOrDefault(); if (notes != null) { notes.Remove(oldNote); } notes.Add(new NoteSummary { NoteId = note.NoteId, UserId = note.UserId, Title = note.Title, CreatedAt = note.CreatedAt }); await SaveNoteList(note.UserId, notes); } catch (Exception ex) { _logger.LogError(ex, "An error occured while saving a note."); throw; } }
public async Task DeleteNote(string username, Guid noteId) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException("username"); } if (noteId == null) { throw new ArgumentNullException("noteId"); } string noteObjectKey = GetNoteObjectKey(username, noteId); DeleteObjectRequest deleteRequest = new DeleteObjectRequest { BucketName = _s3Settings.BucketName, Key = noteObjectKey }; try { DeleteObjectResponse response = await _s3Client.DeleteObjectAsync(deleteRequest); // Remove data from cache. _cache.Remove(noteObjectKey); // Update summary List <NoteSummary> notes = await GetNoteList(username); NoteSummary oldNote = notes.Where(n => n.NoteId == noteId).SingleOrDefault(); if (notes != null) { notes.Remove(oldNote); // Remove data from cache. _cache.Remove(noteObjectKey); } await SaveNoteList(username, notes); } catch (AmazonS3Exception ex) { _logger.LogError(ex, "An error occured while deleting a note."); return; } }
/// <summary> /// 重写 /// 生成总结说明 /// </summary> /// <param name="parm"></param> /// <returns></returns> public override NoteSummary CreateSummary(NoteNaiping parm) { NoteSummary sy = new NoteSummary { note_category = "naiping", note_id = parm.id, baby_id = parm.baby_id, user_id = parm.user_id, note_time = parm.note_time, note_date = parm.note_time.Substring(0, 10), updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), finished = true }; sy.summary = $"摄入 {parm.intake} ml {parm.kind}。"; return(sy); }
/// <summary> /// 重写 /// 生成总结说明 /// </summary> /// <param name="parm"></param> /// <returns></returns> public override NoteSummary CreateSummary(NoteWanshua parm) { NoteSummary sy = new NoteSummary { note_category = "wanshua", note_id = parm.id, baby_id = parm.baby_id, user_id = parm.user_id, note_time = parm.note_time, note_date = parm.note_time.Substring(0, 10), updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), finished = true }; sy.summary = $"玩了{Utils.TwoTimeInterval(parm.begin_time, parm.end_time)}。"; return(sy); }
public async Task SaveNote(Note note) { if (note == null) { throw new ArgumentNullException("note"); } if (string.IsNullOrWhiteSpace(note.UserId)) { throw new ArgumentException("The note provided didn't have a user ID assigned"); } try { Document document = await _client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(_cosmosDbSettings.DatabaseId, _cosmosDbSettings.CollectionId), note); // re-assign the note id as it was assigned by CosmosDB note.Id = document.Id; string noteObjectKey = GetNoteObjectKey(note.UserId, document.Id); // Save data in cache. _cache.SetString(noteObjectKey, JsonConvert.SerializeObject(note), _cacheEntryOptions); // Update summary List <NoteSummary> notes = GetNoteList(note.UserId); NoteSummary oldNote = notes.SingleOrDefault(n => n.NoteId == document.Id); if (notes != null) { notes.Remove(oldNote); } notes.Add(new NoteSummary { NoteId = note.Id, UserId = note.UserId, Title = note.Title, CreatedAt = note.CreatedAt }); SaveNoteList(note.UserId, notes); } catch (Exception ex) { _logger.LogError(ex, "An error occured while saving a note."); throw; } }
public async Task SaveNote(Note note) { if (note == null) { throw new ArgumentNullException("note"); } if (string.IsNullOrWhiteSpace(note.UserId)) { throw new ArgumentException("The note provided didn't have a user ID assigned"); } Guid noteId = note.NoteId ?? Guid.NewGuid(); string notePath = GetNotePath(note.UserId, noteId); // check that the directory exists if (!Directory.Exists(Path.GetDirectoryName(notePath))) { Directory.CreateDirectory(Path.GetDirectoryName(notePath)); } using (StreamWriter file = File.CreateText(notePath)) { await file.WriteAsync(JsonConvert.SerializeObject(note)); // Save data in cache. _cache.SetString(notePath, JsonConvert.SerializeObject(note), _cacheEntryOptions); } // Update summary List <NoteSummary> notes = await GetNoteList(note.UserId); NoteSummary oldNote = notes.Where(n => n.NoteId == noteId).SingleOrDefault(); if (notes != null) { notes.Remove(oldNote); } notes.Add(new NoteSummary { NoteId = note.NoteId, UserId = note.UserId, Title = note.Title, CreatedAt = note.CreatedAt }); await SaveNoteList(note.UserId, notes); }
/// <summary> /// 重写 /// 生成总结说明 /// </summary> /// <param name="parm"></param> /// <returns></returns> public override NoteSummary CreateSummary(NoteNiaoku parm) { NoteSummary sy = new NoteSummary { note_category = "niaoku", note_id = parm.id, baby_id = parm.baby_id, user_id = parm.user_id, note_time = parm.note_time, note_date = parm.note_time.Substring(0, 10), updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), finished = true }; sy.summary = parm.status; return(sy); }
public Dashboard() { InitializeComponent(); this.LoadNotes(); foreach (var note in AllNotes) { NoteModel noteModel = new NoteModel { Id = note.Id, NoteTitle = note.NoteTitle, NoteContent = note.NoteContent, DateCreated = note.DateCreated, DateModified = note.DateModified }; NoteSummary noteSummary = new NoteSummary(noteModel); notesListFlow.Controls.Add(noteSummary); } }
public async Task DeleteNote(string username, string noteId) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException("username"); } if (noteId == null) { throw new ArgumentNullException("noteId"); } string noteObjectKey = GetNoteObjectKey(username, noteId); try { await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(_cosmosDbSettings.DatabaseId, _cosmosDbSettings.CollectionId, noteId)); // Remove data from cache. _cache.Remove(noteObjectKey); // Update summary List <NoteSummary> notes = GetNoteList(username); NoteSummary oldNote = notes.SingleOrDefault(n => n.NoteId == noteId); if (notes != null) { notes.Remove(oldNote); // Remove data from cache. _cache.Remove(noteObjectKey); } SaveNoteList(username, notes); } catch (Exception ex) { _logger.LogError(ex, "An error occured while deleting a note."); return; } }
public async Task DeleteNote(string username, Guid noteId) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException("username"); } if (noteId == null) { throw new ArgumentNullException("noteId"); } string notePath = GetNotePath(username, noteId); if (File.Exists(notePath)) { File.Delete(notePath); // Remove data from cache. _cache.Remove(notePath); } // Update summary List <NoteSummary> notes = await GetNoteList(username); NoteSummary oldNote = notes.Where(n => n.NoteId == noteId).SingleOrDefault(); if (notes != null) { notes.Remove(oldNote); // Remove data from cache. _cache.Remove(notePath); } await SaveNoteList(username, notes); }