public async Task UpsertNotes(string notes, string ownerName) { try { var db = _mongoClient.GetDatabase(DatabaseName); var notesEntities = db.GetCollection <NotesEntity>(NotesCollectionName); var oldEntity = await notesEntities .Find(e => e.OwnerName == ownerName) .FirstOrDefaultAsync(); var entity = new NotesEntity { Id = oldEntity?.Id, OwnerName = ownerName, Notes = notes, }; if (entity.Id == null) { await notesEntities.InsertOneAsync(entity); } else { await notesEntities.ReplaceOneAsync(e => e.Id == entity.Id, entity); } } catch (Exception e) { _logger.LogError(e.Message); } }
public async Task <IActionResult> SaveNoteDetails([FromBody] NotesEntity notesEntity) { try { // Getting stored conversation data reference. var currentRosterInfo = new ConversationData(); _conversationDataReference.TryGetValue("conversationData", out currentRosterInfo); if (currentRosterInfo == null) { throw new ArgumentNullException(nameof(currentRosterInfo)); } notesEntity.AddedByName = currentRosterInfo.Roster.Length > 0 ? currentRosterInfo.Roster.Where(entity => entity.Email == notesEntity.AddedBy).FirstOrDefault().Name: "Unknown"; var result = await this._notesRepository.StoreOrUpdateQuestionEntityAsync(notesEntity); if (result == null) { return(NotFound()); } return(Ok(result)); } catch (Exception ex) { throw ex; } }
/// <summary> /// Store or update notes in table storage. /// </summary> /// <param name="entity">Represents notes entity used for storage and retrieval.</param> /// <returns><see cref="Task"/> that represents notes entity is saved or updated.</returns> public async Task <TableResult> StoreOrUpdateQuestionEntityAsync(NotesEntity entity) { entity.PartitionKey = entity.CandidateEmail; entity.RowKey = string.Format("{0:D19}", DateTime.UtcNow.Ticks); await this.EnsureInitializedAsync().ConfigureAwait(false); TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(entity); return(await this.notesCloudTable.ExecuteAsync(addOrUpdateOperation).ConfigureAwait(false)); }
public int EditNote(int id, [FromBody] NotesEntity note) { //return objemployee.UpdateEmployee(employee); NotesEntity existingNote = lstNotes.Where(x => x.Id == id).FirstOrDefault(); lstNotes[lstNotes.IndexOf(existingNote)] = note; existingNote.Tags = note.Tags; return(1); }
public IEnumerable <NotesEntity> AddNote([FromBody] NotesEntity note) { var id = 1; if (lstNotes.Count > 0) { id = lstNotes.Max(x => x.Id) + 1; } note.Id = id; lstNotes.Add(note); return(lstNotes); }
public void when_exceptionOccure_createNotes_should_throws_exception() { _odataClientMock.Setup(x => x.For <SSG_Notese>(null).Set(It.Is <NotesEntity>(x => x.Description == "exception")) .InsertEntryAsync(It.IsAny <CancellationToken>())) .Throws(new Exception("fakeException")); var notesEntity = new NotesEntity() { StatusCode = 1, Description = "exception", }; Assert.ThrowsAsync <Exception>(async() => await _sut.CreateNotes(notesEntity, CancellationToken.None)); }
public async Task <SSG_Notese> CreateNotes(NotesEntity note, CancellationToken cancellationToken) { if (note.SearchRequest != null && note.SearchRequest.IsDuplicated) { Guid duplicatedNoteId = await _duplicateDetectService.Exists(note.SearchRequest, note); if (duplicatedNoteId != Guid.Empty) { return new SSG_Notese() { NotesId = duplicatedNoteId } } ; } return(await this._oDataClient.For <SSG_Notese>().Set(note).InsertEntryAsync(cancellationToken)); }
public async Task with_existed_fileId_createNotes_should_return_SSG_Notes() { _odataClientMock.Setup(x => x.For <SSG_Notese>(null).Set(It.Is <NotesEntity>(x => x.Description == "normal")) .InsertEntryAsync(It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new SSG_Notese() { NotesId = _testNotesId }) ); var notesEntity = new NotesEntity() { StatusCode = 1, Description = "normal", }; var result = await _sut.CreateNotes(notesEntity, CancellationToken.None); Assert.AreEqual(_testNotesId, result.NotesId); }
private async Task <bool> UploadNotes(SearchRequestEntity newSearchRequestEntity) { NotesEntity note = new NotesEntity { StatusCode = 1, Description = newSearchRequestEntity.Notes, InformationSource = InformationSourceType.Request.Value, SearchRequest = _uploadedSearchRequest }; SSG_Notese ssgNote = await _searchRequestService.CreateNotes(note, _cancellationToken); if (ssgNote == null) { _logger.LogError("Create new notes failed."); return(false); } _logger.LogInformation("Create new notes successfully."); return(true); }
public async Task searchRequest_has_same_notes_Exists_should_return_existed_entity_guid() { DuplicateDetectionService._configs = null; Guid existedNotesID = Guid.NewGuid(); SSG_SearchRequest request = new SSG_SearchRequest() { SSG_Notes = new List <SSG_Notese>() { new SSG_Notese() { Description = "description", NotesId = existedNotesID } }.ToArray() }; NotesEntity entity = new NotesEntity() { Description = "description" }; Guid guid = await _sut.Exists(request, entity); Assert.AreEqual(existedNotesID, guid); }
private async Task <bool> UploadNotes(SearchRequestEntity newSearchRequestEntity, SSG_SearchRequest existedSearchRequest) { string previousNoteStr = existedSearchRequest.Notes; if (existedSearchRequest.SSG_Notes != null && existedSearchRequest.SSG_Notes?.Length > 0) { try { previousNoteStr = existedSearchRequest.SSG_Notes.Last(m => m.InformationSource == InformationSourceType.Request.Value).Description; }catch (Exception) { _logger.LogInformation("notes does not contain notes from request. It is ok."); } } string newNotes = UpdateCurrentNote(newSearchRequestEntity.Notes, previousNoteStr); if (newNotes != null) { NotesEntity note = new NotesEntity { StatusCode = 1, Description = newNotes, InformationSource = InformationSourceType.Request.Value, SearchRequest = _uploadedSearchRequest, UpdatedByApi = true }; SSG_Notese ssgNote = await _searchRequestService.CreateNotes(note, _cancellationToken); if (ssgNote == null) { _logger.LogError("Create new notes failed."); return(false); } _logger.LogInformation("Create new notes successfully."); } return(true); }