public void Vencimiento_due_date()
        {
            LARCA2.Data.Services.SmoScopeDAL analisis = new LARCA2.Data.Services.SmoScopeDAL();



            var lista_final_aux = analisis.BruteTodos().OrderByDescending(z => z.SmoScopeID).ToList();
            var lista_final     = lista_final_aux.ToList();

            lista_final.Clear();

            foreach (var item in lista_final_aux)
            {
                if (!lista_final.Exists(x => x.RefIdRC == item.RefIdRC && x.RefIdSMO == item.RefIdSMO && x.RefIdBU == item.RefIdBU && x.RefIdOwner == item.RefIdOwner && x.ActionPlan == item.ActionPlan && x.RefIdResponsable == item.RefIdResponsable))
                {
                    lista_final.Add(item);
                }
            }


            var lista_analisis = lista_final.ToList();

            foreach (var item in lista_analisis)
            {
                if (item.DueDate != null)
                {
                    if (DateTime.Compare(DateTime.Parse(item.DueDate.ToString()), DateTime.Today) < 0 && item.O_C != "C")
                    {
                        var    fs      = new FileStream(HttpContext.Current.Server.MapPath("~/AlertTemplates/ActionPlansFirstReminders.htm"), FileMode.Open);
                        var    sr      = new StreamReader(fs);
                        string subject = "LARCA - FIRST REMINDER - ACTION PLANS";
                        var    to      = item.ResponsableSmo.Responsable_user.user_name + "@pg.com";
                        var    body    = sr.ReadToEnd();
                        sr.Close();
                        fs.Close();
                        body = body.Replace("[owner]", item.ResponsableSmo.Responsable_user.user_name);
                        string string_action = item.DueDate.ToString();
                        if (item.DueDate.ToString().Count() > 0)
                        {
                            string_action = item.ActionPlan + " - " + string_action.Substring(0, 10);
                        }
                        body = body.Replace("[action_plan]", string_action);
                        Send(subject, body, to, null);
                    }
                }
            }
        }
        public void Vencimiento_due_date_escalation()
        {
            //new MailingCore().Vencimiento_due_date_escalation();

            LARCA2.Data.Services.SmoScopeDAL analisis = new LARCA2.Data.Services.SmoScopeDAL();
            var lista_final_aux = analisis.BruteTodos().OrderByDescending(z => z.SmoScopeID).ToList();
            var lista_final     = lista_final_aux.ToList();

            lista_final.Clear();

            foreach (var item in lista_final_aux)
            {
                if (!lista_final.Exists(x => x.RefIdRC == item.RefIdRC && x.RefIdSMO == item.RefIdSMO && x.RefIdBU == item.RefIdBU && x.RefIdOwner == item.RefIdOwner && x.ActionPlan == item.ActionPlan && x.RefIdResponsable == item.RefIdResponsable))
                {
                    lista_final.Add(item);
                }
            }


            var lista_analisis = lista_final.ToList();


            foreach (var item in lista_analisis)
            {
                if (item.DueDate != null)
                {
                    if (DateTime.Compare(DateTime.Parse(item.DueDate.ToString()), DateTime.Today) < 0 && item.O_C != "C")
                    {
                        LARCA2.Data.Services.UserOwnerDAL permisos = new LARCA2.Data.Services.UserOwnerDAL();
                        var    permisos_lista2 = permisos.Todos().Where(x => x.IdOwner == item.RefIdOwner && x.IdSmo == item.RefIdSMO && x.IdBU == item.RefIdBU && x.deleted != true);
                        string cc = "";
                        if (permisos_lista2.Count() > 0)
                        {
                            cc = permisos_lista2.First().LARCA20_Users.user_name + "@pg.com";
                        }

                        var    lista    = new List <string>();
                        string manager  = "";
                        string username = item.ResponsableSmo.Responsable_user.user_name;
                        using (var forest = Forest.GetCurrentForest())
                        {
                            foreach (Domain domain in forest.Domains)
                            {
                                var userdomain = domain.Name.Split(Convert.ToChar("."))[0].ToUpper();

                                List <string> gruposEncontrados = new List <string>();
                                // Creamos un objeto DirectoryEntry para conectarnos al directorio activo
                                DirectoryEntry adsRoot = new DirectoryEntry("LDAP://" + userdomain);
                                // Creamos un objeto DirectorySearcher para hacer una búsqueda en el directorio activo
                                DirectorySearcher adsSearch = new DirectorySearcher(adsRoot);
                                adsSearch.PropertiesToLoad.Add("manager");

                                // Ponemos como filtro que busque el usuario actual
                                adsSearch.Filter = "samAccountName=" + username;

                                SearchResult oResult;
                                // Extraemos la primera coincidencia
                                oResult = adsSearch.FindOne();

                                if (oResult != null)
                                {
                                    manager = oResult.Properties["manager"][0].ToString();
                                    string[] words = manager.Split(',');
                                    manager = words[0];
                                    string[] words2 = manager.Split('=');
                                    manager = words2[1] + "@pg.com";
                                }
                            }
                        }

                        string duedate    = item.DueDate.ToString();
                        string actionplan = item.ActionPlan;
                        new MailingCore().Vencimiento_due_date_escalation(username, duedate, actionplan, cc, manager);
                    }
                }
            }
        }