Beispiel #1
0
        public void merge(ReportViewModel rvm, CompanyModel companyModel, ReportModel reportModel, ReportViewModel model)
        {
            this.confidentialLevelInt = model.incident_anonymity_id;

            if (model.incident_anonymity_id != 1)
            {
                name    = model.userName;
                surname = model.userLastName;
                email   = model.userEmail;
            }

            if (companyModel != null && rvm != null)
            {
                CountryModel country         = new CountryModel();
                country      selectedCountry = country.loadById(model.reportFrom);
                reportingFrom = selectedCountry.country_nm;
            }
            List <anonymity> list_anon = companyModel.GetAnonymities(companyModel._company.id, 0);

            if (list_anon != null)
            {
                var       temp = from n in list_anon where n.id == model.incident_anonymity_id select n;
                anonymity anon = temp.FirstOrDefault();
                confidentialLevel = anon.anonymity_company_en;
            }

            List <company_relationship> relationship = reportModel.getCustomRelationshipCompany(companyModel._company.id);

            if (relationship != null)
            {
                var temp = from n in relationship where n.id == model.reporterTypeDetail select n;
                company_relationship rel = temp.FirstOrDefault();
                if (rel != null)
                {
                    reportedAs = rel.relationship_en;
                }
            }

            var locations = companyModel.Locations(companyModel._company.id).ToList();

            if (locations != null)
            {
                var temp = from n in locations where n.id == model.locationsOfIncident select n.location_en;
                if (temp != null)
                {
                    incidentLocation = String.Join(", ", temp);
                }
            }

            List <company_department> depActive   = companyModel.CompanyDepartmentsActive(companyModel._company.id).ToList();
            List <string>             departments = model.departments;
            List <int> departmentsInt             = new List <int>();

            foreach (string item in departments)
            {
                try
                {
                    int temp = 0;
                    Int32.TryParse(item, out temp);
                    if (temp > 0)
                    {
                        departmentsInt.Add(temp);
                    }
                    else if (temp == 0)
                    {
                        departmentsInt.Add(0);
                    }
                }
                catch (Exception) { }
            }
            if (depActive != null && depActive.Count > 0 && departments != null && departments.Count > 0)
            {
                var temp = from n in depActive
                           join entry in departmentsInt
                           on n.id equals entry
                           select n.department_en;
                foreach (string item in temp)
                {
                    affectedDepartments = String.Join(", ", item);
                }
                if (affectedDepartments == null)
                {
                    affectedDepartments = GlobalRes.notListed;
                }
            }

            List <management_know> managament = companyModel.getManagamentKnow();

            if (managament != null && model.managamentKnowId > 0)
            {
                var temp = from n in managament
                           where n.id == model.managamentKnowId
                           select n.text_en;
                managamentKnow = temp.FirstOrDefault();
            }
            List <reported_outside> reported_outside = companyModel.getReportedOutside();

            if (model.reported_outside_id > 0 && reported_outside != null)
            {
                var temp = from n in reported_outside where n.id == model.reported_outside_id select n;
                outOrganization = temp.FirstOrDefault().description_en;
            }

            if (model.isUrgent == 0)
            {
                isCaseUrgent = GlobalRes.No;
            }
            else
            {
                isCaseUrgent = GlobalRes.Yes;
            }

            if (reportModel.isCustomIncidentTypes(model.currentCompanyId))
            {
                /*custom types*/
                List <company_secondary_type> company_secondary_type = reportModel.getCompanySecondaryType(model.currentCompanyId);
                foreach (int item in model.whatHappened)
                {
                    if (item != 0)
                    {
                        var something = company_secondary_type.Where(m => m.id == item).FirstOrDefault();
                        IncidentType += something.secondary_type_en + ", ";
                    }
                    else
                    {
                        IncidentType += GlobalRes.Other + ", ";
                    }
                }
            }
            else
            {
                /*default*/
                List <secondary_type_mandatory> secondary_type_mandatory = reportModel.getSecondaryTypeMandatory();
                foreach (int item in model.whatHappened)
                {
                    if (item != 0)
                    {
                        var something = secondary_type_mandatory.Where(m => m.id == item).FirstOrDefault();
                        IncidentType += something.secondary_type_en + ", ";
                    }
                    else
                    {
                        IncidentType += GlobalRes.Other + ", ";
                    }
                }
            }
            IncidentType = IncidentType.Remove(IncidentType.Length - 2);

            IncidentDate = model.dateIncidentHappened.ToShortDateString();
            switch (model.isOnGoing)
            {
            case 1:
                incidentOngoing = GlobalRes.No;
                break;

            case 2:
                incidentOngoing = GlobalRes.Yes;
                break;

            case 3:
                incidentOngoing = GlobalRes.NotSureUp;
                break;
            }



            List <injury_damage> injuryDamage = companyModel.GetInjuryDamages().ToList();

            if (injuryDamage != null && injuryDamage.Count > 0 && model.incidentResultReport > 0)
            {
                var temp = from n in injuryDamage where n.id == model.incidentResultReport select n;
                incidentResult = temp.FirstOrDefault().text_en;
            }


            incidentDescription = model.describeHappened;

            if (model.files.Count > 0)
            {
                HttpFileCollectionBase files = model.files;
                var fileItem = files["attachDocuments"];
                if (fileItem != null)
                {
                    attachFiles = fileItem.FileName;
                }
            }
            this.report_by_myself = model.report_by_myself == true ? GlobalRes.Myself : GlobalRes.SomeoneElse;

            this.personName     = new List <string>();
            this.personLastName = new List <string>();
            this.personTitle    = new List <string>();
            this.personRole     = new List <string>();
            var personRoles = new List <int>();

            if (model.personName != null)
            {
                this.personName     = model.personName.ToList();
                this.personLastName = model.personLastName.ToList();
                this.personTitle    = model.personTitle.ToList();
                personRoles         = model.personRole.ToList();
            }


            List <role_in_report> roleInReport = ReportModel.getRoleInReport();

            for (int i = 0; i < personRoles.Count; i++)
            {
                role_in_report nameRole = roleInReport.Where(m => m.id == personRoles[i]).FirstOrDefault();
                if (nameRole != null)
                {
                    personRole.Add(nameRole.role_en);
                }
            }
        }
Beispiel #2
0
        public ActionResult New(string companyCode)
        {
            ///    private readonly UserModel userModel = UserModel.inst;
            ///

            ///    reportModel = new ReportModel();
            ///     userModel = new UserModel();
            ////   companyModel = new CompanyModel();
            ModelState.Clear();

            int id = 0;

            if (companyCode != null)
            {
                id = companyModel.GetCompanyByCode(companyCode);
                if (id == 0)
                {
                    return(RedirectToAction("Index", "Index"));

                    // zmachit kod v baze ne nashl
                    ViewBag.currentCompanySubmitted = companyCode;
                    ViewBag.currentCompany          = "";
                    id = 1;
                }
            }
            else
            {
                return(RedirectToAction("Index", "Index"));
                // esli u nas net company_code, znachit reportera nado redirect na index/company_selector
            }

            if (id > 0)
            {
                #region EC-CC Viewbag
                ViewBag.is_cc = is_cc;
                string cc_ext = "";
                if (is_cc)
                {
                    cc_ext = "_cc";
                }
                ViewBag.cc_extension = cc_ext;
                #endregion


                //    if(id == 1 ) - nado pokazat message reporteru iz psd
                //         reporter - file report no company
                ////screen - http://invis.io/QK2VGQNAW
                ////PSD - http://invis.io/a/G91HFKB8NJ4ZV


                CompanyModel model          = new CompanyModel(id);
                company      currentCompany = model.GetById(id);
                //company currentCompany = CompanyModel.inst.GetById(id);
                ViewBag.currentCompanyId = currentCompany.id;

                /*caseInformation*/

                if (reportModel.isCustomIncidentTypes(ViewBag.currentCompanyId))
                {
                    /*custom types*/
                    ViewBag.secondary_type_mandatory = reportModel.getCompanySecondaryType(ViewBag.currentCompanyId);
                    ViewBag.CustomSecondaryType      = true;
                }
                else
                {
                    /*default*/
                    ViewBag.secondary_type_mandatory = reportModel.getSecondaryTypeMandatory().Where(t => t.status_id == 2).ToList();
                    ViewBag.CustomSecondaryType      = false;
                }

                //ViewBag.currentCompanySubmitted = CompanyModel.inst.GetById(id).company_nm;
                ViewBag.currentCompanySubmitted = currentCompany.company_nm;
                ViewBag.currentCompany          = currentCompany.company_nm;
                //ViewBag.country = currentCompany.address.country.country_nm;
                ViewBag.locations   = HtmlDataHelper.MakeSelect(companyModel.Locations(id).Where(t => t.status_id == 2).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("location")));
                ViewBag.managament  = companyModel.getManagamentKnow();
                ViewBag.frequencies = HtmlDataHelper.MakeSelect(companyModel.getFrequencies(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("description")));
                List <country> arr = companyModel.getCountries();
                ViewBag.countries            = HtmlDataHelper.MakeSelect(arr, item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.country_nm.ToString()));
                ViewBag.countriesDescription = arr;
                ViewBag.reportedOutsides     = companyModel.getReportedOutside();
                List <role_in_report> roleInReport         = db.role_in_report.ToList();
                List <SelectListItem> selectedRoleInReport = new List <SelectListItem>();
                /*put other*/
                SelectListItem temp = new SelectListItem {
                    Text = App_LocalResources.GlobalRes.Other, Value = "0", Selected = true
                };
                selectedRoleInReport.Add(temp);
                foreach (var item in roleInReport)
                {
                    SelectListItem role = new SelectListItem {
                        Text = item.role_en, Value = item.id.ToString()
                    };
                    selectedRoleInReport.Add(role);
                }
                ViewBag.selectedRoleInReport = selectedRoleInReport;
                List <anonymity> list_anon = companyModel.GetAnonymities(id, 0);
                foreach (anonymity _anon in list_anon)
                {
                    _anon.anonymity_company_en = string.Format(_anon.anonymity_company_en, currentCompany.company_nm);
                    _anon.anonymity_ds_en      = string.Format(_anon.anonymity_ds_en, currentCompany.company_nm);
                    _anon.anonymity_en         = string.Format(_anon.anonymity_en, currentCompany.company_nm);
                }
                ViewBag.anonimity = list_anon;
                /*Relationship to company*/
                List <company_relationship> relationship = reportModel.getCustomRelationshipCompany(ViewBag.currentCompanyId);
                if (relationship.Count > 0)
                {
                    //loadCustom
                    //get other
                    //company_relationship other = companyModel.getOtherRelationship();
                    //relationship.Add(other);
                    ViewBag.relationship = relationship;
                }
                else
                {
                    ViewBag.relationship = companyModel.getRelationships();
                }


                //  ViewBag.departments = HtmlDataHelper.MakeSelect(currentCompany.company_department.ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("department")));
                var departmentsActive = companyModel.CompanyDepartmentsActive(id).ToList();

                company_department empty = new company_department();
                empty.department_en = App_LocalResources.GlobalRes.notListed;
                empty.id            = 0;
                departmentsActive.Add(empty);
                ViewBag.departments = HtmlDataHelper.MakeSelect(departmentsActive, item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("department")));


                ViewBag.locationsOfIncident = HtmlDataHelper.MakeSelect(companyModel.Locations(id).Where(t => t.status_id == 2).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("location")));

                // ViewBag.departments2 = currentCompany.company_department.ToList();
                ViewBag.departments2 = companyModel.CompanyDepartmentsActive(id).ToList();

                ViewBag.locationsOfIncident2 = companyModel.Locations(id).Where(t => t.status_id == 2).ToList();

                ViewBag.injury_damage = companyModel.GetInjuryDamages().ToList();

                ViewBag.supervisingMediators    = companyModel.AllSupervisingMediators(id, true);    // HtmlDataHelper.MakeSelect(companyModel.AllSupervisingMediators(id, true).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.last_nm));
                ViewBag.nonSupervisingMediators = companyModel.AllNonSupervisingMediators(id, true); // HtmlDataHelper.MakeSelect(companyModel.AllSupervisingMediators(id, true).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.last_nm));

                // company logo
                string companyLogo = currentCompany.path_en;
                string path        = System.IO.Directory.GetCurrentDirectory();
                if (!System.IO.Directory.Exists(path + companyLogo))
                {
                    ViewBag.companylogo = companyLogo;
                }
                else
                {
                    ViewBag.companyLogo = null;
                }
                //
            }
            else
            {
                // esli u nas net company_code, znachit reportera nado redirect na index/company_selector
                return(RedirectToAction("index", "Index"));
            }

            return(View());
        }