Commit 6c2ff73c authored by Dan Brydges's avatar Dan Brydges

A few updates

parent 8642b707
......@@ -39,7 +39,7 @@
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=oracle_user;Password=oracle_user_password;Data Source=oracle" />
<add name="Entities" connectionString="metadata=res://*/EMPLOYEE_PER.csdl|res://*/EMPLOYEE_PER.ssdl|res://*/EMPLOYEE_PER.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;DATA SOURCE=odatst;PASSWORD=yuckof;USER ID=STARHR&quot;" providerName="System.Data.EntityClient" />
<add name="Entities" connectionString="metadata=res://*/EMPLOYEE_PER.csdl|res://*/EMPLOYEE_PER.ssdl|res://*/EMPLOYEE_PER.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;DATA SOURCE=odatst;PASSWORD=<PASSWORD></PASSWORD>;USER ID=STARHR&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.serviceModel>
<bindings>
......
......@@ -294,11 +294,12 @@ namespace UBWToStarHR
// select=personId
// filter=status eq 'N'
string id = "ITADMIN";
string pwd = "Hotpepperz9";
string pwd = "<PASSWORD>";
/*string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/query/employees?companyId=VU&select=personId&filter=status%20eq%20'N'&orderBy=personId"; */
string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/query/employees?companyId=VU&select=personId&filter=status%20eq%20'N'&orderBy=personId";
/*string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/query/employees?companyId=VU&select=personId&filter=status%20eq%20'N'&orderBy=personId"; */
/* string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/query/employees?companyId=VU&select=personId&filter=personId%20eq%20'357795'&orderBy=personId"; */
string url = "https://ubw.unit4cloud.com/ca_viu_prod_webapi/v1/query/employees?companyId=VU&select=personId&filter=status%20eq%20'N'&orderBy=personId";
var client = new RestClient(url);
client.Authenticator = new HttpBasicAuthenticator(id, pwd);
......@@ -313,9 +314,10 @@ namespace UBWToStarHR
public string GetEmployeeJSON(long pid)
{
string id = "ITADMIN";
string pwd = "Hotpepperz9";
string pwd = "<PASSWORD>";
//string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/employees/" + pid.ToString();
string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/objects/resources?companyId=VU&filter=personId%20eq%20'" + pid.ToString() + "'";
/* string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/objects/resources?companyId=VU&filter=personId%20eq%20'" + pid.ToString() + "'"; */
string url = "https://ubw.unit4cloud.com/ca_viu_prod_webapi/v1/objects/resources?companyId=VU&filter=personId%20eq%20'" + pid.ToString() + "'";
var client = new RestClient(url);
client.Authenticator = new HttpBasicAuthenticator(id, pwd);
var request = new RestRequest();
......@@ -328,8 +330,9 @@ namespace UBWToStarHR
public string GetEmployeeDetailJSON(long pid)
{
string id = "ITADMIN";
string pwd = "Hotpepperz9";
string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/employees/" + pid.ToString();
string pwd = "<PASSWORD>";
/* string url = "https://ubw-accept02.unit4cloud.com/ca_viu_acpt02_webapi/v1/employees/" + pid.ToString(); */
string url = "https://ubw.unit4cloud.com/ca_viu_prod_webapi/v1/employees/" + pid.ToString();
var client = new RestClient(url);
client.Authenticator = new HttpBasicAuthenticator(id, pwd);
......@@ -418,17 +421,18 @@ namespace UBWToStarHR
conn.Open();
OracleCommand cmd = conn.CreateCommand();
OracleCommand cmd2 = conn.CreateCommand();
cmd.CommandText = "select 'Y' from HR.UBW_SG_WRITE_LOG where resno = :res_no";
cmd.CommandText = "select 'Y' from HR.UBW_SG_WRITE_LOG where resno = :res_no and last_run_id = :runid";
cmd.Parameters.Add(new OracleParameter("res_no", resno));
cmd.Parameters.Add(new OracleParameter("runid", run_id));
using (OracleDataReader row = cmd.ExecuteReader())
{
if (row.Read())
{
cmd2.CommandText = "update HR.UBW_SG_WRITE_LOG set STATUS_IND=:status_ind, last_run_id=:last_run_id, date_run=sysdate, sg_empno=:sg_emp_no where resno=:res_no";
cmd2.CommandText = "update HR.UBW_SG_WRITE_LOG set STATUS_IND=:status_ind, date_run=sysdate, sg_empno=:sg_emp_no where resno=:res_no and last_run_id=:last_run_id";
cmd2.Parameters.Add(new OracleParameter("status_ind", status));
cmd2.Parameters.Add(new OracleParameter("last_run_id", run_id));
cmd2.Parameters.Add(new OracleParameter("sg_emp_no", sg_emp_no));
cmd2.Parameters.Add(new OracleParameter("res_no", resno));
cmd2.Parameters.Add(new OracleParameter("last_run_id", run_id));
cmd2.ExecuteNonQuery();
}
......@@ -446,6 +450,39 @@ namespace UBWToStarHR
}
public void SetUBWSGEmpStatus(string resno, string sg_emp_no, Int32 run_id, string status)
{
OracleConnection conn = GetHROracleConnection();
conn.Open();
OracleCommand cmd = conn.CreateCommand();
OracleCommand cmd2 = conn.CreateCommand();
cmd.CommandText = "select 'Y' from HR.UBW_SG_EMP_STATUS where UBW_RESNO = :res_no";
cmd.Parameters.Add(new OracleParameter("res_no", resno));
using (OracleDataReader row = cmd.ExecuteReader())
{
if (row.Read())
{
cmd2.CommandText = "update HR.UBW_SG_EMP_STATUS SET LAST_RUN_ID=:runid, LAST_RUN_STATUS=:stat, LAST_RUN_DATE=SYSDATE WHERE UBW_RESNO=:res_no";
cmd2.Parameters.Add(new OracleParameter("runid", run_id));
cmd2.Parameters.Add(new OracleParameter("stat", status));
cmd2.Parameters.Add(new OracleParameter("res_no", resno));
//cmd2.Parameters.Add(new OracleParameter("sg_emp_no", sg_emp_no));
cmd2.ExecuteNonQuery();
}
else
{
cmd2.CommandText = "insert into HR.UBW_SG_EMP_STATUS (UBW_RESNO, SG_EMPNO, FIRST_RUN_ID, FIRST_RUN_STATUS, FIRST_RUN_DATE) values (:res_no, :sg_emp_no, :runid, :stat, sysdate)";
cmd2.Parameters.Add(new OracleParameter("res_no", resno));
cmd2.Parameters.Add(new OracleParameter("sg_emp_no", sg_emp_no));
cmd2.Parameters.Add(new OracleParameter("runid", run_id));
cmd2.Parameters.Add(new OracleParameter("stat", status));
cmd2.ExecuteNonQuery();
}
}
}
public void EMP_COMP_ACCT_COPY()
{
OracleConnection conn = GetOracleConnection();
......@@ -896,20 +933,31 @@ namespace UBWToStarHR
public string GetEmailFromAD(string userName)
{
string rtn;
using (var pc = new PrincipalContext(ContextType.Domain, "viu.int.viu.ca"))
string rtn = " ";
if (userName != null)
{
var usr = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "viu.int.viu.ca\\" + userName);
if (usr != null)
{
rtn = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "viu.int.viu.ca\\" + userName).EmailAddress;
}
else
using (var pc = new PrincipalContext(ContextType.Domain, "viu.int.viu.ca"))
{
rtn = " ";
var usr = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "viu.int.viu.ca\\" + userName);
if (usr != null)
{
rtn = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "viu.int.viu.ca\\" + userName).EmailAddress;
}
else
{
rtn = " ";
}
}
}
return rtn;
if (rtn != null)
{
return rtn;
} else
{
return " ";
}
}
public string GetMailLocFromAD(string userName)
......
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using UBWToStarHR.UBWEmployment;
using UBWToStarHR.UBWPersonnel;
namespace UBWToStarHR
{
class EmployeeProcessor
{
public void DeleteOneFromSG(long ubw_resno)
{
Entities en = new Entities();
EMPLOYEE_PER_Tools tools = new EMPLOYEE_PER_Tools();
tools.DisableFKConstraints();
tools.ClearStargardenTables(ubw_resno.ToString(), ref en);
}
public void ProcessIndividualEmployee(long ubw_resno)
{
// local variables.
string log_path;
bool emp_has_employment;
bool emp_in_sg;
int count = 0;
string usrname;
string company;
string pwd;
EMPLOYEE_PER_Tools tools = new EMPLOYEE_PER_Tools();
// Setup SOAP clients for Employment and Personnel Data.
UBWEmployment.WSCredentials e_creds;// = new UBWEmployment.WSCredentials();
UBWPersonnel.WSCredentials p_creds;// = new UBWPersonnel.WSCredentials();
EmploymentV201010SoapClient e_client;// = new EmploymentV201010SoapClient();
PersonnelV201010SoapClient p_client;// = new PersonnelV201010SoapClient();
usrname = "ITADMIN";
pwd = "Hotpepperz9";
company = "VU";
e_creds = new UBWEmployment.WSCredentials();
e_creds.Username = usrname;
e_creds.Password = pwd;
e_creds.Client = company;
p_creds = new UBWPersonnel.WSCredentials();
p_creds.Username = usrname;
p_creds.Password = pwd;
p_creds.Client = company;
e_client = new EmploymentV201010SoapClient();
p_client = new PersonnelV201010SoapClient();
EmploymentUnitType e_filter = new EmploymentUnitType();
tools.InitializeEmploymentUnitTypeEFilter(ref e_filter);
// This is the reference to the dbContext //
Entities en = new Entities();
// Tools is a helper class that implements functions to initialize objects
// Reason: Not sure if I can implement constructors on Partial Classes.
// Keep track of integration runs. We have several million available.
Int32 run_id = tools.GetNextRunID();
log_path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\source\\repos\\UBWToStarHR\\UBWToStarHR\\UBWToStarHR_" + ubw_resno.ToString() + "_" + run_id.ToString() + ".log";
System.IO.File.AppendAllText(log_path, "Logging employee: " + ubw_resno.ToString() + " run #" + run_id.ToString() + "-" + DateTime.Now.ToString() + "\r\n");
if (ubw_resno > 0 )
{
tools.DisableFKConstraints();
emp_has_employment = false;
// Is the new RESNO already in SG?
emp_in_sg = tools.EmpInSG(ubw_resno.ToString());
// In theory if the user had no position (emp_has_employment) we'd still clear the SG tables if a records exist.
// On second thought - maybe not what about FK from external systems into SG?
tools.ClearStargardenTables(ubw_resno.ToString(), ref en);
// Get the employement Object first - if there are none we can avoid processing this person.
EmploymentObject[] e_obj = new EmploymentObject[10];
e_filter.ResourceId = ubw_resno.ToString();
e_obj = e_client.GetEmployments(e_filter, false, e_creds);
// Note: Need to see how SOAP returns when there are no employments - handle as appropriate.
emp_has_employment = LoadEmployments(ref e_obj, ref tools, ubw_resno.ToString(), ref en);
if (emp_has_employment)
{
PersonnelObject p_obj = new PersonnelObject();
p_obj = p_client.GetPersonnel(company, ubw_resno.ToString(), false, p_creds);
LoadPersonData(ref p_obj, ref tools, ref en, run_id);
Console.WriteLine("Loaded -" + p_obj.ResourceId.ToString() + " - Count:" + count.ToString());
if (emp_in_sg)
{
// Log the update of the SG record with a status of 'R'
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId, "R", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "IN_SG_EMPL");
}
else
{
// Log the addition of the SG records with a status of 'A'
// 'A' will also trigger pickup by App Reconciliation process.
// PLSQL HR.UBW_SG_APP_RECONCILE package.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId, "A", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "NEWSG_EMPL");
}
System.IO.File.AppendAllText(log_path, "#" + count.ToString() + " Processed - " + p_obj.ResourceId.ToString() + "-" + DateTime.Now.ToString() + "\r\n");
}
else
{
// Log persons with no employments in UBW with a status of E -
// Normally in SG such a situation would cause access to be disabled for many systems
// It may be better to create the records in any case and mark the
// EMP_COMPACCTS records as NT_DISABLED = 'Y'
PersonnelObject p_obj = new PersonnelObject();
p_obj = p_client.GetPersonnel(company, ubw_resno.ToString(), false, p_creds);
LoadPersonData(ref p_obj, ref tools, ref en, run_id);
Console.WriteLine("Loaded -" + p_obj.ResourceId.ToString() + " - Count:" + count.ToString());
if (emp_in_sg)
{
// Log with 'N' status - already in SG and no UBW employment record.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId.ToString(), "N", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "IN_SGNOEMP");
}
else
{
// Log the addition of the SG records with a status of 'E'
// 'E' will also trigger pickup by App Reconciliation process.
// PLSQL HR.UBW_SG_APP_RECONCILE package.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId.ToString(), "E", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "NEWSGNOEMP");
}
System.IO.File.AppendAllText(log_path, "#" + count.ToString() + " Processed - " + ubw_resno.ToString() + " (NO Employments)-" + DateTime.Now.ToString() + "\r\n");
}
}
// Console.WriteLine(JSON);
try
{
// Your code...
// Could also be before try if you know the exception occurs in SaveChanges
System.IO.File.AppendAllText(log_path, "Asking Entity Framework To Save..." + DateTime.Now.ToString() + "\r\n");
en.SaveChanges();
System.IO.File.AppendAllText(log_path, "Entity Framework Saved..." + DateTime.Now.ToString() + "\r\nDeactivate those not updated...\r\n");
//tools.POST_UBW_SG_PURGE(run_id);
//tools.DeactivateRemovedAndNonEmployed(run_id);
tools.ReconcileApps(run_id);
tools.EnableFKConstraints();
System.IO.File.AppendAllText(log_path, "Work Completed..." + DateTime.Now.ToString() + "\r\n\r\n*********\r\n");
//tools.EMP_COMP_ACCT_COPY();
}
catch (DbEntityValidationException e)
{
tools.Fail_UBW_SG_WRITE_LOG("F", run_id);
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
System.IO.File.AppendAllText(log_path, "Entity of type " + eve.Entry.Entity.GetType().Name + " in state " + eve.Entry.State.ToString() + " has the following validation errors:");
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
System.IO.File.AppendAllText(log_path, "Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage + "\r\n");
}
}
throw;
}
Console.WriteLine("Program Finished\r\n");
}
public void ProcessAllEmployees()
{
// local variables.
string log_path;
bool emp_has_employment;
bool emp_in_sg;
int count = 0;
string JSON;
string usrname;
string company;
string pwd;
EMPLOYEE_PER_Tools tools = new EMPLOYEE_PER_Tools();
// Setup SOAP clients for Employment and Personnel Data.
UBWEmployment.WSCredentials e_creds;// = new UBWEmployment.WSCredentials();
UBWPersonnel.WSCredentials p_creds;// = new UBWPersonnel.WSCredentials();
EmploymentV201010SoapClient e_client;// = new EmploymentV201010SoapClient();
PersonnelV201010SoapClient p_client;// = new PersonnelV201010SoapClient();
usrname = "ITADMIN";
pwd = "Hotpepperz9";
company = "VU";
e_creds = new UBWEmployment.WSCredentials();
e_creds.Username = usrname;
e_creds.Password = pwd;
e_creds.Client = company;
p_creds = new UBWPersonnel.WSCredentials();
p_creds.Username = usrname;
p_creds.Password = pwd;
p_creds.Client = company;
e_client = new EmploymentV201010SoapClient();
p_client = new PersonnelV201010SoapClient();
EmploymentUnitType e_filter = new EmploymentUnitType();
tools.InitializeEmploymentUnitTypeEFilter(ref e_filter);
// This is the reference to the dbContext //
Entities en = new Entities();
// Tools is a helper class that implements functions to initialize objects
// Reason: Not sure if I can implement constructors on Partial Classes.
// Keep track of integration runs. We have several million available.
Int32 run_id = tools.GetNextRunID();
log_path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\source\\repos\\UBWToStarHR\\UBWToStarHR\\UBWToStarHR_" + run_id.ToString() + ".log";
System.IO.File.AppendAllText(log_path, "Logging run #" + run_id.ToString() + "-" + DateTime.Now.ToString() + "\r\n");
System.IO.File.AppendAllText(log_path, "Getting JSON List..." + DateTime.Now.ToString() + "\r\n");
// First we get a list of all employees from the JSON of:
JSON = tools.GetEmployeeListJSON();
List<JsonEmpList> elist = JsonEmpList.FromJson(JSON);
System.IO.File.AppendAllText(log_path, "JSON List Retrieved..." + DateTime.Now.ToString() + "\r\n");
// For each employee in the list - process that person...
tools.DisableFKConstraints();
foreach (JsonEmpList emp in elist)
{
// We could check to see if a person has an employment record before migrating them to Stargarden.
// but each application may not provide just security.
// DEBUGGING - For now let's limit how many employees are processed.
//if (count >= 500 && count < 600)
if (count < 40000)
{
emp_has_employment = false;
// Is the new RESNO already in SG?
emp_in_sg = tools.EmpInSG(emp.PersonId.ToString());
// In theory if the user had no position (emp_has_employment) we'd still clear the SG tables if a records exist.
// On second thought - maybe not what about FK from external systems into SG?
tools.ClearStargardenTables(emp.PersonId.ToString(), ref en);
// Get the employement Object first - if there are none we can avoid processing this person.
EmploymentObject[] e_obj = new EmploymentObject[10];
e_filter.ResourceId = emp.PersonId.ToString();
e_obj = e_client.GetEmployments(e_filter, false, e_creds);
// Note: Need to see how SOAP returns when there are no employments - handle as appropriate.
emp_has_employment = LoadEmployments(ref e_obj, ref tools, emp.PersonId.ToString(), ref en);
if (emp_has_employment)
{
PersonnelObject p_obj = new PersonnelObject();
p_obj = p_client.GetPersonnel(company, emp.PersonId.ToString(), false, p_creds);
LoadPersonData(ref p_obj, ref tools, ref en, run_id);
Console.WriteLine("Loaded -" + p_obj.ResourceId.ToString() + " - Count:" + count.ToString());
if (emp_in_sg)
{
// Log the update of the SG record with a status of 'R'
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId, "R", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "IN_SG_EMPL");
}
else
{
// Log the addition of the SG records with a status of 'A'
// 'A' will also trigger pickup by App Reconciliation process.
// PLSQL HR.UBW_SG_APP_RECONCILE package.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId, "A", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "NEWSG_EMPL");
}
System.IO.File.AppendAllText(log_path, "#" + count.ToString() + " Processed - " + p_obj.ResourceId.ToString() + "-" + DateTime.Now.ToString() + "\r\n");
}
else
{
// Log persons with no employments in UBW with a status of E -
// Normally in SG such a situation would cause access to be disabled for many systems
// It may be better to create the records in any case and mark the
// EMP_COMPACCTS records as NT_DISABLED = 'Y'
PersonnelObject p_obj = new PersonnelObject();
p_obj = p_client.GetPersonnel(company, emp.PersonId.ToString(), false, p_creds);
LoadPersonData(ref p_obj, ref tools, ref en, run_id);
Console.WriteLine("Loaded -" + p_obj.ResourceId.ToString() + " - Count:" + count.ToString());
if (emp_in_sg)
{
// Log with 'N' status - already in SG and no UBW employment record.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId.ToString(), "N", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "IN_SGNOEMP");
}
else
{
// Log the addition of the SG records with a status of 'E'
// 'E' will also trigger pickup by App Reconciliation process.
// PLSQL HR.UBW_SG_APP_RECONCILE package.
tools.Update_UBW_SG_WRITE_LOG(p_obj.ResourceId.ToString(), "E", run_id, p_obj.Dim1);
tools.SetUBWSGEmpStatus(p_obj.ResourceId, p_obj.Dim1, run_id, "NEWSGNOEMP");
}
System.IO.File.AppendAllText(log_path, "#" + count.ToString() + " Processed - " + emp.PersonId.ToString() + " (NO Employments)-" + DateTime.Now.ToString() + "\r\n");
}
}
count++;
}
//EmployeeDetail employeeDetail = EmployeeDetail.FromJson(tools.GetEmployeeDetailJSON(elist[0].PersonId));
// Console.WriteLine(JSON);
try
{
// Your code...
// Could also be before try if you know the exception occurs in SaveChanges
System.IO.File.AppendAllText(log_path, "Asking Entity Framework To Save..." + DateTime.Now.ToString() + "\r\n");
en.SaveChanges();
System.IO.File.AppendAllText(log_path, "Entity Framework Saved..." + DateTime.Now.ToString() + "\r\nDeactivate those not updated...\r\n");
//tools.POST_UBW_SG_PURGE(run_id);
//tools.DeactivateRemovedAndNonEmployed(run_id);
tools.ReconcileApps(run_id);
tools.EnableFKConstraints();
System.IO.File.AppendAllText(log_path, "Work Completed..." + DateTime.Now.ToString() + "\r\n\r\n*********\r\n");
//tools.EMP_COMP_ACCT_COPY();
}
catch (DbEntityValidationException e)
{
tools.Fail_UBW_SG_WRITE_LOG("F", run_id);
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
System.IO.File.AppendAllText(log_path, "Entity of type " + eve.Entry.Entity.GetType().Name + " in state " + eve.Entry.State.ToString() + " has the following validation errors:");
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
System.IO.File.AppendAllText(log_path, "Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage + "\r\n");
}
}
throw;
}
Console.WriteLine("Program Finished\r\n");
}
public EMPLOYEE_PER LoadEMPLOYEE_PER(ref PersonnelObject p_obj, ref EMPLOYEE_PER_Tools tools)
{
EMPLOYEE_PER emp_per = new EMPLOYEE_PER();
tools.initializeEMPLOYEE_PER(ref emp_per, p_obj.ResourceId);
//emp_per.EMP_GOVT_NO = tools.NVL(p_obj.SocialSec," ");
emp_per.EMP_GOVT_NO = "000000000";
emp_per.SURNAME = p_obj.SurName.ToUpper();
emp_per.EMP_INITIALS = p_obj.ShortName.ToUpper();
emp_per.PHONE_NO_UNLISTED = "N";
foreach (PersonnelRelationValueUnitType prvu in p_obj.RelationValueList)
{
// U401 is EE_STATUS
if (prvu.RelAttrId == "U401")
{
if (DateTime.Now > prvu.DateFrom && DateTime.Now < prvu.DateTo)
{
emp_per.EMP_STATUS = prvu.RelationValue;
}
}
if (prvu.RelAttrId == "U465")
{
// U465 is WINDOWS_ID
emp_per.EMAIL_ADDRESS = tools.GetEmailFromAD(prvu.RelationValue);
emp_per.MAIL_LOC = tools.GetMailLocFromAD(prvu.RelationValue);
}
if (prvu.RelAttrId == "U466")
{
// U466 is PUBLIC_CELL
if (prvu.RelationValue == "N")
{
emp_per.PHONE_NO_UNLISTED = "Y";
}
}
//if (prvu.RelAttrId == "U465"){// U465 is WINDOWS_ID
// emp_comp_acct.NT_USERNAME = prvu.RelationValue;}
}
emp_per.GIVEN_NAME1 = p_obj.FirstName.ToUpper();
emp_per.PREFRD_NAME = tools.NVL(p_obj.FreeName2, p_obj.FirstName).ToUpper();
if (p_obj.AddressList[0].Address.Length > 30)
{
emp_per.ADDRESS_1 = p_obj.AddressList[0].Address.Substring(1, 30);
}
else
{
emp_per.ADDRESS_1 = tools.NVL(p_obj.AddressList[0].Address, " ");
}
emp_per.CITY = tools.NVL(p_obj.AddressList[0].Place, " ");
if (p_obj.AddressList[0].Province.Length < 4)
{
emp_per.ID_LOCATION = tools.NVL(p_obj.AddressList[0].Province, " ");
}
else
{
emp_per.ID_LOCATION = " ";
}
emp_per.COUNTRY = tools.ConvertISO2ToISO3(p_obj.AddressList[0].CountryCode);
emp_per.COUNTRY_PROC = emp_per.COUNTRY;
emp_per.CITIZEN = "CDN/LI";
emp_per.MAILING_CODE = tools.NVL(p_obj.AddressList[0].ZipCode, " ");
emp_per.PHONE_NO = tools.NVL(p_obj.AddressList[0].Telephone7.Replace('.', '-'), " ");
emp_per.GENDER = tools.NVL(p_obj.Sex, " ");
emp_per.EMP_STATUS = "ACR";
emp_per.DATE_STAMP = Int32.Parse(DateTime.Now.ToString("yyyyMMdd"));
emp_per.DATE_STAMP_IN = Int32.Parse(DateTime.Now.ToString("yyyyMMdd"));
emp_per.TIME_STAMP = Int32.Parse(DateTime.Now.ToString("hhmmssff"));
emp_per.ID_USER_STAMP = "ITADMIN";
emp_per.ID_PROC_STAMP = "UBW";
emp_per.EMAIL_LIST = "Y";
emp_per.PRINT_PAY_ADVICE = "N";
emp_per.PHONE_NO_UNLISTED = "N";
return emp_per;
}
public EMP_COMPACCTS LoadEMP_COMPACCTS(ref PersonnelObject p_obj, ref EMPLOYEE_PER_Tools tools)
{
EMP_COMPACCTS emp_comp_acct = new EMP_COMPACCTS();
emp_comp_acct.EMP_NO = p_obj.ResourceId;
foreach (PersonnelRelationValueUnitType prvu in p_obj.RelationValueList)
{
if (prvu.RelAttrId == "U465")
{
// U465 is WINDOWS_ID
emp_comp_acct.NT_USERNAME = prvu.RelationValue;
emp_comp_acct.VMS_USERNAME = prvu.RelationValue;
}
}
emp_comp_acct.PROTECT_UNTIL = tools.EmployeeProtectUntil(ref p_obj);
emp_comp_acct.NT_DISABLED = tools.EmployeeADDisabled(ref p_obj);
emp_comp_acct.EMP_INACTIVE = tools.EmployeeInactive(ref p_obj);
emp_comp_acct.EMP_ON_LEAVE = tools.EmployeeOnLeave(ref p_obj);
emp_comp_acct.EMP_WORKING_ON_LEAVE = tools.EmployeeWorkingOnLeave(ref p_obj);
emp_comp_acct.NT_EMAIL_ADDRESS = tools.GetEmailFromAD(emp_comp_acct.NT_USERNAME);
if (tools.EmployeeDisableRegardless(ref p_obj))