Ejemplo n.º 1
0
        public Task<Response> DeleteNote(string noteId, string editKey)
        {
            var noteManager = new NoteManager(Resolver.Get<KeyValueStore<NoteEntity>>());
            var deleteRequest = new DeleteNoteRequest
            {
                NoteId = noteId,
                EditKey = editKey,
            };

            return noteManager.DeleteNote(deleteRequest, CancellationToken.None);
        }
Ejemplo n.º 2
0
        public async Task<Response> DeleteNote(DeleteNoteRequest 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);
            }

            var noteEntity = await GetEntityForEditing(request.NoteId, request.EditKey, cancellationToken);
            if (noteEntity == null)
            {
                return new Response { StatusCode = HttpStatusCode.NotFound };
            }

            try
            {
                await this.noteStore.Delete(noteEntity, cancellationToken);
                return new Response { StatusCode = HttpStatusCode.OK };
            }
            catch (ETagMismatchException)
            {
                return new Response { StatusCode = HttpStatusCode.PreconditionFailed };
            }
        }