public ActionResult Export()
        {
            var model = new Larca2.Views.ViewModels.SMOScopeViewModel();

            /*try
             * {
             *  ViewData["MasterRows"] = new SMOScopeBLL().Todos().ToList();
             * }
             * catch
             * {
             *  ViewData["MasterRows"] = new List<LARCA20_SmoScope>();
             * }*/

            //Declaro BLLs e inicializo viewModel
            Larca2.Views.ViewModels.SMOScopeViewModel viewModel    = new Larca2.Views.ViewModels.SMOScopeViewModel();
            LARCA2.Business.Services.UsuariosBLL      repoUsuarios = new LARCA2.Business.Services.UsuariosBLL();
            LARCA2.Business.Services.UserOwnerBLL     uobll        = new LARCA2.Business.Services.UserOwnerBLL();
            LARCA2.Business.Services.SMOScopeBLL      ssbll        = new LARCA2.Business.Services.SMOScopeBLL();


            //Reviso el usuario logueado, sino como prueba traigo al de ID 2
            LARCA2.Data.DatabaseModels.LARCA20_Users user = (LARCA2.Data.DatabaseModels.LARCA20_Users)Session["Usuario"];
            if (user == null)
            {
                user = repoUsuarios.Traer(2);
            }



            //determino el rol del usuario para entender qué filtros y funcionalidades disponer
            LARCA2.Business.Services.RolesBLL         robll = new LARCA2.Business.Services.RolesBLL();
            LARCA2.Business.Services.UsuariosRolesBLL urbll = new LARCA2.Business.Services.UsuariosRolesBLL();
            viewModel.userRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Description;
            viewModel.idRole   = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Id;
            //Obtengo los registros de User Owner con IdUser igual al del usuario logueado
            List <LARCA2.Data.DatabaseModels.LARCA20_User_Owner> luo = uobll.TraerPorIdUsuario(user.Id);


            // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de UserOwner para el usuario logueado
            //    viewModel.SMOList = viewModel.SMOList.Where(x => luo.Exists(y => y.IdSmo.ToString() == x.Value) || x.Value == "0").ToList();
            //    viewModel.BUList = viewModel.BUList.Where(x => luo.Exists(y => y.IdBU.ToString() == x.Value) || x.Value == "0").ToList();

            //Filtro los registros de la tabla SmoScope en función del rol y los permisos para cada uno
            //Aquellos cuyos RefIdSMO, RefIdBU, y RefIdOwner coinciden con los de un registro de la tabla UserOwner para el usuario logueado, permanecen
            //Con que algunos de los campos en cuestion difiera, el registro de SmoScope ya no será mostrado.
            if (viewModel.idRole != 1 && viewModel.idRole != 3)
            {
                List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope> smoscopeact;
                viewModel.RegistrosSMO = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
                foreach (LARCA2.Data.DatabaseModels.LARCA20_User_Owner actualLuo in luo)
                {
                    smoscopeact = ssbll.Filtrar(actualLuo.IdBU.ToString(), actualLuo.IdSmo.ToString(), viewModel.idRole.ToString()).Where(x => x.RefIdOwner == actualLuo.IdOwner).ToList();
                    if (smoscopeact != null)
                    {
                        viewModel.RegistrosSMO.AddRange(smoscopeact);
                    }
                }
            }
            else
            {
                viewModel.RegistrosSMO = ssbll.Filtrar("0", "0", viewModel.idRole.ToString()).ToList();
            }

            viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList();

            var masterData = viewModel.RegistrosSMO.ToList();
            //var masterData = new SMOScopeBLL().Todos().ToList();
            var file = new ExcelCore().GenerarExcelPendingAnalysis("LARCA Pending Analysis", masterData);

            DownloadFile(file);
            return(Content("<script language='javascript' type='text/javascript'>alert('Exported!');document.location = 'Index';</script>"));
        }
        public ActionResult Index()
        {
            var model = new Larca2.Views.ViewModels.SMOScopeViewModel();

            /*try
             * {
             *  ViewData["MasterRows"] = new SMOScopeBLL().Todos().ToList();
             * }
             * catch
             * {
             *  ViewData["MasterRows"] = new List<LARCA20_SmoScope>();
             * }*/

            //Declaro BLLs e inicializo viewModel
            Larca2.Views.ViewModels.SMOScopeViewModel viewModel    = new Larca2.Views.ViewModels.SMOScopeViewModel();
            LARCA2.Business.Services.UsuariosBLL      repoUsuarios = new LARCA2.Business.Services.UsuariosBLL();
            LARCA2.Business.Services.UserOwnerBLL     uobll        = new LARCA2.Business.Services.UserOwnerBLL();
            LARCA2.Business.Services.SMOScopeBLL      ssbll        = new LARCA2.Business.Services.SMOScopeBLL();


            //Reviso el usuario logueado, sino como prueba traigo al de ID 2
            LARCA2.Data.DatabaseModels.LARCA20_Users user = (LARCA2.Data.DatabaseModels.LARCA20_Users)Session["Usuario"];
            if (user == null)
            {
                user = repoUsuarios.Traer(2);
            }



            //determino el rol del usuario para entender qué filtros y funcionalidades disponer
            LARCA2.Business.Services.RolesBLL         robll = new LARCA2.Business.Services.RolesBLL();
            LARCA2.Business.Services.UsuariosRolesBLL urbll = new LARCA2.Business.Services.UsuariosRolesBLL();
            viewModel.userRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Description;
            viewModel.idRole   = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Id;
            //Obtengo los registros de User Owner con IdUser igual al del usuario logueado
            List <LARCA2.Data.DatabaseModels.LARCA20_User_Owner> luo = uobll.TraerPorIdUsuario(user.Id);


            // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de UserOwner para el usuario logueado
            //    viewModel.SMOList = viewModel.SMOList.Where(x => luo.Exists(y => y.IdSmo.ToString() == x.Value) || x.Value == "0").ToList();
            //    viewModel.BUList = viewModel.BUList.Where(x => luo.Exists(y => y.IdBU.ToString() == x.Value) || x.Value == "0").ToList();

            //Filtro los registros de la tabla SmoScope en función del rol y los permisos para cada uno
            //Aquellos cuyos RefIdSMO, RefIdBU, y RefIdOwner coinciden con los de un registro de la tabla UserOwner para el usuario logueado, permanecen
            //Con que algunos de los campos en cuestion difiera, el registro de SmoScope ya no será mostrado.
            if (viewModel.idRole != 1 && viewModel.idRole != 3)
            {
                List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope> smoscopeact;
                viewModel.RegistrosSMO = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
                foreach (LARCA2.Data.DatabaseModels.LARCA20_User_Owner actualLuo in luo)
                {
                    smoscopeact = ssbll.FiltrarPending(actualLuo.IdBU.ToString(), actualLuo.IdSmo.ToString(), viewModel.idRole.ToString()).Where(x => x.RefIdOwner == actualLuo.IdOwner).ToList();
                    if (smoscopeact != null)
                    {
                        viewModel.RegistrosSMO.AddRange(smoscopeact);
                    }
                }
            }
            else
            {
                viewModel.RegistrosSMO = ssbll.FiltrarPending("0", "0", viewModel.idRole.ToString()).ToList();
            }

            viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList();

            /*
             *
             * viewModel.SMOList = viewModel.SMOList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdSMO.ToString() == x.Value) || x.Value == "0").ToList();
             * viewModel.BUList = viewModel.BUList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdBU.ToString() == x.Value) || x.Value == "0").ToList();
             *
             *
             * //LARCA2.Business.Services.MasterDataBLL mdlll = new LARCA2.Business.Services.MasterDataBLL();
             * //List<LARCA2.Data.DatabaseModels.LARCA20_MasterData> allmaster = mdlll.Todos().Exists(z => viewModel.SMOList.Where(x => x.Text == z.DataIni).ToList());
             * // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de SmoScope valido en termino de fecha pero llevaria mas horas
             * //viewModel.SMOList = viewModel.SMOList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdSMO.ToString() == x.Value) || x.Value == "0").ToList();
             * //viewModel.BUList = viewModel.BUList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdBU.ToString() == x.Value) || x.Value == "0").ToList();
             *
             * if (viewModel.RegistrosSMO.Where(x => x.date.Value.Month == (DateTime.Now.Month - 1)).Count() > 0)
             *  viewModel.dropdownMeses.Add(new SelectListItem { Text = "Previous Month", Value = "1", Selected = false });
             *
             * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Where(x => x.date.Value.Month == DateTime.Now.Month).ToList();
             *
             * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList();
             *
             * //traigo aquellos de los cuales el user es el responsable
             * ResponsablesBLL respBLL = new ResponsablesBLL();
             * int idResp = respBLL.TraerPorNombreDeUsuario(user.user_name).Id;
             * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Where(x => x.RefIdResponsable != null && x.RefIdResponsable.Value == idResp).ToList();
             *
             *
             * //Copio la lista a los editables para poder modificar los datos necesarios.
             * viewModel.EditablesSMO = viewModel.RegistrosSMO;
             *
             *
             * LARCA2.Business.Services.ApplicationDataBLL adb = new LARCA2.Business.Services.ApplicationDataBLL();
             * int valMax = adb.Todos()[0].Toplvl4;
             * viewModel.maxClones = new List<int>();
             * for (int i = 0; i < viewModel.EditablesSMO.Count; i++)
             * { viewModel.maxClones.Add(valMax); }
             *
             * ResponsablesBLL repoResponsables = new ResponsablesBLL();
             * viewModel.responsibles = new List<string>();
             * foreach (LARCA2.Data.DatabaseModels.LARCA20_SmoScope itemstr in viewModel.EditablesSMO)
             *
             *
             *  viewModel.responsibles.Add((itemstr.RefIdResponsable == null ? "" : repoResponsables.TraerSuNombreDeUsuario(itemstr.RefIdResponsable.Value)));
             *
             * */
            ViewData["MasterRows"] = viewModel.RegistrosSMO;
            return(View(model));
        }
Ejemplo n.º 3
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);
        }