Example #1
0
        public ActionResult EditUsuarioPlayer(int id)
        {
            //Listar todos Usuários
            GPCLib.Models.PlayerUsuarioModels  objPlayerUsuario = new GPCLib.Models.PlayerUsuarioModels();
            List <GPCLib.Models.UsuarioModels> lstUsuarios      = new List <GPCLib.Models.UsuarioModels>();

            GPCLib.DataAccess.Player  daPlayer  = new GPCLib.DataAccess.Player();
            GPCLib.DataAccess.Usuario daUsuario = new GPCLib.DataAccess.Usuario();

            objPlayerUsuario = daPlayer.ObterPlayerUsuario(id);
            lstUsuarios      = daUsuario.ListarUsuarios();

            objPlayerUsuario.UsuarioCombo = new GPCLib.Models.UsuarioCombo();

            lstUsuarios.Insert(0, new GPCLib.Models.UsuarioModels()
            {
                Id = "", UserName = "******"
            });
            objPlayerUsuario.UsuarioCombo.SelectOptions = lstUsuarios.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.UserName
            }).ToList();


            if (objPlayerUsuario.Usuario != null)
            {
                objPlayerUsuario.UsuarioCombo.SelectedOption = objPlayerUsuario.Usuario.Id;
            }



            return(View(objPlayerUsuario));
        }
Example #2
0
        public ActionResult GravarUsuariosPlayer(GPCLib.Models.PlayerUsuarioModels model)
        {
            GPCLib.DataAccess.Guilda daGuilda = new GPCLib.DataAccess.Guilda();
            daGuilda.AtualizarPlayerUsuario(model);

            //Se já tiver Usuario x Player já grava a Guilda no ASPNETUSERs.
            GPCLib.DataAccess.Player          daPlayer      = new GPCLib.DataAccess.Player();
            GPCLib.Models.PlayerUsuarioModels playerUsuario = daPlayer.ObterPlayerUsuario(model.Player.Id);

            if (playerUsuario.Usuario != null)
            {
                //Atualiza o codigo da Guilda
                GPCLib.DataAccess.Usuario daUsuario = new GPCLib.DataAccess.Usuario();
                daUsuario.AtualizarCodGuilda(model.Guilda.Id, playerUsuario.Usuario.Id);
            }


            TempData["Success"] = "Gravado com sucesso";
            return(RedirectToAction("EditUsuarioPlayer", new { id = model.Player.Id }));
        }
Example #3
0
        public ActionResult GravarUsuariosGuilda(GPCLib.Models.GuildaPlayersModels model)
        {
            GPCLib.DataAccess.Guilda          daGuilda  = new GPCLib.DataAccess.Guilda();
            GPCLib.DataAccess.Player          daPlayer  = new GPCLib.DataAccess.Player();
            GPCLib.DataAccess.Usuario         daUsuario = new GPCLib.DataAccess.Usuario();
            GPCLib.Models.PlayerUsuarioModels playerUsuario;

            //Antes de excluir selecioar todos os usuários
            GPCLib.Models.GuildaPlayersModels usuariosOld = daGuilda.ListarUsuariosGuilda(model.Guilda.Id);

            //Excluir membros da GUild e inserir novamente.
            daGuilda.ExcluirMembrosGuilda(model.Guilda.Id);

            GPCLib.Models.GuildaPlayer objPlayer;

            foreach (int item in model.GuildaUsuarioListBox.idPlayer)
            {
                objPlayer          = new GPCLib.Models.GuildaPlayer();
                objPlayer.Ativo    = 1;
                objPlayer.idGuilda = model.Guilda.Id;
                objPlayer.idPlayer = item;
                if (usuariosOld.Players.Select(x => x.Id == item).Count() > 0)
                {
                    objPlayer.idUsuario = usuariosOld.Players.First(x => x.Id == item).Usuario.Id;
                }

                daGuilda.InserirMembroGuilda(objPlayer);

                //Se já tiver Usuario x Player já grava a Guilda no ASPNETUSERs.
                playerUsuario = daPlayer.ObterPlayerUsuario(item);
                if (playerUsuario.Usuario != null)
                {
                    //Atualiza o codigo da Guilda
                    daUsuario.AtualizarCodGuilda(model.Guilda.Id, playerUsuario.Usuario.Id);
                }
            }
            TempData["Success"] = "Gravado com sucesso";
            return(RedirectToAction("GuildaPlayer", new { id = model.Guilda.Id }));
        }
Example #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, IdGuilda = long.Parse(model.Guildas.SelectedOption)
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    try
                    {
                        //Liga Usuario x Player

                        GPCLib.DataAccess.Player          daPlayer      = new GPCLib.DataAccess.Player();
                        GPCLib.Models.PlayerUsuarioModels playerUsuario = daPlayer.ObterPlayerUsuario(int.Parse(Request.Form[5]));

                        playerUsuario.UsuarioCombo = new GPCLib.Models.UsuarioCombo();
                        playerUsuario.UsuarioCombo.SelectedOption = user.Id;

                        GPCLib.DataAccess.Guilda daGuilda = new GPCLib.DataAccess.Guilda();
                        daGuilda.AtualizarPlayerUsuario(playerUsuario);
                    }
                    catch (Exception)
                    {
                        //nao é para dar pau nesta etapa. Se nao der certo, segue a vida.
                    }


                    /*
                     * EMAIL CONFIRMAÇÂO
                     *
                     * */

                    ApplicationDbContext context = new ApplicationDbContext();
                    var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

                    UserManager.AddToRole(user.Id, "Membros");


                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);


                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link

                    var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("GPC");
                    UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider <ApplicationUser>(provider.Create("EmailConfirmation"));
                    var token = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = token }, protocol: Request.Url.Scheme);
                    UserManager.EmailService = new EmailService();

                    //StringBuilder Mensagem = new StringBuilder();
                    //Mensagem.AppendLine("Ólá! ");
                    //Mensagem.AppendLine("Recebemos uma requisição de cadastro no GPC - Guilda Painel de Controle. ");
                    //Mensagem.AppendLine("Para confirmar seu cadastro acesse o link abaixo.  ");
                    string emailc = "<head></head><body> <div style=\"background-color:#fff;margin:0 auto 0 auto;padding:30px 0 30px 0;color:#4f565d;font-size:13px;line-height:20px;font-family:'Helvetica Neue'," +
                                    "Arial,sans-serif;text-align:left;\"> <center> <table style=\"width:550px;text-align:center\"> <tbody> <tr> <td style=\"padding:0 0 20px 0;border-bottom:1px solid #e9edee;\">" +
                                    "<h1> <a href=\"http://www.demonorange.party\" style=\"display:block; margin:0 auto;\" target=\"_blank\"> GPC - Guilda Painel de Controle </a></h1> </td> </tr> <tr> " +
                                    "<td colspan=\"2\" style=\"padding:30px 0;\"> <p style=\"color:#1d2227;line-height:28px;font-size:22px;margin:12px 10px 20px 10px;font-weight:400;\">" +
                                    "Olá Recebemos uma requisição de cadastro no GPC - Guilda Painel de Controle.</p> <p style=\"margin:0 10px 10px 10px;padding:0;\">Para confirmar seu cadastro acesse o link abaixo." +
                                    "</p> <p> <a style=\"display:inline-block;text-decoration:none;padding:15px 20px;background-color:#2baaed;border:1px solid #2baaed;border-radius:3px;color:#FFF;font-weight:bold;\" " +
                                    "href=\"" + callbackUrl + "\" target=\"_blank\">Confirmar Cadastro</a> </p> </td> </tr> <tr> <td colspan=\"2\" style=\"padding:30px 0 0 0;border-top:1px solid #e9edee;color:#9b9fa5\"> " +
                                    "Se tiver dúvidas por favor entrar em contato com <a style=\"color:#666d74;text-decoration:none;\" href=\"mailto:[email protected]\" target=\"_blank\">[email protected]</a> " +
                                    "</td> </tr> </tbody> </table> </center> </div> </body>";


                    await UserManager.SendEmailAsync(user.Id, "GPC - Confirmação de Cadastro", emailc);

                    // Uncomment to debug locally
                    // TempData["ViewBagLink"] = callbackUrl;

                    ViewBag.Message = "Um email de confirmação foi enviado a seu email de cadastro. Por favor acesse o link recebido para validação do seu cadastro. ";

                    return(View("Info"));
                    //return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }