public Task<Response> UpdateNote(string noteId, string editKey) { var updateNoteRequest = new UpdateNoteRequest { NoteId = noteId, EditKey = editKey, Content = Content, Title = Title, NoteType = NoteType, }; var noteManager = new NoteManager(Resolver.Get<KeyValueStore<NoteEntity>>()); return noteManager.UpdateNote(updateNoteRequest, CancellationToken.None); }
public async Task<Response> UpdateNote(UpdateNoteRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var validationContext = new ValidationContext(); request.Validate(validationContext); if (validationContext.HasErrors) { throw new ValidationException(validationContext); } // if there's an etag mismatch exception, retry up to 3 times for (int i = 0; i < 3; i++) { var noteEntity = await GetEntityForEditing(request.NoteId, request.EditKey, cancellationToken); if (noteEntity == null) { return new Response { StatusCode = HttpStatusCode.NotFound }; } noteEntity.Title = request.Title; noteEntity.Content = request.Content; noteEntity.NoteType = request.NoteType; try { await this.noteStore.Update(noteEntity, cancellationToken); return new Response { StatusCode = HttpStatusCode.OK }; } catch (ETagMismatchException) { } } return new Response { StatusCode = HttpStatusCode.PreconditionFailed }; }