public bool addDepartmentCompany(int companyCode, int userId, string nameDepartment) { try { if (companyCode != 0) { company_department department = new company_department { client_id = userId, company_id = companyCode, status_id = 2, department_en = nameDepartment, last_update_dt = DateTime.Now, user_id = 1 }; db.company_department.Add(department); db.SaveChanges(); } } catch (System.Data.DataException ex) { logger.Error(ex.ToString()); return(false); } return(true); }
public string delDepartment(SettingsViewModel newSetting) { try { if (newSetting.companyId > 0 && newSetting.userId > 0 && newSetting.data != null) { int count = db.company_department.Where(item => item.company_id == newSetting.companyId && item.status_id == 2).Count(); if (count <= 1) { return("false"); } int idDepartment = Int32.Parse(newSetting.data); company_department oldDepartmnet = db.company_department.Where(item => item.id == idDepartment).FirstOrDefault(); if (oldDepartmnet != null) { oldDepartmnet.status_id = 1; oldDepartmnet.user_id = newSetting.userId; oldDepartmnet.last_update_dt = DateTime.Now; db.SaveChanges(); } } else { return("false"); } } catch (Exception e) { return("false"); } return("true"); }
public string addDepartment(SettingsViewModel newSetting) { string id = null; try { if (newSetting.companyId > 0 && newSetting.userId > 0 && newSetting.data != null) { company_department oldDepartment = db.company_department.Where(item => item.department_en.Trim().ToLower() == newSetting.data.Trim().ToLower() && item.company_id == newSetting.companyId).FirstOrDefault(); if (oldDepartment != null) { oldDepartment.status_id = 2; db.SaveChanges(); id = oldDepartment.id.ToString(); } else { company_department department = new company_department(); department.user_id = newSetting.userId; department.client_id = 1; department.company_id = newSetting.companyId; department.department_en = newSetting.data; department.status_id = 2; department.last_update_dt = DateTime.Now; department = db.company_department.Add(department); db.SaveChanges(); id = department.id.ToString(); } } else { return("false"); } } catch (Exception e) { return("false"); } return(id); }
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()); }