コード例 #1
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (this.IsFormValid("RegisterForm"))
            {
                try
                {
                    using (UnitOfWork unitOfWork = new UnitOfWork())
                    {
                        DbContextTransaction transaction = unitOfWork.Context.Database.BeginTransaction();

                        var userStore = new UserStore <Usuario>(unitOfWork.Context);
                        var manager   = new UserManager <Usuario>(userStore);

                        Usuario usuario = new Usuario
                        {
                            Nome           = this.CadastroUsuario.Nome,
                            Sobrenome      = this.CadastroUsuario.Sobrenome,
                            UserName       = this.CadastroUsuario.Username,
                            Email          = this.CadastroUsuario.Email,
                            Ativo          = false,
                            DataNascimento = this.CadastroUsuario.DataNascimento
                        };

                        var result = manager.Create(usuario, this.CadastroUsuario.Senha);

                        if (result.Succeeded)
                        {
                            Pesquisador pesquisador = new Pesquisador {
                                Usuario = usuario
                            };
                            unitOfWork.Pesquisadores.Insert(pesquisador);

                            unitOfWork.Save();
                            transaction.Commit();

                            var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                            var userIdentity          = manager.CreateIdentity(usuario, DefaultAuthenticationTypes.ApplicationCookie);
                            authenticationManager.SignIn(new AuthenticationProperties()
                            {
                            }, userIdentity);
                            Response.Redirect(Urls.SignIn);
                        }
                        else
                        {
                            transaction.Rollback();
                            result.Errors.ToList().ForEach(er => this.AddErrorAlert(er));
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.AddErrorAlert(ex.Message);
                }
            }
        }
コード例 #2
0
        public ActionResult Cadastrar(Pesquisador Pesquisa)
        {
            if (ModelState.IsValid)
            {
                Pesquisa.Senha = Crypto.HashPassword(Pesquisa.Senha.ToString());
                db.Pesquisadores.Add(Pesquisa);
                db.SaveChanges();

                return(RedirectToAction("Login"));
            }

            return(View(Pesquisa));
        }
コード例 #3
0
        private async void Entrar()
        {
            try
            {
                bool isOnline = Utils.IsOnline();

                if (!isOnline)
                {
                    throw new Exception("Não há conexão disponível.");
                }

                IsRunning = true;

                ws = WSUtil.Instance;

                JObject obj = new JObject();
                obj["idpesquisador"] = TxtId;
                obj["senha"]         = TxtSenha;

                String imei = Utils.ObterImei();

                if (!String.IsNullOrEmpty(imei))
                {
                    obj["imei"] = imei;

                    HttpResponseMessage resposta = await ws.Post("login", obj);

                    String message = await resposta.Content.ReadAsStringAsync();

                    if (resposta.IsSuccessStatusCode)
                    {
                        Pesquisador pesquisadorWeb = JsonConvert.DeserializeObject <Pesquisador>(message);

                        pesquisador = dao08.ObterPesquisador(Int32.Parse(TxtId));

                        if (pesquisador == null)
                        {
                            pesquisadorWeb.pesquisador.idpesquisador = Int32.Parse(TxtId);
                            pesquisadorWeb.pesquisador.senha         = TxtSenha;
                            pesquisadorWeb.pesquisador.logado        = 1;
                            dao08.InserirPesquisador(pesquisadorWeb.pesquisador);
                        }
                        else
                        {
                            pesquisador.logado      = 1;
                            pesquisador.nome        = pesquisadorWeb.pesquisador.nome;
                            pesquisador.razaosocial = pesquisadorWeb.pesquisador.razaosocial;
                            dao08.AtualizarPesquisador(pesquisador);
                        }

                        await this.page.Navigation.PushAsync(new PesquisaPage());
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                }
            }
            catch (Exception ex)
            {
                await this.page.DisplayAlert("Erro", ex.Message, "Ok");
            }
            finally
            {
                IsRunning = false;
            }
        }
コード例 #4
0
ファイル: Configuration.cs プロジェクト: dcdaltin/IEB
        protected override void Seed(PlataformaIEB.Models.BancoDeDados context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            Admin admin = new Admin();

            admin.Senha = Crypto.HashPassword("123");
            admin.Email = "[email protected]";
            admin.Nome  = "Administrador";
            context.Admins.Add(admin);


            Medico medico = new Medico();

            medico.CRM           = 123;
            medico.Email         = "[email protected]";
            medico.Nome          = "Médico";
            medico.Senha         = Crypto.HashPassword("123");
            medico.Especialidade = "Neuro";
            medico.Endereco      = "asdfad";
            medico.Instituicao   = " asdfsadfsadf";
            context.Medicos.Add(medico);


            Pesquisador pesquisa = new Pesquisador();

            pesquisa.Email  = "[email protected]";
            pesquisa.Nome   = "Loo";
            pesquisa.Lattes = "http://www.dsdf.com";
            pesquisa.Senha  = Crypto.HashPassword("123");
            context.Pesquisadores.Add(pesquisa);


            Paciente paciente = new Paciente();

            paciente.Nome        = "Paciente";
            paciente.Email       = "[email protected]";
            paciente.Senha       = Crypto.HashPassword("123");
            paciente.Nascimento  = DateTime.Parse("11/02/2009").Date;
            paciente.Responsavel = "João";
            paciente.Sexo        = "Masculino";
            context.Pacientes.Add(paciente);

            Variavel sexo = new Variavel();

            sexo.Nome = "Sexo";
            context.Variaveis.Add(sexo);

            Variavel idade = new Variavel();

            idade.Nome = "Idade";
            context.Variaveis.Add(idade);

            context.SaveChanges();
        }
コード例 #5
0
        public ActionResult Cadastrar()
        {
            Pesquisador Pesquisa = new Pesquisador();

            return(View(Pesquisa));
        }