Esempio n. 1
0
        public async Task <List <Usuario> > GetUsuario(string id)
        {
            //Declaro un objeto list que depende la clase Usuario
            List <Usuario> usuario    = new List <Usuario>();
            var            appUsuario = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == id);

            usuarioRole = await _usuarioRole.GetRole(_userManager, _roleManager, id);

            UsuarioEmpresaController uec = new UsuarioEmpresaController(_context);

            //saco el idempresa

            usuario.Add(new Usuario()
            {
                Id                   = appUsuario.Id,
                UserName             = appUsuario.UserName,
                PhoneNumber          = appUsuario.PhoneNumber,
                Email                = appUsuario.Email,
                Role                 = usuarioRole[0].Text,
                RoleId               = usuarioRole[0].Value,
                AccessFailedCount    = appUsuario.AccessFailedCount,
                ConcurrencyStamp     = appUsuario.ConcurrencyStamp,
                EmailConfirmed       = appUsuario.EmailConfirmed,
                LockoutEnabled       = appUsuario.LockoutEnabled,
                LockoutEnd           = appUsuario.LockoutEnd,
                NormalizedEmail      = appUsuario.NormalizedEmail,
                NormalizedUserName   = appUsuario.NormalizedUserName,
                PasswordHash         = appUsuario.PasswordHash,
                PhoneNumberConfirmed = appUsuario.PhoneNumberConfirmed,
                SecurityStamp        = appUsuario.SecurityStamp,
                TwoFactorEnabled     = appUsuario.TwoFactorEnabled,
            });
            return(usuario);
        }
Esempio n. 2
0
        public async Task <String> CreateUsuario(string email,
                                                 string phoneNumber, string passwordHash,
                                                 string selectRole, string selectEmpresa, ApplicationUser applicationUser)
        {
            var resp = "";

            applicationUser = new ApplicationUser
            {
                UserName    = email,
                Email       = email,
                PhoneNumber = phoneNumber
            };
            var result = await _userManager.CreateAsync(applicationUser, passwordHash);

            if (result.Succeeded)
            {
                await _userManager.AddToRoleAsync(applicationUser, selectRole);


                //añado la empresa
                UsuarioEmpresa ue = new UsuarioEmpresa();
                ue.Id        = applicationUser.Id;
                ue.EmpresaId = int.Parse(selectEmpresa);
                UsuarioEmpresaController uec = new UsuarioEmpresaController(_context);
                try
                {
                    uec.Create(ue);
                }
                catch (Exception ex)
                {
                    resp = "NoSave";
                }

                resp = "Save";
            }
            else
            {
                resp = "NoSave";
            }
            return(resp);
        }