Example #1
0
        public ActionResult Registar(RegistarViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            else
            {
                if (DateTime.Now.Year - viewModel.DataNascimento.Year < 18)
                {
                    ViewBag.mensagem = "Deve ser maior de 18 anos para efetuar o cadastro!";
                    return(View(viewModel));
                }
                viewModel.UsuarioPerfilId = UsuarioPerfilRepositorio.BuscarPeloNome("Usuário").Id;
                viewModel.NomeUsuario     = viewModel.Email;

                var id = UsuarioRepositorio.Salvar(Mapper.Map <Usuario>(viewModel));

                if (string.IsNullOrEmpty(id))
                {
                    return(View(viewModel));
                }

                return(RedirectToAction("Login", "Conta"));
            }
        }
Example #2
0
 public RegistarView()
 {
     InitializeComponent();
     BindingContext = new RegistarViewModel();
     NavigationPage.SetHasBackButton(this, true);
     NavigationPage.SetHasNavigationBar(this, true);
     ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.FromHex("#C65F4A");
 }
        public ActionResult RegistrarUsuario(RegistarViewModel objViewModel)
        {
            LBPEntities context    = new LBPEntities();
            Usuarios    objUsuario = new Usuarios();

            if (objUsuario == null)
            {
                return(View(objViewModel));
            }

            List <Usuarios> lstUsuarios = new List <Usuarios>();

            lstUsuarios = context.Usuarios.ToList();

            for (int i = 0; i < lstUsuarios.Count; i++)
            {
                if (objViewModel.Usuario == lstUsuarios[i].Usuario)
                {
                    return(View(objViewModel));
                }
                else
                {
                    if (objViewModel.Usuario == null || objViewModel.Password == null || objViewModel.Nombre == null ||
                        objViewModel.Paterno == null || objViewModel.Materno == null)
                    {
                        return(View(objViewModel));
                    }
                    else
                    {
                        objUsuario.Nombre    = objViewModel.Nombre;
                        objUsuario.Paterno   = objViewModel.Paterno;
                        objUsuario.Materno   = objViewModel.Materno;
                        objUsuario.Usuario   = objViewModel.Usuario;
                        objUsuario.Password  = objViewModel.Password;
                        objUsuario.EstatusId = 2;
                        objUsuario.RolId     = 3;
                    }
                }
            }
            context.Usuarios.Add(objUsuario);
            context.SaveChanges();

            return(RedirectToAction("Login"));
        }
        public async Task RegistrarAsync(RegistarViewModel model)
        {
            AddToken();
            var resposta = await _httpClient.PostAsJsonAsync($"v1/Auth/novo-usuario", model);

            if (!resposta.IsSuccessStatusCode)
            {
                HttpResponseHeaders header = resposta.Headers;
                var contents = await resposta.Content.ReadAsStringAsync();

                resposta.StatusCode = System.Net.HttpStatusCode.BadRequest;
            }
            else
            {
                resposta.EnsureSuccessStatusCode();
            }
            //if (response.IsSuccessStatusCode)

            //    var responseJson = await resposta.Content.ReadAsStringAsync();
            //Console.WriteLine(responseJson);
        }
        public ActionResult RegistrarUsuario()
        {
            RegistarViewModel objViewMolel = new RegistarViewModel();

            return(View(objViewMolel));
        }