public static Response <Bundles.AnsattInfo> FinnAnsatt(int personIdHRM) { var client = new WebClient { Credentials = new NetworkCredential(Username, Password) }; client.Encoding = Encoding.UTF8; try { var response = client.DownloadString($"{hrm_URL}/id/{personIdHRM}"); var doc = new XmlDocument(); doc.LoadXml(response); var fornavn = doc.SelectSingleNode(@"//person/givenName").InnerText; var etternavn = doc.SelectSingleNode(@"//person/familyName").InnerText; var ansattnr = doc.SelectSingleNode(@"//person/employments/employment/employeeId").InnerText; var ledereResult = FinnLedereForAnsatt(fornavn, etternavn, ansattnr); if (ledereResult.Success) { var bundle = new Bundles.AnsattInfo { AnsattNr = ansattnr, Fornavn = fornavn, Etternavn = etternavn, Lederliste = ledereResult.Get(), }; return(new Response <Bundles.AnsattInfo>(bundle, "OK", Codes.Code.OK)); } else { return(new Response <Bundles.AnsattInfo>(Bundles.AnsattInfo.Empty, ledereResult.Message, ledereResult.Code)); } } catch (NullReferenceException) { return(new Response <Bundles.AnsattInfo>(Bundles.AnsattInfo.Empty, StringConstants.ERROR_SSN_NOT_FOUND_HRM, Codes.Code.ERROR)); } catch (WebException wex) { return(new Response <Bundles.AnsattInfo>(Bundles.AnsattInfo.Empty, wex.Message, Codes.Code.ERROR)); } }
public static Response <Bundles.AnsattInfo> GetTestUser(string ansattnr, string userAD) { try { var user = Testbrukere.Where(b => b.AnsattNr.Equals(ansattnr)).First(); user.Lederliste = Superbrukere.ToArray(); user.IsTest = true; return(new Response <Bundles.AnsattInfo>(user, "OK", Codes.Code.OK)); } catch { var bundle = new Bundles.AnsattInfo { AnsattNr = "-1", Fornavn = "These aren't the droids you're looking for", Lederliste = new Bundles.LederInfo[] { new Bundles.LederInfo { AD = userAD } }, IsTest = true }; return(new Response <Bundles.AnsattInfo>(bundle, "OK", Codes.Code.OK)); } }
public static Response <Bundles.LederInfo[]> FinnLedereForAnsatt(Bundles.AnsattInfo ansatt) { return(FinnLedereForAnsatt(ansatt.Fornavn, ansatt.Etternavn, ansatt.AnsattNr)); }
public static Response <List <AvtaleInfo> > HentAnsattStillingsInfo(Bundles.AnsattInfo ansatt, string innloggetAD) { var client = new WebClient { Credentials = new NetworkCredential(Username, Password) }; client.Encoding = Encoding.UTF8; var resultList = new List <AvtaleInfo>(); // liste med alle stillinger som innlogget bruker er leder for denne personen try { var response = client.DownloadString($"{hrm_URL}/name/firstname/{Uri.EscapeDataString(ansatt.Fornavn)}/lastname/{Uri.EscapeDataString(ansatt.Etternavn)}"); var doc = new XmlDocument(); doc.LoadXml(response); var persons = doc.SelectNodes(@"//personsXML/person"); foreach (XmlNode person in persons) { var employments = person.SelectNodes(@"./employments/employment"); foreach (XmlNode employment in employments) { var employeeId = employment.SelectSingleNode("./employeeId").InnerText; if (ansatt.AnsattNr.Equals(employeeId)) { // hent alle stillinger til den ansatte var positions = employment.SelectNodes(@"./positions/position"); foreach (XmlNode position in positions) { // finn nærmeste leder for denne stillingen var managerIdHRM = position.SelectSingleNode(@"./chart/unit/manager").Attributes["id"].Value; var lederHRM = FinnLeder(managerIdHRM); if (lederHRM.Success) { // sjekk at innlogget bruker er nærmeste leder for denne stillingen //if (innloggetAD.ToUpper().Equals(lederHRM.Get().AD.ToUpper())) { var stillingTittel = position.SelectSingleNode(@"./positionInfo/positionCode").Attributes["name"].Value; var stillingKode = position.SelectSingleNode(@"./positionInfo/positionCode").Attributes["positionCode"].Value; var fastAnsatt = position.SelectSingleNode(@"./positionInfo/positionType").Attributes["value"].Value; var prosent = position.SelectSingleNode(@"./positionPercentage").InnerText; var ssn = person.SelectSingleNode(@"./ssn").InnerText; var enhetNavn = position.SelectSingleNode(@"./chart/unit").Attributes["name"].Value; var arbeidssted = position.SelectSingleNode(@"./chart").Attributes["name"].Value; var enhetDim3 = position.SelectSingleNode(@"./costCentres/dimension3").Attributes["name"].Value; //enhetNavn = enhetNavn.Substring(0, 1).ToUpper() + enhetNavn.ToLower().Substring(1, enhetNavn.Length - 1); var lonn = position.SelectSingleNode(@"./salaryInfo/yearlySalary").InnerText; var timerPrUke = position.SelectSingleNode(@"./weeklyHours").InnerText; var fast = position.SelectSingleNode(@"./positionInfo/positionType ").Attributes["value"].Value; if (fast.ToUpper().Equals("F")) { var ai = new AvtaleInfo() { Navn = ansatt.Navn, Personnr = ssn, Arbeidssted = enhetNavn + " " + enhetDim3, TittelStilling = stillingKode + " " + stillingTittel, Lonn = lonn, Prosent = prosent, TimerPrUke = timerPrUke }; resultList.Add(ai); } else { var sluttdato = position.SelectSingleNode(@"./positionEndDate").InnerText; var ai = new AvtaleInfoMidlertidlig() { Navn = ansatt.Navn, Personnr = ssn, Arbeidssted = arbeidssted,//enhetNavn + " " + enhetDim3, TittelStilling = stillingKode + " " + stillingTittel, Lonn = lonn, Hjemmel = fast.ToLower(), Prosent = prosent, Sluttdato = sluttdato }; resultList.Add(ai); } } } else { return(new Response <List <AvtaleInfo> >(null, "Nærmeste leder ble ikke funnet i HRM", Codes.Code.ERROR)); } } } } } return(new Response <List <AvtaleInfo> >(resultList, "OK", Codes.Code.OK)); } catch (Exception e) { return(new Response <List <AvtaleInfo> >(null, e.Message, Codes.Code.ERROR)); } }
public static Response <string> FinnPersonnrForAnsatt(Bundles.AnsattInfo ansatt) { return(FinnPersonnrForAnsatt(ansatt.Fornavn, ansatt.Etternavn, ansatt.AnsattNr)); }
private static Response <Bundles.AnsattInfo> GetADBruker(string ansattNr) { try { using (DirectoryEntry searchRoot = new DirectoryEntry("", Username, Password)) { using (DirectorySearcher dSearcher = new DirectorySearcher(searchRoot)) { dSearcher.PropertiesToLoad.Add("employeeID"); dSearcher.PropertiesToLoad.Add("givenName"); dSearcher.PropertiesToLoad.Add("sn"); dSearcher.PropertiesToLoad.Add("mail"); dSearcher.ReferralChasing = ReferralChasingOption.All; dSearcher.SearchScope = SearchScope.Subtree; // filtrerer ut deaktiverte brukere // https://forums.asp.net/t/1172159.aspx?using+C+to+access+active+directory+and+pull+active+users+ 21.05.2019 dSearcher.Filter = $"(&(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(employeeID={ansattNr}))"; var resultAD = dSearcher.FindOne(); if (resultAD != null) { var value = resultAD.GetDirectoryEntry(); var lederResult = GetInfoForLeder(Convert.ToInt32(ansattNr)); if (lederResult.Success) { var ansattEpost = ""; if (value.Properties["mail"] != null) { var mailValue = value.Properties["mail"].Value; if (mailValue != null) { ansattEpost = value.Properties["mail"].Value.ToString(); } } var bundle = new Bundles.AnsattInfo { AnsattNr = ansattNr, Fornavn = value.Properties["givenName"].Value.ToString(), Etternavn = value.Properties["sn"].Value.ToString(), AnsattEPost = ansattEpost, Lederliste = new Bundles.LederInfo[] { lederResult.Get() } }; return(new Response <Bundles.AnsattInfo>(bundle, "OK", Codes.Code.OK)); } else { var bundle = new Bundles.AnsattInfo { AnsattNr = ansattNr, Fornavn = value.Properties["givenName"].Value.ToString(), Etternavn = value.Properties["sn"].Value.ToString(), //AnsattEPost = value.Properties["mail"].Value.ToString(), Lederliste = HRMHelper.FinnLedereForAnsatt(value.Properties["givenName"].Value.ToString(), value.Properties["sn"].Value.ToString(), ansattNr).Get(), }; return(new Response <Bundles.AnsattInfo>(bundle, lederResult.Message, Codes.Code.OK)); } } else { return(new Response <Bundles.AnsattInfo>(Bundles.AnsattInfo.Empty, string.Format(StringConstants.WARN_ID_NOT_FOUND_AD, ansattNr), Codes.Code.WARNING)); } } } } catch (Exception e) { return(new Response <Bundles.AnsattInfo>(Bundles.AnsattInfo.Empty, e.Message, Codes.Code.ERROR)); } }