Ejemplo n.º 1
0
        public JsonResult Crear([Bind(Include = "investigator_id,user_id,first_name,second_name,last_name,second_last_name,gender_id,mobile_phone," +
                                                "birthdate_text,user_email,user_pass,document_type_id,doc_nro,nationality_id,contract_name,phone,address,user_pass2,institution_id," +
                                                "investigation_group_id,program_id,interest_areas,address_country_id,department_id,address_municipality_id,commissions,educational_institution_id,education_level_id,CVLAC")] InvestigatorViewModel pViewModel)
        {
            // TODO: Add insert logic here

            if (pViewModel == null)
            {
                return(Json(new
                {
                    message_error = "Datos inavalidos",
                    status = "0",
                }));
            }
            pViewModel.investigator_id = 0;

            pViewModel.user_id_created = 0;
            pViewModel.birthdate       = DateTime.ParseExact(pViewModel.birthdate_text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            var user_pass = pViewModel.user_pass;

            pViewModel.user_pass    = Helper.Encripta(pViewModel.user_pass);
            pViewModel.user_name    = pViewModel.first_name + " " + pViewModel.second_name + " " + pViewModel.last_name + " " + pViewModel.second_last_name;
            pViewModel.user_name    = pViewModel.user_name.Replace("  ", " ").Replace("  ", " ");
            pViewModel.contact_name = pViewModel.user_name;
            string user_code = Guid.NewGuid().ToString();

            pViewModel.user_code_activate = user_code;
            UserBL oBL = new UserBL();

            var user_id = oBL.AgregarInvestigador(pViewModel);

            SendEmailNotificationBL oSendEmailNotificationBL = new SendEmailNotificationBL();

            NotificationGeneralAccountViewModel oNotification = new NotificationGeneralAccountViewModel();


            oNotification.url_activar_cuenta = ConfigurationManager.AppSettings["site.url"] + "/Account/Activar/?code=" + user_code;
            oNotification.url_home           = ConfigurationManager.AppSettings["site.url"];

            oNotification.url_politicas  = ConfigurationManager.AppSettings["site.url.politicas"];
            oNotification.url_contacto   = ConfigurationManager.AppSettings["site.url.contacto"];
            oNotification.url_privacidad = ConfigurationManager.AppSettings["site.url.privacidad"];
            oNotification.name           = pViewModel.contact_name;
            oNotification.to             = pViewModel.user_email;
            oSendEmailNotificationBL.EnviarNotificacionActivarCuenta(oNotification);

            return(Json(new
            {
                // this is what datatables wants sending back
                status = "1",
            }));
        }