internal static List <string> GetOfficeNames(string countryName, SNAPContext db) { try { List <string> officeNames = new List <string>(); Country country = db.Countries.Where(x => x.Name == countryName).FirstOrDefault(); if (country == null) { return(officeNames); } officeNames.Add(String.Format("{0}, Home Office", country.ISO3)); officeNames.Add(String.Format("{0}, Client Site", country.ISO3)); foreach (Office office in db.Offices.Where(x => x.Country.Name == countryName)) { officeNames.Add(office.Name); } return(officeNames); } catch (Exception) { return(new List <string>()); } }
internal static NewHire EmployeeLookup(string workerId, string hireType, SNAPContext db) { try { NewHire employee = new NewHire(); dynamic workdayEmployee = PowerShell.RunScript("Get-WorkdayEmployee", new { WorkerID = workerId }); employee.WorkerID = workerId; employee.HireType = hireType; if (employee.HireType == "Employee Conversion") { employee.IsConversion = true; } switch (workdayEmployee.Worker_Type as string) { case "Contractor": employee.IsContingent = true; employee.WorkerType = workdayEmployee.Worker_Type; break; case "Regular": employee.WorkerType = "Employee-Regular"; employee.O365License = "E3, EMS"; employee.OracleRequired = true; break; default: employee.WorkerType = workdayEmployee.Worker_Type; employee.O365License = "E3, EMS"; employee.OracleRequired = true; break; } employee.FirstName = workdayEmployee.First_Name; employee.LastName = workdayEmployee.Last_Name; employee.EmailAddress = workdayEmployee.Email; employee.StartDate = Convert.ToDateTime(workdayEmployee.Hire_Date); employee.Title = workdayEmployee.Title; employee.Department = workdayEmployee.Department; employee.ManagersEmail = workdayEmployee.Manager_Email; employee.Office = workdayEmployee.Office_Location; employee.Country = workdayEmployee.Country; if (db.Countries.Any(x => x.Name == employee.Country) == false) { employee.Country = "United States of America"; } employee.SetServiceDate(); return(employee); } catch (Exception) { return(null); } }
internal void Decommission(SNAPContext db) { Active = false; EndDate = DateTime.Today; MailExternalCompany(); db.Entry(this).State = EntityState.Modified; db.SaveChanges(); }
internal static ServiceRequest LastDay(LastDay lastDay, SNAPContext db) { try { ServiceRequest serviceRequest = new ServiceRequest(); serviceRequest.Name = lastDay.Name; serviceRequest.Title = lastDay.Title; serviceRequest.Department = lastDay.Department; serviceRequest.Manager = lastDay.Manager; serviceRequest.Office = lastDay.Office; serviceRequest.Notes = String.Format("{0}\n{1}", lastDay.PublicNotes, lastDay.PrivateNotes); Country country = db.Countries.Where(x => x.ISO2 == lastDay.Country).First(); string workerType = "#FTE"; if (lastDay.IsContingent == true) { workerType = "#CONT"; } string region = country.ISO2; if (lastDay.ITaaS == true) { region = "ITAAS"; } serviceRequest.Subject = String.Format("AM.{0} SNAP Last Day | {1} | {2} | {3}", region, serviceRequest.Name, Convert.ToDateTime(lastDay.EndDate).ToString("MMMM dd, yyyy"), workerType); if (lastDay.Immediate == true) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Immediate"); } if (db.Offices.Any(o => o.Name == lastDay.Office) == false) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Remote"); } return(serviceRequest); } catch (Exception) { return(null); } }
internal static string PasswordReset(ADUser adUser, IPrincipal user, SNAPContext db) { try { ChangeLog changeLog = new ChangeLog(); changeLog.Timestamp = DateTime.Now; changeLog.Event = "Password Reset"; changeLog.Description = String.Format("Password reset for {0}", adUser.EmailAddress); changeLog.SubmittedBy = user.Identity.Name; db.ChangeLogs.Add(changeLog); db.SaveChanges(); return(changeLog.Description); } catch (Exception) { return(null); } }
internal static string ContactAccount(ContactAccount contactAccount, SNAPContext db) { try { ChangeLog changeLog = new ChangeLog(); changeLog.Timestamp = DateTime.Now; changeLog.Event = "Contact Account Created"; changeLog.Description = String.Format("{0} created", contactAccount.EmailAddress); changeLog.SubmittedBy = contactAccount.Creator; db.ChangeLogs.Add(changeLog); db.SaveChanges(); return(changeLog.Description); } catch (Exception) { return(null); } }
internal static ServiceRequest NewHire(NewHire newHire, SNAPContext db) { try { ServiceRequest serviceRequest = new ServiceRequest(); serviceRequest.Name = String.Format("{0} {1}", newHire.FirstName, newHire.LastName); serviceRequest.Title = newHire.Title; serviceRequest.Department = newHire.Department; serviceRequest.Manager = newHire.Manager; serviceRequest.Office = newHire.Office; serviceRequest.Notes = String.Format("{0}\n{1}", newHire.PublicNotes, newHire.PrivateNotes); Country country = db.Countries.Where(x => x.Name == newHire.Country).First(); string workerType = "#CONT"; if (newHire.WorkerType == "Employee-Regular") { workerType = "#FTE"; } string region = country.ISO2; if (newHire.ITaaS == true) { region = "ITAAS"; } serviceRequest.Subject = String.Format("AM.{0} SNAP New Hire | {1} | {2} | {3}", region, serviceRequest.Name, newHire.StartDate.ToString("MMMM dd, yyyy"), workerType); if (newHire.HireType == "Employee Transfer") { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Transfer"); } switch (newHire.O365License) { case "E1": serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#E1"); break; case "E1/Windows": serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Computer"); serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#E1"); break; case "E3, EMS": serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Computer"); serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#E3"); break; default: break; } if (newHire.PhoneRequired == true) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Phone"); } if (db.Offices.Any(o => o.Name == newHire.Office) == false) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Remote"); } if (newHire.Department.Contains("Managed Services") && newHire.Title.Contains("Engineer")) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#GSC"); } if (newHire.Department.Contains("Solutions") || newHire.Department.Contains("PreSales")) { serviceRequest.Subject = String.Format("{0} {1}", serviceRequest.Subject, "#Solutions"); } return(serviceRequest); } catch (Exception) { return(null); } }
internal static string DistributionGroup(DistributionGroup distributionGroup, SNAPContext db) { try { ChangeLog changeLog = new ChangeLog(); changeLog.Timestamp = DateTime.Now; changeLog.Event = "Distribution Group Created"; changeLog.Description = String.Format("@{0} created", distributionGroup.Alias); changeLog.SubmittedBy = distributionGroup.Creator; db.ChangeLogs.Add(changeLog); db.SaveChanges(); return(changeLog.Description); } catch (Exception) { return(null); } }