Пример #1
0
        // GET: Employees/Verify/5
        public async Task <IActionResult> Verify(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var employee = await _employees.FindByIdAsync(id.Value);

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


            // Populate 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;
            ViewBag.ToVerifyPhotoData = new EmployeePhotoViewModel();

            return(View(employee));
        }
Пример #2
0
        // GET: Employees/Edit/5
        public async Task <IActionResult> Edit(int?id, bool highlightFaces = false)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var employee = await _employees.FindByIdAsync(id.Value);

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

            // Populate Photo View Model
            var photoData = new EmployeePhotoViewModel(employee, _storageService);

            if (highlightFaces == true)
            {
                // Check Faces
                var validPhoto = await _employees.ValidatePhotoAsync(employee);

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

            return(View(employee));
        }
Пример #3
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));
        }