Exemple #1
0
        public ActionResult Register(Users usuario)
        {
            ModelState.Clear();
            ViewBag.Message = "Empty";
            try
            {
                if (ModelState.IsValid)
                {
                    int perfil = 0;
                    Int32.TryParse(Session["perfil"].ToString(), out perfil);
                    if (Session["email"] != null && perfil == 1)
                    {
                        if (DBcontext.AgregarUsuario(usuario))
                        {
                            String Recipient = usuario.email;
                            usuario.idUser = DBcontext.Mostrar(Recipient);
                            String Subject = "Registro PIACT";
                            String Body    = "<body>Gracias por registarse a PIACT " + "<br>"
                                             + "Por favor haga click en el " + "<br>" +
                                             "siguiente enlace para <a href='" + "http://piactcr.azurewebsites.net/Login/Confirmar/" + usuario.idUser.ToString() + "'>"
                                             + "registrarse</a></body>";
                            String From         = "*****@*****.**";
                            String FromPassword = "******";
                            String Action       = "";

                            try
                            {
                                int res = NetworkContext.Instance.sendEmail(From, FromPassword, Recipient, Subject, Body);
                                //Case successful
                                if (res == 1)
                                {
                                    ViewBag.Message    = usuario.name + "name" + "Registro Correcto!";
                                    Session["mensaje"] = "correcto";
                                    Action             = "correcto";
                                }
                                //Case failed conection
                                else if (res == 0)
                                {
                                    Session["mensaje"] = "incorrecto";
                                    Action             = "Incorrecto";
                                }
                            }
                            catch (System.Net.Mail.SmtpException ex)
                            {
                                Session["mensaje"] = "incorrecto";
                                Action             = "Incorrecto";
                                DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), "IP", "BETA");
                            }
                            catch (Exception ex)
                            {
                                Session["mensaje"] = "incorrecto";
                                Action             = "Incorrecto";
                                DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), "IP", "BETA");
                            }
                            String location = "Class: " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                            location += "-Method: " + System.Reflection.MethodBase.GetCurrentMethod().Name;
                            TrackLog(location, Action);

                            return(View());
                        }
                        else
                        {
                            ModelState.AddModelError("email", "Email ya existe!");
                            return(View());
                        }
                    }
                    return(RedirectToAction("Index", "Login"));
                }



                return(View());
            }
            catch (Exception ex)
            {
                Session["mensaje"] = "incorrecto";
                DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), "IP", "BETA");
                return(View());
            }
        }