Пример #1
0
        public async Task <ActionResult> CompareAsync(int id)
        {
            var result = await _contentService.GetContentAsync(id);

            if (!result.Success)
            {
                return(new NotFoundObjectResult(result.Message));
            }

            if (string.IsNullOrEmpty(result.Content.LeftContentData))
            {
                return(new NotFoundObjectResult($"Content {id} left not found."));
            }

            if (string.IsNullOrEmpty(result.Content.RightContentData))
            {
                return(new NotFoundObjectResult($"Content {id} right not found."));
            }

            var contentLeft  = Convert.FromBase64String(result.Content.LeftContentData);
            var contentRight = Convert.FromBase64String(result.Content.RightContentData);

            var compareResult = _contentService.CompareContents(contentLeft, contentRight);

            if (compareResult.Differences?.Count > 0)
            {
                return(new OkObjectResult(compareResult.Differences));
            }

            return(new OkObjectResult(compareResult.Message));
        }