public async Task <ActionResult> Create(MvcUsuarioModel usuario)
        {
            var account = new RegisterModel()
            {
                Email           = usuario.Email,
                Password        = "******",
                ConfirmPassword = "******"
            };

            bool errorBadRequest = false;

            try
            {
                try
                {
                    await _authenticationEndpoint.RegisterAccount(account, _userSession.BearerToken);
                }
                catch (BadRequestException ex)
                {
                    ModelState.AddModelErrors(ex.Errors);

                    errorBadRequest = true;
                }

                try
                {
                    var entity = _mapper.Map <Usuario>(usuario);

                    await _usuarioEndpoint.Post(entity, _userSession.BearerToken);
                }
                catch (BadRequestException ex)
                {
                    ModelState.AddModelErrors(ex.Errors);

                    errorBadRequest = true;
                }
            }
            catch (UnauthorizedRequestException)
            {
                return(RedirectToAction("AccessDeniedPartial", "Error"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("SpecificErrorPartial", "Error", new { error = ex.Message }));
            }


            if (errorBadRequest)
            {
                return(PartialView("_Create", usuario));
            }

            return(Content("OK"));
        }
Beispiel #2
0
        public async void Create()
        {
            ErrorMessages = null;

            var usuario = new WpfUsuarioModel
            {
                Firstname = FirstnameInForm,
                Surname   = SurnameInForm,
                Email     = EmailInForm,
                Username  = UsernameInForm,
                Legajo    = LegajoInForm,
                Matricula = MatriculaInForm,
                IsAdmin   = IsAdminInForm,
                Phone1    = Phone1InForm,
                Phone2    = Phone2InForm
            };

            try
            {
                var entity = _mapper.Map <Usuario>(usuario);

                await _usuarioEndpoint.Post(entity, _usuarioLogged.Token);
                await LoadUsuarios();

                SelectedUsuario = null;
            }
            catch (UnauthorizedRequestException)
            {
                ErrorMessages = new BindingList <string> {
                    "No tiene acceso"
                };
            }
            catch (BadRequestException ex)
            {
                ErrorMessages = new BindingList <string>(ex.Errors.Select(kvp => string.Join(". ", kvp.Value)).ToList());
            }
            catch (Exception ex)
            {
                ErrorMessages = new BindingList <string> {
                    $"{ex.Message} Ha ocurrido un error. Por favor contacte a soporte"
                };
            }
        }