Пример #1
0
        public async Task <IActionResult> VerifySubmit(int id, IFormFile photo)
        {
            var employee = await _employees.FindByIdAsync(id);

            // Populate Known Photo View Model
            var photoData  = new EmployeePhotoViewModel(employee, _storageService);
            var validPhoto = await _employees.ValidatePhotoAsync(employee);

            photoData.MapFacesForValidation(validPhoto.Faces);
            if (!validPhoto.IsValidEmployeePhoto)
            {
                ViewBag.ErrorMessage = "There was an error with the photo.";
            }
            ViewBag.KnownPhotoData = photoData;

            // Upload the Verification Photo to Blob Storage
            var uniqueVerifyPath = "verify/" + System.Guid.NewGuid().ToString() + Path.GetExtension(photo.FileName);
            var photoUploadData  = await _storageService.WriteEmployeePhoto(employee.Id, uniqueVerifyPath, photo);

            var verifyFullUrl = _storageService.FullPhotoUrl(employee.Id, uniqueVerifyPath);

            // Run Verification
            var verifyData = await _employees.VerifyPhotoAsync(employee, verifyFullUrl);

            // Populate Photo Data for Verification Matches
            var verifyPhotoData = new EmployeePhotoViewModel(employee, _storageService);

            verifyPhotoData.Url = verifyFullUrl;
            verifyPhotoData.OriginalImageHeight = photoUploadData.ImageHeight;
            verifyPhotoData.OriginalImageWidth  = photoUploadData.ImageWidth;
            verifyPhotoData.MapFacesForVerification(verifyData);
            ViewBag.ToVerifyPhotoData = verifyPhotoData;

            ViewBag.IsMatch = false;
            if (verifyData.Where(y => y.IsMatch == true).Count() > 0)
            {
                ViewBag.IsMatch = true;
            }

            return(View(employee));
        }