Пример #1
0
        public FileContentResult ShowLegalEntityOwnersGraph(int?legalEntityFK, string color, int?dpi)
        {
            ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);

            ILegalEntityOwnersRepository legalEntityOwnersRepository = new LegalEntityOwnersRepository(db);
            IPhysicalEntitiesRepository  physicalEntitiesRepository  = new PhysicalEntitiesRepository(db);

            List <LegalEntityOwner>       filteredCoList         = new List <LegalEntityOwner>();
            IQueryable <LegalEntityOwner> legalEntityOwnersTable = legalEntityOwnersRepository.GetValid();

            if (legalEntityFK != null)
            {
                List <LegalEntityOwner> coList = new List <LegalEntityOwner>();
                coList = legalEntityOwnersRepository.GetFirstLegalEntityOwnersForLegalEntity((int)legalEntityFK).ToList();

                foreach (var co in coList)
                {
                    LegalEntityOwnerView.Fill(filteredCoList, legalEntityOwnersTable.ToList(), co);
                }

                legalEntityOwnersTable = filteredCoList.AsQueryable();
            }

            IQueryable <LegalEntityOwnerView> legalEntityOwners = LegalEntityOwnerView.GetLegalEntityOwnerView(legalEntityOwnersTable,
                                                                                                               physicalEntitiesRepository.GetValid(),
                                                                                                               legalEntitiesRepository.GetValid());

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

            foreach (LegalEntityOwnerView item in legalEntityOwners)
            {
                graphElements.Add(item.OwnerFK.ToString() + "[label=\"" + item.OwnerName + "\", shape=ci, fontsize=12, fontname=arial, labelloc=t, style=filled, fillcolor=\"white\", width=1.5]");

                if (legalEntityFK == item.LegalEntityFK)
                {
                    graphElements.Add(item.LegalEntityFK.ToString() + "[label=\"" + item.LegalEntityName + "\", shape=box, fontsize=12, fontname=arial, labelloc=t, style=filled, fontcolor=\"white\", color=\"black\", width=1.5]");
                }
                else
                {
                    graphElements.Add(item.LegalEntityFK.ToString() + "[label=\"" + item.LegalEntityName + "\", shape=box, fontsize=12, fontname=arial, labelloc=t, style=filled, fillcolor=\"white\", width=1.5]");
                }

                graphElements.Add(item.OwnerFK.ToString() + "->" + item.LegalEntityFK.ToString());
            }

            string graph = @"digraph Graphviz {";

            graph += "[bgcolor=\"" + color + "\", dpi=\"" + dpi + "\"],";
            graph += string.Join(", ", graphElements.ToArray());
            graph += "}";

            graph = graph.ConvertNonASCIICharacters();

            byte[] imageByte   = imageByte = Graphviz.RenderImage(graph, "dot", "png");;
            string contentType = "image/png";

            return(File(imageByte, contentType));
        }
Пример #2
0
        public ActionResult Edit(AssessmentsView assessmentView, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                IAssessmentsRepository assessmentsRepository = new AssessmentsRepository(db);
                Assessment             assessment            = assessmentsRepository.GetAssessmentByPK((int)assessmentView.AssessmentPK);

                IAssessmentAnswersRepository assessmentAnswersRepository = new AssessmentAnswersRepository(db);

                // Delete old values
                assessmentAnswersRepository.Delete(a => a.AssessmentFK == assessment.AssessmentPK);

                // Add new values
                IAssessmentGroupsRepository    assessmentGroupsRepository    = new AssessmentGroupsRepository(db);
                IAssessmentQuestionsRepository assessmentQuestionsRepository = new AssessmentQuestionsRepository(db);
                IAssessmentTypesRepository     assessmentTypesRepository     = new AssessmentTypesRepository(db);

                assessmentView.AssessmentsTypesView = AssessmentsView.FillQuiz(assessmentTypesRepository.GetValid(), assessmentGroupsRepository, assessmentQuestionsRepository, form);

                // Fetching answered type
                AssessmentsTypeView atw = assessmentView.AssessmentsTypesView.Where(a => a.AssessmentType.AssessmentTypePK == assessmentView.AssessmentTypeFK).First();

                List <AssessmentAnswers> assessmentAnswers = AssessmentAnswerView.ExtractQuizAnswers(atw, assessment.AssessmentPK);

                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                LegalEntity legalEntity             = legalEntitiesRepository.GetLegalEntityByPK((int)assessmentView.LegalEntityFK);
                bool        activityHighRisky       = legalEntity.Activity.HighRisk != null && (bool)legalEntity.Activity.HighRisk ? true : false;
                bool        activityLowRisky        = legalEntity.Activity.LowRisk != null && (bool)legalEntity.Activity.LowRisk ? true : false;
                bool        headquarterCountryRisky = legalEntity.Country.Risk != null && (bool)legalEntity.Country.Risk ? true : false;

                IRisksRepository risksRepository = new RisksRepository(db);
                if (activityHighRisky || headquarterCountryRisky) // check explicitly if related legalEntity activity is high risk
                {
                    assessmentView.RiskFK = risksRepository.GetRiskByName("Visok").RiskPK;
                }
                else if (activityLowRisky) // check explicitly if related legalEntity activity is low risk
                {
                    assessmentView.RiskFK = risksRepository.GetRiskByName("Nizak").RiskPK;
                }
                else // run assesment quiz
                {
                    ILegalEntityOwnersRepository  legalEntityOwnersRepository = new LegalEntityOwnersRepository(db);
                    IQueryable <LegalEntityOwner> legalEntityOwnersTable      = legalEntityOwnersRepository.GetValid();
                    ICountriesRepository          countriesRepository         = new CountriesRepository(db);

                    IActivitiesRepository activitiesRepository = new ActivitiesRepository(db);

                    List <LegalEntityOwner> coList = legalEntityOwnersRepository.GetFirstLegalEntityOwnersForLegalEntity((int)assessmentView.LegalEntityFK).ToList();

                    legalEntityOwnersTable = LegalEntityOwnerView.GetLegalEntityOwnersForLegalEntity(Convert.ToInt32(assessmentView.LegalEntityFK), coList, legalEntityOwnersTable);

                    IQueryable <LegalEntity> legalEntityView = LegalEntityOwnerView.GetRelatedLegalEntities(legalEntityOwnersTable, legalEntitiesRepository.GetValid(), countriesRepository.GetValid(), activitiesRepository.GetValid());

                    // check owners risks
                    bool ownersResidenceCountryRisky = false;
                    bool ownersActivitiesHighlyRisky = false;
                    bool ownersActivitiesLowRisky    = false;

                    if (legalEntityView.Count() > 0)
                    {
                        if (legalEntityView.ToList().TrueForAll(le => le.Country.Risk == null || (le.Country.Risk != null && (bool)le.Country.Risk != true)) == false)
                        {
                            ownersResidenceCountryRisky = true;
                        }

                        if (legalEntityView.ToList().TrueForAll(le => le.Activity == null || (le.Activity.HighRisk == null || (le.Activity.HighRisk != null && (bool)le.Activity.HighRisk != true))) == false)
                        {
                            ownersActivitiesHighlyRisky = true;
                        }

                        if (legalEntityView.ToList().TrueForAll(le => le.Activity == null || (le.Activity.LowRisk == null || (le.Activity.LowRisk != null && (bool)le.Activity.LowRisk != true))) == false)
                        {
                            ownersActivitiesLowRisky = true;
                        }
                    }

                    // check form
                    bool allAnswersYes = false;
                    bool allAnswersNo  = false;
                    bool mixedAnswers  = false;

                    if (assessmentAnswers.TrueForAll(aa => aa.AssessmentAnswer != null && (bool)aa.AssessmentAnswer == true))
                    {
                        allAnswersYes = true;
                    }

                    if (assessmentAnswers.TrueForAll(aa => aa.AssessmentAnswer != null && (bool)aa.AssessmentAnswer == false))
                    {
                        allAnswersNo = true;
                    }

                    if (allAnswersYes == false && allAnswersNo == false)
                    {
                        mixedAnswers = true;
                    }

                    // check general conditions
                    if (ownersActivitiesLowRisky)
                    {
                        assessmentView.RiskFK = risksRepository.GetRiskByName("Nizak").RiskPK;
                    }
                    else if (allAnswersYes || ownersResidenceCountryRisky || ownersActivitiesHighlyRisky)
                    {
                        assessmentView.RiskFK = risksRepository.GetRiskByName("Visok").RiskPK;
                    }
                    else if (allAnswersNo || mixedAnswers)
                    {
                        assessmentView.RiskFK = risksRepository.GetRiskByName("Srednji").RiskPK;
                    }
                }

                if (assessmentAnswers.Count() > 0)
                {
                    assessmentAnswersRepository.AddAll(assessmentAnswers);
                    assessmentAnswersRepository.SaveChanges();
                }

                assessmentView.ConvertTo(assessmentView, assessment);
                assessmentsRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", assessment.AssessmentPK);

                return(RedirectToAction("Index", "Assessment"));
            }
            else
            {
                IAssessmentGroupsRepository    assessmentGroupsRepository    = new AssessmentGroupsRepository(db);
                IAssessmentQuestionsRepository assessmentQuestionsRepository = new AssessmentQuestionsRepository(db);

                //Assessment types ddl
                IAssessmentTypesRepository assessmentTypesRepository = new AssessmentTypesRepository(db);
                assessmentView.AssessmentTypes = new SelectList(assessmentTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "AssessmentTypePK", "Name");

                //legalEntities ddl
                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                assessmentView.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().ToList(), "LegalEntityPK", "Name");

                assessmentView.AssessmentsTypesView = AssessmentsView.FillQuiz(assessmentTypesRepository.GetValid(), assessmentGroupsRepository, assessmentQuestionsRepository, form);

                return(View(assessmentView));
            }
        }