예제 #1
0
        public async Task <IActionResult> DeleteAsync([FromRoute] string tagId)
        {
            if (!Guid.TryParse(tagId, out var id))
            {
                return(BadRequest(new ErrorResponse {
                    Error = "Invalid tag id"
                }));
            }

            var userId = _identityService.GetUserIdentity();
            var tag    = await _tagsService.GetByIdAsync(id, userId).ConfigureAwait(false);

            if (tag == null)
            {
                return(NotFound());
            }

            var exist = await _tagsService.CheckLinkedLocksExistence(id, userId).ConfigureAwait(false);

            if (exist)
            {
                return(BadRequest(new ErrorResponse {
                    Error = "Could not delete tag wih linked locks"
                }));
            }

            var deleted = await _tagsService.DeleteAsync(id, userId).ConfigureAwait(false);

            if (!deleted)
            {
                return(NotFound());
            }

            return(NoContent());
        }