Ejemplo n.º 1
0
        public async Task <IActionResult> CreateSecretAsync([FromBody] Client.SecretCreationInfo creationInfo,
                                                            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (creationInfo == null)
            {
                var error = ErrorResponsesService.BodyIsMissing(nameof(creationInfo));
                return(BadRequest(error));
            }

            const string blackTemplateWithColoredPoints = "1001582";
            var          pointsUrl = await PhotolabService.PostMultipartFormData(creationInfo.ImageUrl, blackTemplateWithColoredPoints);

            var webClient  = new WebClient();
            var imageBytes = await webClient.DownloadDataTaskAsync(pointsUrl);

            Stream stream = new MemoryStream(imageBytes);

            var          description = PhysiognomyService.GetDescription(new Bitmap(stream));
            const string photoTemplateWithColoredPoints = "1001581";
            var          url = await PhotolabService.PostMultipartFormData(creationInfo.ImageUrl, photoTemplateWithColoredPoints);

            var modelCreationInfo = new Model.SecretCreationInfo(url, description);
            var modelSecret       =
                await repository.CreateAsync(modelCreationInfo, cancellationToken).ConfigureAwait(false);

            var clientSecret = Converter.SecretConverter.Convert(modelSecret);

            return(CreatedAtRoute("GetSecretRoute", new { id = clientSecret.Id }, clientSecret));
        }
        public static Model.SecretCreationInfo Convert(Client.SecretCreationInfo clientCreationInfo)
        {
            if (clientCreationInfo == null)
            {
                throw new ArgumentNullException(nameof(clientCreationInfo));
            }

            //todo stub
            var modelCreationInfo = new Model.SecretCreationInfo(clientCreationInfo.ImageUrl, string.Empty);

            return(modelCreationInfo);
        }