Esempio n. 1
0
        public IActionResult ViewAll(int idFormat,
                                     [FromServices] IOrganigramaModelFactory organigramModelFactory,
                                     [FromServices] IRepository <EmployeeFormat> formatRepository,
                                     [FromServices] INotificationModelFactory notificationModelFactory,
                                     [FromServices] IHttpContextAccessor _httpContextAccessor)
        {
            FormatApproverPendingModel model = new FormatApproverPendingModel();
            var formats = notificationModelFactory.NotificaticonsItems;


            var format = formatRepository.GetElement(idFormat);

            if (format != null)
            {
                var employee = organigramModelFactory.GetEmployeeData(format.EmployeeId);
                if (employee != null)
                {
                    model.FormatEmployee.Area         = employee.Area;
                    model.FormatEmployee.JobCenter    = employee.JobCenter;
                    model.FormatEmployee.Departamento = employee.Departamento;
                    model.FormatEmployee.Name         = $"{employee.GeneralInfo.FirstName} {employee.GeneralInfo.LastName} {employee.GeneralInfo.LastName2}";
                    model.FormatEmployee.PicturePath  = employee.GeneralInfo.Picture;
                }

                var formatDetail = formats.Where(u => u.Id.Equals(idFormat));
                if (formatDetail.Any())
                {
                    model.FormatDetail = formatDetail.FirstOrDefault();
                }
            }

            return(View(model));
        }
Esempio n. 2
0
        public IActionResult ViewDetail(int idFormat,
                                        [FromServices] IOrganigramaModelFactory organigramModelFactory,
                                        [FromServices] IRepository <EmployeeFormat> formatRepository,
                                        [FromServices] INotificationModelFactory notificationModelFactory,
                                        [FromServices] IRepository <FormatApprover> formatApprover,
                                        [FromServices] IHttpContextAccessor _httpContextAccessor)
        {
            FormatApproverPendingModel model = new FormatApproverPendingModel();
            var formats   = notificationModelFactory.NotificaticonsItems;
            var employees = organigramModelFactory.GetAllData();

            var format = formatRepository.GetElement(idFormat);

            if (format != null)
            {
                var employee = organigramModelFactory.GetEmployeeData(format.EmployeeId);
                if (employee != null)
                {
                    model.FormatEmployee.Area         = employee.Area;
                    model.FormatEmployee.JobCenter    = employee.JobCenter;
                    model.FormatEmployee.Departamento = employee.Departamento;
                    model.FormatEmployee.JobTitle     = employee.GeneralInfo.JobTitle;
                    model.FormatEmployee.Name         = $"{employee.GeneralInfo.FirstName} {employee.GeneralInfo.LastName} {employee.GeneralInfo.LastName2}";
                    model.FormatEmployee.PicturePath  = employee.GeneralInfo.Picture;
                }


                var formatDetail = formats.Where(u => u.Id.Equals(idFormat));
                if (formatDetail.Any())
                {
                    model.FormatDetail = formatDetail.FirstOrDefault();
                    var employeeSust = organigramModelFactory.GetEmployeeData(format.EmployeeSubstitute);
                    model.FormatDetail.EmployeeSustitution = $"{employeeSust.GeneralInfo.FirstName} {employeeSust.GeneralInfo.LastName} {employeeSust.GeneralInfo.LastName2}";

                    List <FormatApprover> apprs = new List <FormatApprover>();

                    //Approbador Global
                    formatApprover.SearhItemsFor(i => i.Area.Equals(string.Empty) &&
                                                 i.Centro.Equals(string.Empty) && i.Departamento.Equals(string.Empty)).ToList().ForEach(f =>
                    {
                        if (string.IsNullOrEmpty(f.ApproverListEmployees))
                        {
                            apprs.Add(f);
                        }
                        else
                        {
                            var listEmp = JsonConvert.DeserializeObject <List <string> >(f.ApproverListEmployees);
                            if (listEmp != null && listEmp.Any())
                            {
                                listEmp.ForEach(emp =>
                                {
                                    if (emp.Equals(format.EmployeeId))
                                    {
                                        apprs.Add(f);
                                    }
                                });
                            }
                        }
                    });


                    //Aprobador Area
                    apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());


                    //Aprobador Centro
                    apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area) &&
                                                                i.Centro.Equals(model.FormatEmployee.JobCenter)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());


                    //Aprobador Depto
                    apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area) &&
                                                                i.Centro.Equals(model.FormatEmployee.JobCenter) && i.Departamento.Equals(model.FormatEmployee.Departamento)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());



                    if (apprs.Any())
                    {
                        apprs.ForEach((a) =>
                        {
                            var approName = employees.Employess.Where(d => d.RowId.ToString().ToLower().Equals(a.RowGuid.ToString().ToLower())).FirstOrDefault();
                            if (approName != null)
                            {
                                model.Approvers.Add(new ForrmatApproverWorkflow()
                                {
                                    Id    = a.Id,
                                    RowId = a.RowGuid,
                                    Name  = approName.Name
                                });
                            }
                        });
                    }
                }
                else
                {
                    model.FormatDetail = notificationModelFactory.AllNotificaticonsItems.Where(d => d.Id.Equals(format.Id)).FirstOrDefault();
                    var employeeSust = organigramModelFactory.GetEmployeeData(format.EmployeeSubstitute);
                    model.FormatDetail.EmployeeSustitution = $"{employeeSust.GeneralInfo.FirstName} {employeeSust.GeneralInfo.LastName} {employeeSust.GeneralInfo.LastName2}";

                    if (!string.IsNullOrEmpty(format.ApprovalWorkFlow))
                    {
                        List <FormatApprover> apprs = new List <FormatApprover>();

                        //Approbador Global
                        formatApprover.SearhItemsFor(i => i.Area.Equals(string.Empty) &&
                                                     i.Centro.Equals(string.Empty) && i.Departamento.Equals(string.Empty)).ToList().ForEach(f =>
                        {
                            if (string.IsNullOrEmpty(f.ApproverListEmployees))
                            {
                                apprs.Add(f);
                            }
                            else
                            {
                                var listEmp = JsonConvert.DeserializeObject <List <string> >(f.ApproverListEmployees);
                                if (listEmp != null && listEmp.Any())
                                {
                                    listEmp.ForEach(emp =>
                                    {
                                        if (emp.Equals(format.EmployeeId))
                                        {
                                            apprs.Add(f);
                                        }
                                    });
                                }
                            }
                        });

                        //Aprobador Area
                        apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());


                        //Aprobador Centro
                        apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area) &&
                                                                    i.Centro.Equals(model.FormatEmployee.JobCenter)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());


                        //Aprobador Depto
                        apprs.AddRange(formatApprover.SearhItemsFor(i => i.Area.Equals(model.FormatEmployee.Area) &&
                                                                    i.Centro.Equals(model.FormatEmployee.JobCenter) && i.Departamento.Equals(model.FormatEmployee.Departamento)).Where(p => (apprs).All(p2 => p2.RowGuid != p.RowGuid)).ToList());


                        var apps = JsonConvert.DeserializeObject <List <ForrmatApproverWorkflow> >(format.ApprovalWorkFlow);

                        apprs.ForEach(h =>
                        {
                            var t = apps.Where(k => k.RowId.Equals(h.RowGuid));
                            if (!t.Any())
                            {
                                var approName = employees.Employess.Where(d => d.RowId.ToString().ToLower().Equals(h.RowGuid.ToString().ToLower())).FirstOrDefault();
                                if (approName != null)
                                {
                                    model.Approvers.Add(new ForrmatApproverWorkflow()
                                    {
                                        Id    = h.Id,
                                        RowId = h.RowGuid,
                                        Name  = approName.Name
                                    });
                                }
                            }
                        });


                        model.Approvers.AddRange(apps);
                    }
                }
            }

            return(View(model));
        }