コード例 #1
0
        public async Task <ActionResult> Register(EnrolleeDto enrolleeDto, HttpPostedFileBase image)
        {
            string[] formats = new string[] { ".jpg", ".png", ".gif", ".jpeg" };

            if ((image == null || !image.ContentType.Contains("image")) || !formats.Any(item =>
                                                                                        image.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError(string.Empty, "Load your valid document");
            }

            if (!ModelState.IsValid)
            {
                return(View(enrolleeDto));
            }

            if (image != null || image.ContentType.Contains("image") || !formats.Any(item =>
                                                                                     image.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
            {
                enrolleeDto = _accountService.VerifyImage(enrolleeDto, image);
            }

            var sucsess = await UserService.Create(enrolleeDto);

            if (sucsess)
            {
                return(RedirectToAction("Login", "Account"));
            }

            ModelState.AddModelError("RegisterError", "The register was failed. Please, try again.");

            return(View(enrolleeDto));
        }
コード例 #2
0
        public async Task <bool> Create(EnrolleeDto enrolleeDto)
        {
            _logger.Info($"Finding by Email {enrolleeDto.Email} an enrolee. ");

            var user = await _unitOfWork.UserManager.FindByEmailAsync(enrolleeDto.Email);

            if (user != null)
            {
                return(false);
            }

            user = new IdentityUser {
                Email = enrolleeDto.Email, UserName = enrolleeDto.Email
            };

            var result = await _unitOfWork.UserManager.CreateAsync(user, enrolleeDto.Password);

            if (result.Errors.Count() != 0)
            {
                throw new Exception();
            }

            _logger.Info($"Adding the role to new enrolee.");

            await _unitOfWork.UserManager.AddToRoleAsync(user.Id, "User");

            var profile = _mapper.Map <Enrollee>(enrolleeDto);

            profile.AppCustomer = user;
            profile.Lock        = false;

            _unitOfWork.EnrolleeGenericRepository.Create(profile);

            return(true);
        }
コード例 #3
0
        public EnrolleeDto VerifyImage(EnrolleeDto enrolleeDto, HttpPostedFileBase image)
        {
            _logger.Info($"Verify image for {enrolleeDto.Email}");

            enrolleeDto.ImageMimeType = image.ContentType;
            enrolleeDto.ImageData     = new byte[image.ContentLength];
            image.InputStream.Read(enrolleeDto.ImageData, 0, image.ContentLength);

            return(enrolleeDto);
        }
コード例 #4
0
        public void VerifyImage_ExistingEnrolle()
        {
            var enrolee = new EnrolleeDto();
            var image   = new Mock <HttpPostedFileBase>();

            image.SetupGet(file => file.ContentType).Returns("jpg");
            image.SetupGet(file => file.ContentLength).Returns(1);
            image.Setup(file => file.InputStream).Returns(new FileStream("path", FileMode.OpenOrCreate, FileAccess.Read));

            _sut.VerifyImage(enrolee, image.Object);

            Assert.Equal(image.Object.ContentType, enrolee.ImageMimeType);
        }