public async Task <IActionResult> AddClaims(Guid id, IntegranteViewModel integranteViewModel)
        {
            IdentityUser usr = await _userManager.FindByIdAsync(id.ToString());

            if (String.IsNullOrEmpty(integranteViewModel.ManipulateUserClaimsType) &
                String.IsNullOrEmpty(integranteViewModel.ManipulateUserClaimsType))
            {
                return(RedirectToAction(nameof(Index)));
            }

            string claimType  = integranteViewModel.ManipulateUserClaimsType.ToUpper();
            string claimValue = integranteViewModel.ManipulateUserClaimsValue.ToUpper();


            Claim claimUsr = new Claim(claimType, claimValue);
            await _userManager.AddClaimAsync(usr, claimUsr);

            var integrante = await _integranteRepository.ObterPorId(id);

            ViewData["Normalized"] = integrante.Nome.ToUpper();

            return(RedirectToAction("EditClaims", new RouteValueDictionary(
                                        new { controller = "Integrantes", action = "EditClaims", id })));
        }
        public async Task <IActionResult> Edit(Guid id, IntegranteViewModel integrante)
        {
            if (id != integrante.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var imgPrefixo  = id + "_Foto";
                var imgPrefixo2 = id + "_Ass";

                var integranteImgs = await _integranteRepository.ObterPorId(id);

                integrante.ImgFoto = integranteImgs.ImgFoto;
                integrante.ImgSign = integranteImgs.ImgSign;

                if (integrante.ImgFotoUpload == null)
                {
                    goto Jfoto;
                }
                if (!await UploadArquivoImgFoto(integrante.ImgFotoUpload, imgPrefixo))
                {
                    return(View(integrante));
                }

                integrante.ImgFoto =
                    imgPrefixo + ".JPG";
Jfoto:
                if (integrante.ImgSignUpload == null)
                {
                    goto Jsign;
                }
                if (!await UploadArquivoSignFoto(integrante.ImgSignUpload, imgPrefixo2))
                {
                    return(View(integrante));
                }
                integrante.ImgSign =
                    imgPrefixo2 + ".JPG";

Jsign:
                try
                {
                    integrante.Admissao = DateTime.Now;

                    UpperIntegranteVm(integrante);



                    var integranteMapped = _mapper.Map <Integrante>(integrante);
                    await _integranteRepository.Atualizar(integranteMapped);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IntegranteExists(integrante.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(integrante));
        }
Beispiel #3
0
        public ActionResult AdicionarIntegrante(IntegranteViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(User.Identity.GetUserId <int>());

                int Id;
                if (int.TryParse(Util.Decrypt(model.GrupoId), out Id))
                {
                    Grupo grupo = db.Grupo.Find(Id);

                    if (string.IsNullOrEmpty(Util.IsPremium(grupo)))
                    {
                        return(RedirectToAction("PremiumPropaganda", "Premium"));
                    }
                    else if (Util.IsPremium(grupo) != TaskQuest.PagSeguro.Status.Ativa && grupo.Users.Count >= 10)
                    {
                        return(RedirectToAction("PremiumAguardandoPagamento", "Premium"));
                    }

                    if (!User.Identity.IsAdm(grupo.Id))
                    {
                        TempData["Classe"] = "yellow-alert";
                        TempData["Alerta"] = "Você não pode executar esta ação";
                        return(View("Redirect", new RedirectViewModel("/Grupo/Index", Util.Encrypt(grupo.Id.ToString()))));
                    }

                    var aux2 = db.Users.Where(q => q.Email == model.Email);
                    if (aux2.Any())
                    {
                        User usuario = aux2.First();

                        if (!grupo.Users.Any(q => q == usuario))
                        {
                            grupo.Users.Add(usuario);
                            db.SaveChanges();

                            TempData["Classe"] = "green-alert";
                            TempData["Alerta"] = "Integrante adicionado com sucesso";
                            return(View("Redirect", new RedirectViewModel("/Grupo/Index", Util.Encrypt(grupo.Id.ToString()))));
                        }
                    }
                    else
                    {
                        TempData["Classe"] = "yellow-alert";
                        TempData["Alerta"] = "Usuário não cadastrado";

                        (new EmailService()).SendAsync(new IdentityMessage()
                        {
                            Destination = model.Email,
                            Subject     = "Uma equipe quer você como colaborador!",
                            Body        = string.Format(@"
                                <table width=621 border='1' cellpadding='0' cellspacing='0'>
	                                <tr height=160 style='background-color: #106494;'>
		                                <td style='text-align: center; color:white; font-size: 100px;'><span style='font-family: Calibri;'>Task</span><span style='font-family: Impact;'>Quest</span></td>
	                                </tr>
	                                <tr height=300>
		                                <td style='text-align: center;'>
			                                <span style='font-size: 50px; font-family: Impact;'>Convite de Participação</span>
			                                <br>
			                                <br>
			                                <span style='color: #929496; font-family: Calibri; font-size: 20px;'>Você foi convidado por {0},<br> para participar da equipe {1},<br> no sistema TaskQuest.</span style='font-family:Calibri; font-size: 20px;'><br><br><span style='font-size: 20px;'><a href='{2}' style='text-decoration: none; color: #106494;'>Comece Já!</a></span>
		                                </td>
	                                </tr>
                                </table>
                            ", user.Nome + " " + user.Sobrenome, grupo.Nome, Url.Action("Index", "Home"))
                        });

                        return(View("Redirect", new RedirectViewModel("/Grupo/Index", Util.Encrypt(grupo.Id.ToString()))));
                    }
                }
            }
            TempData["Classe"] = "yellow-alert";
            TempData["Alerta"] = "Formulário inválido";
            return(RedirectToAction("Inicio", "Home"));
        }