Exemplo n.º 1
0
        public async Task <VerifyFaceResponse> VerifyFace(VerifyFace model)
        {
            var face = await DetectFace(model.Image);

            if (face.Length == 0 || face.Length > 1)
            {
                return(new VerifyFaceResponse
                {
                    Error = new Error
                    {
                        Code = "Validation error",
                        Message = face.Length == 0 ? "No face found" : "More than one face found"
                    }
                });
            }

            var groupId = Configuration["PersonGroupId"];

            var url = Configuration["CognitiveFacesUri"] + "/verify";

            var key = Configuration["CognitiveFacesKey"];

            var payload = "{ \"faceId\": \"" + face.First().FaceId + "\", \"personId\": \"" + model.Id + "\", \"personGroupId\": \"" + groupId + "\"}";

            var byteData = Encoding.UTF8.GetBytes(payload);

            using (var content = new ByteArrayContent(byteData))
            {
                var response = await CognitiveServicesHttpClient.HttpPost(content, url, key);

                var responseBytes = await response.Content.ReadAsStringAsync();

                return(JSONHelper.FromJson <VerifyFaceResponse>(responseBytes));
            }
        }
        public async Task <JsonResult> VerifyFace(VerifyFace model)
        {
            if (ModelState.IsValid)
            {
                var response = await FaceVerificationService.VerifyFace(model);

                return(new JsonResult(response));
            }

            var modelStateErrors = ModelState.Values.Select(x => x.Errors);

            return(new JsonResult(modelStateErrors));
        }