public LAScopeViewModel()
        {
            rbu           = string.Empty;
            smo           = string.Empty;
            BUList        = new List <SelectListItem>();
            SMOList       = new List <SelectListItem>();
            MasterDataBLL = new LARCA2.Business.Services.MasterDataBLL();
            BUList.Add(new SelectListItem {
                Text = "Select RBU", Value = "0", Selected = true
            });
            SMOList.Add(new SelectListItem {
                Text = "Select SMO", Value = "0", Selected = true
            });

            foreach (LARCA2.Data.DatabaseModels.LARCA20_MasterData md in MasterDataBLL.Todos().Where(x => x.Data == "BU" && x.deleted != true).ToList())
            {
                if (md.DataFin.Length > 0)
                {
                    if (!BUList.Exists(m => m.Text == md.DataFin.ToString()))
                    {
                        BUList.Add(new SelectListItem {
                            Text = md.DataFin, Value = md.DataFin
                        });
                    }
                }
            }

            foreach (LARCA2.Data.DatabaseModels.LARCA20_MasterData md in MasterDataBLL.Todos().Where(x => x.Data == "SMO" && x.deleted != true).ToList())
            {
                if (!SMOList.Exists(m => m.Text == md.DataFin.ToString()) && md.DataFin != "VENEZUELA")
                {
                    SMOList.Add(new SelectListItem {
                        Text = md.DataFin, Value = md.DataFin
                    });
                }
            }
            SMOList.Add(new SelectListItem {
                Text = "LA", Value = "1"
            });

            var user = (LARCA20_Users)HttpContext.Current.Session["Usuario"];

            if (user == null)
            {
                user = new UsuariosBLL().Traer(2);
            }
            Permisos = new LARCA2.Business.Services.UserOwnerBLL().TraerPorIdUsuario(user.Id);
        }
Example #2
0
        /// <summary>
        /// Metodo que se encarga de enviar los PRIMEROS REMINDERS por email
        /// </summary>
        public List <string> EnviarPrimerosRemiders()
        {
            // General Reminders

            /* LARCA2.Data.Services.SmoScopeDAL analisis = new LARCA2.Data.Services.SmoScopeDAL();
             * //var lista_analisis = analisis.Todos();
             *
             * var lista_final_aux = analisis.Todos().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))
             *   {
             *       lista_final.Add(item);
             *   }
             * }*/

            List <string> return_list = new List <string>();

            LARCA2.Business.Services.ApplicationDataBLL repo = new LARCA2.Business.Services.ApplicationDataBLL();
            DateTime siev = DateTime.Now.AddDays(-repo.Todos().First().SmoDays.Value);


            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result            = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_test       = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_aux_smo    = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_aux_bu     = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScopeDetail> lista_tops_level2 = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScopeDetail>();

            //result = result.Where(x => x.deleted == false && x.date >= siev).ToList();
            LARCA2.Business.Services.MasterDataBLL smo_list = new LARCA2.Business.Services.MasterDataBLL();
            LARCA2.Business.Services.MasterDataBLL bu_list  = new LARCA2.Business.Services.MasterDataBLL();
            var toplvl3 = new LARCA2.Business.Services.ApplicationDataBLL().TraerTopLvl3();
            var toplvl2 = new LARCA2.Business.Services.ApplicationDataBLL().TraerTopLvl2();

            decimal volumen;
            decimal vol;

            LARCA2.Business.Services.SMOScopeBLL smoscopebll = new LARCA2.Business.Services.SMOScopeBLL();

            LARCA2.Data.Services.SmoScopeDAL SmoScopeDAL = new LARCA2.Data.Services.SmoScopeDAL();

            foreach (var smo_var in smo_list.Todos().Where(x => x.Data == "SMO").ToList())
            {
                result_aux_smo.AddRange(SmoScopeDAL.Todos().Where(x => x.date >= siev && x.RefIdSMO == smo_var.id && x.clone != true).ToList());
            }

            var result_aux_s = result_aux_smo.GroupBy(p => p.RefIdSMO).ToList();


            var tops_smo = smoscopebll.traer_tops_level2(1);

            foreach (var item in result_aux_s)
            {
                var result_aux = item.Where(i => i.RefIdSMO == item.Key).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]).ToList();

                foreach (var subitem in result_aux)
                {
                    if (tops_smo.Exists(p => p.level == subitem.Key.ToString() && p.smo == item.Key))
                    {
                        volumen = tops_smo.SingleOrDefault(t => t.level == subitem.Key.ToString() && t.smo == item.Key).volumen;



                        vol = 0;
                        int cant = 0;
                        foreach (var item_list in subitem.OrderByDescending(p => p.Volumen).ToList())
                        {
                            cant++;
                            if (cant == 1)
                            {
                                result_test.Add(item_list);
                                vol = vol + Convert.ToDecimal(item_list.Volumen);
                            }

                            else
                            {
                                if ((vol * 100 / volumen <= 80))
                                {
                                    result_test.Add(item_list);
                                    vol = vol + Convert.ToDecimal(item_list.Volumen);
                                }
                            }
                        }
                        result.AddRange(result_test.OrderByDescending(s => s.Volumen).Take(toplvl3).ToList());
                        result_test.Clear();
                    }
                }
            }



            foreach (var bu_var in smo_list.Todos().Where(x => x.Data == "BU").ToList())
            {
                result_aux_bu.AddRange(SmoScopeDAL.Todos().Where(x => x.date >= siev && x.RefIdBU == bu_var.id && x.clone != true).ToList().ToList());
            }

            var result_aux_b = result_aux_bu.GroupBy(p => p.MasterBU.DataFin).ToList();


            var tops_bu = smoscopebll.traer_tops_level2(2);

            foreach (var item in result_aux_b)
            {
                var result_aux = item.Where(i => i.MasterBU.DataFin == item.Key.ToString()).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]).ToList();

                foreach (var subitem in result_aux)
                {
                    if (tops_bu.Exists(p => p.level == subitem.Key.ToString() && p.bu == item.Key.ToString()))
                    {
                        //volumen = tops_bu.SingleOrDefault(t => t.level == subitem.Key.ToString() && t.bu == item.Key.ToString()).volumen;
                        volumen = tops_bu.FirstOrDefault(t => t.level == subitem.Key.ToString() && t.bu == item.Key.ToString()).volumen;



                        vol = 0;
                        int cant = 0;
                        foreach (var item_list in subitem.OrderByDescending(p => p.Volumen).ToList())
                        {
                            cant++;
                            if (cant == 1)
                            {
                                result_test.Add(item_list);
                                vol = vol + Convert.ToDecimal(item_list.Volumen);
                            }

                            else
                            {
                                if ((vol * 100 / volumen <= 80))
                                {
                                    result_test.Add(item_list);
                                    vol = vol + Convert.ToDecimal(item_list.Volumen);
                                }
                            }
                        }
                        result.AddRange(result_test.OrderByDescending(s => s.Volumen).Take(toplvl3).ToList());
                        result_test.Clear();
                    }
                }
            }


            var lista_analisis = result.ToList();

            lista_analisis.Clear();

            foreach (var item in result.ToList())
            {
                if (!lista_analisis.Exists(x => x.RefIdBU == item.RefIdBU && x.RefIdSMO == item.RefIdSMO && x.RefIdRC == item.RefIdRC))
                {
                    lista_analisis.Add(item);
                }
            }

            foreach (var item in lista_analisis)
            {
                if ((item.Problem == "" || item.Problem == null) || (item.ActionPlan == "" || item.ActionPlan == null))
                {
                    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);

                    var    fs      = new FileStream(HttpContext.Current.Server.MapPath("~/AlertTemplates/FirstReminders.htm"), FileMode.Open);
                    var    sr      = new StreamReader(fs);
                    string subject = "LARCA - FIRST REMINDER - PENDING ANALYSIS";
                    var    body    = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();

                    if (permisos_lista2.Count() > 0)
                    {
                        var to = permisos_lista2.First().LARCA20_Users.user_name + "@pg.com";
                        return_list.Add(permisos_lista2.First().LARCA20_Users.user_name + " - " + item.MasterBU.DataFin + " - " + item.MasterSMO.DataFin + " - " + item.MasterLvl.Description);
                        body = body.Replace("[owner]", permisos_lista2.First().LARCA20_Users.user_name);
                        string texto = item.MasterBU.DataFin + " - " + item.MasterSMO.DataFin + " - " + item.MasterLvl.Description;
                        body = body.Replace("[action_plan]", texto);
                        Send(subject, body, to, null);
                    }
                }
            }

            return(return_list);
        }