public async Task <IActionResult> Create(ApplicationUserCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _blobService.CreateBlobAsync(model.Image);

            if (result.Success)
            {
                model.ImageName = result.NewFileName;

                if (await _appUserService.CreateAsync(model))
                {
                    var oMessage = new MessageViewModel($"El usuario <a href='#' class='alert-link'>{model.Name}</a> ha sido creado exitosamente!", "alert-success");

                    TempData.PutObject("Message", oMessage);
                }
                else
                {
                    var oMessage = new MessageViewModel("Hubo un problema y no se pudo crear el recurso.", "alert-danger");

                    TempData.PutObject("Message", oMessage);
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError(nameof(model.Image), "Sólo se admiten tipos de archivos PNG o JPG.");

                return(View(model));
            }
        }
        public async Task <IActionResult> CreateUserAsync(CreateUserViewModel model)
        {
            ApplicationUserDto user = new ApplicationUserDto
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                UserName  = model.UserName,
                Email     = model.Email
            };

            await applicationUserService.CreateAsync(user, model.Password);

            return(RedirectToAction("UsersList", "Account"));
        }
Example #3
0
        public async Task <IActionResult> Create(ApplicationUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var dto = _mapper.Map <ApplicationUserDto>(viewModel);
                var id  = await _applicationUserService.CreateAsync(dto);

                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.ErrorMessage = ModelState.ModelErrorsToString();
                return(View(viewModel));
            }
        }
        public async Task <RegistrationView> RegisterAsync(RegistrationDto dto)
        {
            var existingUser = await context.Users.SingleOrDefaultAsync(auth => auth.Username == dto.Username);

            if (existingUser != null)
            {
                throw new AuthenticationException();
            }

            var user = mapper.Map <ApplicationUser>(dto);

            var securedPassword = passwordUtils.CreateHash(dto.Password);

            user.SetHashAndSalt(securedPassword.Hash, securedPassword.Salt);

            await userService.CreateAsync(user);

            return(mapper.Map <RegistrationView>(user));
        }