Esempio n. 1
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_EFU_1845 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            P_L5EM_GEFE_1150 par = new P_L5EM_GEFE_1150();
            par.EmployeeID = Parameter.CMN_BPT_EMP_EmployeeID;
            L5CM_GCSFT_1157 company = cls_Get_Company_Structure_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            employee.Save(Connection, Transaction);

            return(returnValue);

            #endregion UserCode
        }
Esempio n. 2
0
        protected static FR_L5EM_GENFT_1344_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GENFT_1344_Array();

            List <L5EM_GENFT_1344>         employeeResultList = new List <L5EM_GENFT_1344>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GENFT_1344          result   = new L5EM_GENFT_1344();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employeeItem.CMN_BPT_EMP_EmployeeID;

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);


                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.FirstName = personInfo.FirstName;
                result.LastName  = personInfo.LastName;
                employeeResultList.Add(result);

                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GENFT_1344_EmployeeWorkplaceHistory>     employeeWorkplaceAssignments     = new List <L5EM_GENFT_1344_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GENFT_1344_EmployeeWorkplaceHistory item = new L5EM_GENFT_1344_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 3
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_DE_1006 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here

            P_L5EM_GEFE_1150 par = new P_L5EM_GEFE_1150();
            par.EmployeeID = Parameter.CMN_BPT_EMP_EmployeeID;
            L5EM_GEFE_1150 employee = cls_Get_Employee_For_EmployeeID.Invoke(Connection, Transaction, par, securityTicket).Result;


            ORM_CMN_BPT_EMP_Employee whereInstanceEmployee = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_Employee>();
            whereInstanceEmployee.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceEmployee);


            var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
            KeyPerformanceIndicator action = new KeyPerformanceIndicator();
            action.PerformedByAccountID     = securityTicket.AccountID;
            action.PerformedByApplicationID = Parameter.ApplicationID;
            action.PerformedOn               = DateTime.Now;
            action.PerformedByTenantID       = securityTicket.TenantID;
            action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
            action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Length;

            var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);

            ORM_CMN_BPT_EMP_EmploymentRelationship whereInstanceContract = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_EmploymentRelationship>();
            whereInstanceContract.CMN_BPT_EMP_EmploymentRelationshipID = employee.CMN_BPT_EMP_EmploymentRelationshipID;
            CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceContract);

            ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query searchInstanceWorkingContract = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
            searchInstanceWorkingContract.WorkingContract_RefID = employee.CMN_BPT_EMP_EmploymentRelationshipID;
            List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> employmentRelationshipToWorkingContract = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, searchInstanceWorkingContract);
            if (employmentRelationshipToWorkingContract != null)
            {
                foreach (var relationShipToContract in employmentRelationshipToWorkingContract)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContractQuery = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract>();
                    workingContractQuery.CMN_BPT_EMP_WorkingContractID = relationShipToContract.WorkingContract_RefID;
                    CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, workingContractQuery);


                    ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason allowedreasons = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason>();
                    allowedreasons.WorkingContract_RefID = relationShipToContract.WorkingContract_RefID;
                    CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, allowedreasons);
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Esempio n. 4
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SFE_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();



            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name     = Parameter.City_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Tenant_RefID  = Parameter.TenantID;
            address.Save(Connection, Transaction);

            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = Parameter.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.BirthDate     = Parameter.BirthDate;
            person.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = Parameter.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();


            CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = Parameter.TenantID;

            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved);

            ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty)
            {
                var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID);
                if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employeeRelationship.Work_StartDate = Parameter.Work_StartDate;
            employeeRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employeeRelationship.Tenant_RefID   = Parameter.TenantID;
            employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employeeRelationship.Save(Connection, Transaction);



            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, Parameter.USR_AccountID);
                account.USR_AccountID             = Parameter.USR_AccountID;
                account.Username                  = Parameter.username;
                account.DefaultLanguage_RefID     = Parameter.LanguageID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID              = Parameter.TenantID;
                account.Save(Connection, Transaction);

                var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                personToAccountQuery.IsDeleted         = false;
                var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                if (personToAccounts.Count != 0)
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }

                if (Parameter.Rights != null)
                {
                    foreach (var rightParam in Parameter.Rights)
                    {
                        var right = new ORM_USR_Account_FunctionLevelRight();
                        if (rightParam.RightID != Guid.Empty)
                        {
                            var result = right.Load(Connection, Transaction, rightParam.RightID);
                            if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty)
                            {
                                right.USR_Account_FunctionLevelRightID = rightParam.RightID;
                                right.Tenant_RefID = Parameter.TenantID;
                                right.RightName    = rightParam.RightName;
                                right.FunctionLevelRights_Group_RefID = Guid.Empty;
                                right.Save(Connection, Transaction);
                            }
                        }

                        var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                        right2account.Account_RefID            = account.USR_AccountID;
                        right2account.FunctionLevelRight_RefID = rightParam.RightID;
                        right2account.Tenant_RefID             = Parameter.TenantID;
                        right2account.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5OF_GOFT_1157_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5OF_GOFT_1157_Array();
            ORM_CMN_STR_Office.Query officesQuery = new ORM_CMN_STR_Office.Query();
            officesQuery.IsDeleted    = false;
            officesQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_STR_Office> officesResult     = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officesQuery);
            List <L5OF_GOFT_1157>     officesResultList = new List <L5OF_GOFT_1157>();
            foreach (var office in officesResult)
            {
                L5OF_GOFT_1157 result = new L5OF_GOFT_1157();
                var            item   = new ORM_CMN_STR_Office();

                var resultOffice = item.Load(Connection, Transaction, office.CMN_STR_OfficeID);
                if (resultOffice.Status != FR_Status.Success || item.CMN_STR_OfficeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }

                result.CMN_CAL_CalendarInstance_RefID = item.CMN_CAL_CalendarInstance_RefID;
                result.CMN_STR_OfficeID             = item.CMN_STR_OfficeID;
                result.Country_RefID                = item.Country_RefID;
                result.Default_FaxNumber            = item.Default_FaxNumber;
                result.Default_PhoneNumber          = item.Default_PhoneNumber;
                result.Office_ShortName             = item.Office_ShortName;
                result.OfficeDescription            = item.Office_Description;
                result.OfficeName                   = item.Office_Name;
                result.Region_RefID                 = item.Region_RefID;
                result.BillingAddress_CMN_AddressID = item.Default_BillingAddress_RefID;



                var address    = new ORM_CMN_Address();
                var resultItem = address.Load(Connection, Transaction, item.Default_BillingAddress_RefID);
                if (resultItem.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }

                result.BillingAddress_City_Name = address.City_Name;
                result.BillingAddress_City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                result.BillingAddress_City_PostalCode             = address.City_PostalCode;
                result.BillingAddress_City_Region     = address.City_Region;
                result.BillingAddress_Country_Name    = address.Country_Name;
                result.BillingAddress_Province_Name   = address.Province_Name;
                result.BillingAddress_Street_Name     = address.Street_Name;
                result.BillingAddress_Street_Number   = address.Street_Number;
                result.BillingAddress_Country_ISOCode = address.Country_ISOCode;



                ORM_CMN_STR_Office_2_CostCenter.Query officeToCostcenterQuery = new  ORM_CMN_STR_Office_2_CostCenter.Query();
                officeToCostcenterQuery.Office_RefID = office.CMN_STR_OfficeID;
                officeToCostcenterQuery.Tenant_RefID = securityTicket.TenantID;
                officeToCostcenterQuery.IsDeleted    = false;
                List <ORM_CMN_STR_Office_2_CostCenter> officeToCostcenterList = ORM_CMN_STR_Office_2_CostCenter.Query.Search(Connection, Transaction, officeToCostcenterQuery);
                if (officeToCostcenterList.Count != 0)
                {
                    L5OF_GOFT_1157_Costcenter costCenter     = new L5OF_GOFT_1157_Costcenter();
                    ORM_CMN_STR_CostCenter    costCenterItem = new ORM_CMN_STR_CostCenter();
                    costCenterItem.Load(Connection, Transaction, officeToCostcenterList[0].CostCenter_RefID);
                    if (!costCenterItem.IsDeleted)
                    {
                        costCenter.AssignmentID         = officeToCostcenterList[0].AssignmentID;
                        costCenter.CMN_STR_CostCenterID = officeToCostcenterList[0].CostCenter_RefID;
                        costCenter.CostcenterName       = costCenterItem.Name;
                        costCenter.InternalID           = costCenterItem.InternalID;
                        result.Costcenter = costCenter;
                    }
                }
                var responsiblePersonsQuery = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
                responsiblePersonsQuery.Tenant_RefID = securityTicket.TenantID;
                responsiblePersonsQuery.Office_RefID = item.CMN_STR_OfficeID;
                responsiblePersonsQuery.IsDeleted    = false;
                var responsiblePersonsList = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
                List <L5OF_GOFT_1157_ResponsiblePersons> responsiblePresonsResultList = new List <L5OF_GOFT_1157_ResponsiblePersons>();
                foreach (var responsiblePerson in responsiblePersonsList)
                {
                    L5OF_GOFT_1157_ResponsiblePersons responsiblePersonResult = new L5OF_GOFT_1157_ResponsiblePersons();
                    responsiblePersonResult.CMN_BPT_EMP_EmployeeID             = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                    responsiblePersonResult.CMN_STR_Office_ResponsiblePersonID = responsiblePerson.CMN_STR_Office_ResponsiblePersonID;

                    ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                    employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                    ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                    ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                    person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                    responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                    responsiblePersonResult.FirstName = person.FirstName;
                    responsiblePersonResult.LastName  = person.LastName;
                    responsiblePresonsResultList.Add(responsiblePersonResult);
                }
                result.Managers = responsiblePresonsResultList.ToArray();
                officesResultList.Add(result);
            }
            returnValue.Result = officesResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5EM_GEFT_0959_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GEFT_0959_Array();
            List <L5EM_GEFT_0959>          employeeResultList = new List <L5EM_GEFT_0959>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GEFT_0959           result   = new L5EM_GEFT_0959();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;

                ORM_USR_Account.Query accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
                accountQuery.Tenant_RefID = securityTicket.TenantID;
                accountQuery.IsDeleted    = false;
                ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();
                if (account != null)
                {
                    result.USR_AccountID = account.USR_AccountID;
                }

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                result.CMN_BPT_BusinessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
                result.DisplayName = businessParticipant.DisplayName;

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.CMN_PER_PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                result.FirstName            = personInfo.FirstName;
                result.LastName             = personInfo.LastName;
                result.PrimaryEmail         = personInfo.PrimaryEmail;
                result.Title = personInfo.Title;
                result.ProfileImage_Document_RefID = personInfo.ProfileImage_Document_RefID;
                result.BirthDate = personInfo.BirthDate;

                ORM_CMN_BPT_EMP_EmploymentRelationship.Query workingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship.Query();
                workingContractQuery.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                workingContractQuery.IsDeleted      = false;
                workingContractQuery.Tenant_RefID   = securityTicket.TenantID;
                ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = ORM_CMN_BPT_EMP_EmploymentRelationship.Query.Search(Connection, Transaction, workingContractQuery).FirstOrDefault();

                result.CMN_BPT_EMP_EmploymentRelationshipID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                result.Work_StartDate = employmentRelationship.Work_StartDate;
                result.Work_EndDate   = employmentRelationship.Work_EndDate;

                //Address
                if (personInfo.Address_RefID != Guid.Empty)
                {
                    ORM_CMN_Address address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    result.CMN_AddressID = address.CMN_AddressID;
                    result.Street_Name   = address.Street_Name;
                    result.Street_Number = address.Street_Number;
                    result.City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                    result.City_Region     = address.City_Region;
                    result.City_Name       = address.City_Name;
                    result.City_PostalCode = address.City_PostalCode;
                    result.Province_Name   = address.Province_Name;
                    result.Country_Name    = address.Country_Name;
                    result.Country_ISOCode = address.Country_ISOCode;
                }

                //Contacts
                ORM_CMN_PER_CommunicationContact.Query comunicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                comunicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                comunicationContactQuery.Tenant_RefID     = securityTicket.TenantID;
                comunicationContactQuery.IsDeleted        = false;
                List <ORM_CMN_PER_CommunicationContact> comunicationContacts       = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, comunicationContactQuery);
                List <L5EM_GEFT_0959_Contacts>          resultComunicationContacts = new List <L5EM_GEFT_0959_Contacts>();
                foreach (var comunicationContact in comunicationContacts)
                {
                    ORM_CMN_PER_CommunicationContact_Type contactType = new ORM_CMN_PER_CommunicationContact_Type();
                    contactType.Load(Connection, Transaction, comunicationContact.CMN_PER_CommunicationContactID);
                    L5EM_GEFT_0959_Contacts resultComunicationContact = new L5EM_GEFT_0959_Contacts();
                    resultComunicationContact.CMN_PER_CommunicationContact_TypeID = contactType.CMN_PER_CommunicationContact_TypeID;
                    resultComunicationContact.CMN_PER_CommunicationContactID      = comunicationContact.CMN_PER_CommunicationContactID;
                    resultComunicationContact.Content = comunicationContact.Content;
                    resultComunicationContact.Type    = contactType.Type;
                    resultComunicationContacts.Add(resultComunicationContact);
                }
                result.Contacts = resultComunicationContacts.ToArray();


                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>      employeeWorkplaceAssignments     = new List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFT_0959_EmployeeWorkplaceHistory item = new L5EM_GEFT_0959_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();


                //Contracts

                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query contractTermQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                contractTermQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                contractTermQuery.IsDeleted    = false;
                contractTermQuery.Tenant_RefID = securityTicket.TenantID;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> contracts = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, contractTermQuery);
                List <L5EM_GEFT_0959_WorkingContracts> resultContracts = new List <L5EM_GEFT_0959_WorkingContracts>();
                foreach (var contractToRelationship in contracts)
                {
                    L5EM_GEFT_0959_WorkingContracts resultContract = new L5EM_GEFT_0959_WorkingContracts();

                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    workingContract.Load(Connection, Transaction, contractToRelationship.WorkingContract_RefID);
                    if (!workingContract.IsDeleted)
                    {
                        resultContract.CMN_BPT_EMP_WorkingContractID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        resultContract.EmploymentRelationshipToWorkingContractAssignmentID = contractToRelationship.AssignmentID;
                        resultContract.IsWorkingContract_Active     = contractToRelationship.IsContract_Active;
                        resultContract.Contract_StartDate           = workingContract.Contract_StartDate;
                        resultContract.Contract_EndDate             = workingContract.Contract_EndDate;
                        resultContract.IsContractEndDateDefined     = workingContract.IsContractEndDateDefined;
                        resultContract.IsWorkTimeCalculated_InDays  = workingContract.IsWorkTimeCalculated_InDays;
                        resultContract.IsWorkTimeCalculated_InHours = workingContract.IsWorkTimeCalculated_InHours;
                        resultContract.R_WorkTime_DaysPerWeek       = workingContract.R_WorkTime_DaysPerWeek;
                        resultContract.R_WorkTime_HoursPerWeek      = workingContract.R_WorkTime_HoursPerWeek;

                        //Office hours
                        ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query workingContractTermToWorkingDayQuery = new ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query();
                        workingContractTermToWorkingDayQuery.CMN_BPT_EMP_WorkingContract_RefID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        workingContractTermToWorkingDayQuery.Tenant_RefID = securityTicket.TenantID;
                        workingContractTermToWorkingDayQuery.IsDeleted    = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay> workingDayAssigments    = ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query.Search(Connection, Transaction, workingContractTermToWorkingDayQuery);
                        List <L5EM_GEFT_0959_WeeklyOfficeHours>             resultWeeklyOfficeHours = new List <L5EM_GEFT_0959_WeeklyOfficeHours>();
                        foreach (var workingDayAssigment in workingDayAssigments)
                        {
                            ORM_CMN_CAL_WeeklyOfficeHours_Interval interval = new ORM_CMN_CAL_WeeklyOfficeHours_Interval();
                            interval.Load(Connection, Transaction, workingDayAssigment.CMN_CAL_WeeklyOfficeHours_Interval_RefID);

                            L5EM_GEFT_0959_WeeklyOfficeHours resultOfficeHour = new L5EM_GEFT_0959_WeeklyOfficeHours();
                            resultOfficeHour.CMN_CAL_WeeklyOfficeHours_IntervalID = interval.CMN_CAL_WeeklyOfficeHours_IntervalID;
                            resultOfficeHour.IsFriday           = interval.IsFriday;
                            resultOfficeHour.IsMonday           = interval.IsMonday;
                            resultOfficeHour.IsSaturday         = interval.IsSaturday;
                            resultOfficeHour.IsSunday           = interval.IsSunday;
                            resultOfficeHour.IsThursday         = interval.IsThursday;
                            resultOfficeHour.IsTuesday          = interval.IsTuesday;
                            resultOfficeHour.IsWednesday        = interval.IsWednesday;
                            resultOfficeHour.IsWholeDay         = interval.IsWholeDay;
                            resultOfficeHour.TimeFrom_InMinutes = interval.TimeFrom_InMinutes;
                            resultOfficeHour.TimeTo_InMinutes   = interval.TimeTo_InMinutes;
                            resultWeeklyOfficeHours.Add(resultOfficeHour);
                        }
                        resultContract.WeeklyOfficeHours = resultWeeklyOfficeHours.ToArray();


                        //Allowed absence reasons
                        ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query AllowedAbsenceReasonQuery = new ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query();
                        AllowedAbsenceReasonQuery.WorkingContract_RefID = resultContract.CMN_BPT_EMP_WorkingContractID;
                        AllowedAbsenceReasonQuery.Tenant_RefID          = securityTicket.TenantID;
                        AllowedAbsenceReasonQuery.IsDeleted             = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason> allowedAbsenceReasons       = ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query.Search(Connection, Transaction, AllowedAbsenceReasonQuery);
                        List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>         resultAllowedAbsenceReasons = new List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>();
                        foreach (var allowedAbsenceReason in allowedAbsenceReasons)
                        {
                            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
                            absenceReason.Load(Connection, Transaction, allowedAbsenceReason.STA_AbsenceReason_RefID);

                            L5EM_GEFT_0959_WorkingContractToLeaveRequest resultReasonresultReason = new L5EM_GEFT_0959_WorkingContractToLeaveRequest();
                            resultReasonresultReason.CMN_BPT_EMP_Employee_WorkingContract_AllowedAbsenceReasonID = allowedAbsenceReason.CMN_BPT_EMP_WorkingContract_AllowedAbsenceReasonID;
                            resultReasonresultReason.STA_AbsenceReason_RefID          = absenceReason.CMN_BPT_STA_AbsenceReasonID;
                            resultReasonresultReason.IsAbsenceCalculated_InDays       = allowedAbsenceReason.IsAbsenceCalculated_InDays;
                            resultReasonresultReason.IsAbsenceCalculated_InHours      = allowedAbsenceReason.IsAbsenceCalculated_InHours;
                            resultReasonresultReason.ContractAllowedAbsence_per_Month = allowedAbsenceReason.ContractAllowedAbsence_per_Month;
                            resultAllowedAbsenceReasons.Add(resultReasonresultReason);
                        }
                        resultContract.WorkingContractToLeaveRequest = resultAllowedAbsenceReasons.ToArray();

                        resultContracts.Add(resultContract);
                    }
                }
                result.WorkingContracts = resultContracts.ToArray();
                employeeResultList.Add(result);
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 7
0
        protected static FR_L5WA_GWAFWA_0907 Execute(DbConnection Connection, DbTransaction Transaction, P_L5WA_GWAFWA_0907 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5WA_GWAFWA_0907();
            returnValue.Result = new L5WA_GWAFWA_0907();

            L5WA_GWAFT_1201 result = new L5WA_GWAFT_1201();

            ORM_CMN_STR_PPS_WorkArea item = new ORM_CMN_STR_PPS_WorkArea();
            if (Parameter.WorkAreaID != Guid.Empty)
            {
                var resultWorkplace = item.Load(Connection, Transaction, Parameter.WorkAreaID);
                if (resultWorkplace.Status != FR_Status.Success || item.CMN_STR_PPS_WorkAreaID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }
            }
            result.CMN_CAL_CalendarInstance_RefID   = item.CMN_CAL_CalendarInstance_RefID;
            result.CMN_BPT_STA_SettingProfile_RefID = item.CMN_BPT_STA_SettingProfile_RefID;
            result.Office_RefID             = item.Office_RefID;
            result.Parent_RefID             = item.Parent_RefID;
            result.WorkAreaName             = item.Name;
            result.WorkAreaDescription      = item.Description;
            result.ShortName                = item.ShortName;
            result.CMN_STR_PPS_WorkAreaID   = item.CMN_STR_PPS_WorkAreaID;
            result.Default_StartWorkingHour = item.Default_StartWorkingHour;



            ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query workareaToCostcenterQuery = new ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query();
            workareaToCostcenterQuery.WorkArea_RefID = Parameter.WorkAreaID;
            workareaToCostcenterQuery.Tenant_RefID   = securityTicket.TenantID;
            workareaToCostcenterQuery.IsDeleted      = false;
            List <ORM_CMN_STR_PPS_WorkArea_2_CostCenter> workareaToCostcenterList = ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query.Search(Connection, Transaction, workareaToCostcenterQuery);
            if (workareaToCostcenterList.Count != 0)
            {
                L5WA_GWAFT_1201_Costcenter costCenter     = new L5WA_GWAFT_1201_Costcenter();
                ORM_CMN_STR_CostCenter     costCenterItem = new ORM_CMN_STR_CostCenter();
                costCenterItem.Load(Connection, Transaction, workareaToCostcenterList[0].CostCenter_RefID);
                if (!costCenterItem.IsDeleted)
                {
                    costCenter.AssignmentID         = workareaToCostcenterList[0].AssignmentID;
                    costCenter.CMN_STR_CostCenterID = workareaToCostcenterList[0].CostCenter_RefID;
                    costCenter.CostcenterName       = costCenterItem.Name;
                    costCenter.InternalID           = costCenterItem.InternalID;
                    result.Costcenter = costCenter;
                }
            }


            var responsiblePersonsQuery = new ORM_CMN_STR_PPS_WorkArea_ResponsiblePerson.Query();
            responsiblePersonsQuery.Tenant_RefID   = securityTicket.TenantID;
            responsiblePersonsQuery.WorkArea_RefID = item.CMN_STR_PPS_WorkAreaID;
            responsiblePersonsQuery.IsDeleted      = false;
            var responsiblePersonsList = ORM_CMN_STR_PPS_WorkArea_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
            List <L5WA_GWAFT_1201_ResponsiblePersons> responsiblePresonsResultList = new List <L5WA_GWAFT_1201_ResponsiblePersons>();
            foreach (var responsiblePerson in responsiblePersonsList)
            {
                L5WA_GWAFT_1201_ResponsiblePersons responsiblePersonResult = new L5WA_GWAFT_1201_ResponsiblePersons();
                responsiblePersonResult.CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                responsiblePersonResult.CMN_STR_PPS_WorkArea_ResponsiblePersonID = responsiblePerson.CMN_STR_PPS_WorkArea_ResponsiblePersonID;

                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                responsiblePersonResult.FirstName            = person.FirstName;
                responsiblePersonResult.LastName             = person.LastName;
                responsiblePersonResult.CMN_PER_PersonInfoID = person.CMN_PER_PersonInfoID;
                responsiblePersonResult.WorkArea_RefID       = item.CMN_STR_PPS_WorkAreaID;

                responsiblePresonsResultList.Add(responsiblePersonResult);
            }

            result.ResponsiblePersons = responsiblePresonsResultList.ToArray();

            returnValue.Result.workarea = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
Esempio n. 9
0
        protected static FR_L5EM_GEFU_445 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var           returnValue = new FR_L5EM_GEFU_445();
            L5EM_GEFU_445 result      = new L5EM_GEFU_445();


            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            if (account.USR_AccountID == Guid.Empty)
            {
                return(null);
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            employeeQuery.BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);
            if (employeeList.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee employee = employeeList[0];
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;


                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFU_445_EmployeeWorkplaceHistory>       employeeWorkplaceAssignments     = new List <L5EM_GEFU_445_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFU_445_EmployeeWorkplaceHistory item = new L5EM_GEFU_445_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 10
0
        protected static FR_L6LR_GLR_ID_1339 Execute(DbConnection Connection, DbTransaction Transaction, P_L6LR_GLR_ID_1339 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6LR_GLR_ID_1339();
            returnValue.Result = new L6LR_GLR_ID_1339();


            //Covers
            ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query leaveRequestQuery = new ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query();
            leaveRequestQuery.CMN_BPT_EMP_Employee_LeaveRequestID = Parameter.LeaveID;
            leaveRequestQuery.Tenant_RefID = securityTicket.TenantID;
            leaveRequestQuery.IsDeleted    = false;
            ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query.Search(Connection, Transaction, leaveRequestQuery).FirstOrDefault();
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            employee.Load(Connection, Transaction, leaveRequest.RequestedFor_Employee_RefID);
            L5LR_GLRFSP_1532 result = new L5LR_GLRFSP_1532();
            result.ForEmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            result.ForEmployee_BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
            result.ForEmployee_Staff_Number     = employee.Staff_Number;
            result.ForEmployee_StandardFunction = employee.StandardFunction;
            result.LeaveRequestCreationSource   = leaveRequest.LeaveRequestCreationSource;
            ORM_CMN_BPT_BusinessParticipant bpart = new ORM_CMN_BPT_BusinessParticipant();
            bpart.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

            ORM_CMN_PER_PersonInfo per = new ORM_CMN_PER_PersonInfo();
            per.Load(Connection, Transaction, bpart.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
            result.FirstName = per.FirstName;
            result.LastName  = per.LastName;

            result.CMN_CAL_Event_RefID          = leaveRequest.CMN_CAL_Event_RefID;
            result.CMN_CAL_Event_Approval_RefID = leaveRequest.CMN_CAL_Event_Approval_RefID;
            //result.AbsenceReason_Type_RefID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID;
            result.Comment = leaveRequest.Comment;
            result.RequestedBy_Employee_RefID          = leaveRequest.RequestedBy_Employee_RefID;
            result.CMN_BPT_EMP_Employee_LeaveRequestID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID;
            ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query covers = new ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query();
            covers.CMN_BPT_EMP_Employee_LeaveRequests = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID;
            covers.Tenant_RefID = securityTicket.TenantID;
            covers.IsDeleted    = false;
            List <ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover> employeeCovers = ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query.Search(Connection, Transaction, covers);
            result.Cover = new L5LR_GLRFSP_1532_Cover();
            if (employeeCovers.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover employeeCover = employeeCovers[0];
                result.Cover.CMN_BPT_EMP_EmployeeID = employeeCover.EmployeeCover_RefID;
                result.Cover.CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCoverID = employeeCover.CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCoverID;
                result.Cover.SequenceNumber = employeeCover.SequenceNumber;
            }

            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
            absenceReason.Load(Connection, Transaction, leaveRequest.CMN_BPT_STA_AbsenceReason_RefID);

            result.CMN_BPT_STA_AbsenceReason_RefID = absenceReason.CMN_BPT_STA_AbsenceReasonID;
            result.ShortName  = absenceReason.ShortName;
            result.ReasonName = absenceReason.Name;
            result.ReasonDesc = absenceReason.Description;
            result.AbsenceReason_Type_RefID = absenceReason.AbsenceReason_Type_RefID;
            result.ColorCode                            = absenceReason.ColorCode;
            result.Parent_RefID                         = absenceReason.Parent_RefID;
            result.IsAuthorizationRequired              = absenceReason.IsAuthorizationRequired;
            result.IsIncludedInCapacityCalculation      = absenceReason.IsIncludedInCapacityCalculation;
            result.IsAllowedAbsence                     = absenceReason.IsAllowedAbsence;
            result.IsDeactivated                        = absenceReason.IsDeactivated;
            result.IsCarryOverEnabled                   = absenceReason.IsCarryOverEnabled;
            result.IsCaryOverLimited                    = absenceReason.IsCaryOverLimited;
            result.IfCarryOverLimited_MaximumAmount_Hrs = absenceReason.IfCarryOverLimited_MaximumAmount_Hrs;

            ORM_CMN_CAL_Event Event = new ORM_CMN_CAL_Event();
            Event.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID);

            result.CalendarInstance_RefID = Event.CalendarInstance_RefID;
            result.StartTime           = Event.StartTime;
            result.EndTime             = Event.EndTime;
            result.R_EventDuration_sec = Event.R_EventDuration_sec;

            ORM_CMN_CAL_Event_Approval eventApproval = new ORM_CMN_CAL_Event_Approval();
            eventApproval.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_Approval_RefID);

            result.Action = new L5LR_GLRFSP_1532_Action();

            result.IsApproved = eventApproval.IsApproved;
            result.IsApprovalProcessOpened = eventApproval.IsApprovalProcessOpened;
            result.IsApprovalProcessDenied = eventApproval.IsApprovalProcessDenied;

            ORM_CMN_CAL_Event_Approval_Action.Query approvalQuery = new ORM_CMN_CAL_Event_Approval_Action.Query();
            approvalQuery.EventApproval_RefID = eventApproval.CMN_CAL_Event_ApprovalID;
            approvalQuery.Tenant_RefID        = securityTicket.TenantID;
            approvalQuery.IsDeleted           = false;
            List <ORM_CMN_CAL_Event_Approval_Action> apporvalActions = ORM_CMN_CAL_Event_Approval_Action.Query.Search(Connection, Transaction, approvalQuery);
            if (apporvalActions.Count != 0)
            {
                ORM_CMN_CAL_Event_Approval_Action approvalAction = apporvalActions[0];
                result.Action.ActionTriggeredBy_Account_RefID = approvalAction.ActionTriggeredBy_Account_RefID;
                result.Action.CMN_CAL_Event_Approval_ActionID = approvalAction.CMN_CAL_Event_Approval_ActionID;
                result.Action.IsApproval              = approvalAction.IsApproval;
                result.Action.IsRevocation            = approvalAction.IsRevocation;
                result.Action.IsDenial                = approvalAction.IsDenial;
                result.Action.Approval_Action_Commnet = approvalAction.Comment;
            }

            returnValue.Result.Leave = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
		protected static FR_L6DO_SDaSwDC_1224 Execute(DbConnection Connection,DbTransaction Transaction,P_L6DO_SDaSwDC_1224 Parameter,CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null){
			#region UserCode 
			var returnValue = new FR_L6DO_SDaSwDC_1224();
			//Put your code here

            returnValue.Result = new L6DO_SDaSwDC_1224();

            Guid EmployeeId = Guid.Empty;
            if (!Parameter.BaseData.IsDeleted)
            {
                EmployeeId = cls_Save_Doctors_and_Staff.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;

                if(Parameter.UpdateSlots)
                    foreach (var unit in Parameter.BaseData.OrgUnits)
                        cls_CreateUpdate_Slots_for_Practice.Invoke(Connection, Transaction, new P_L5S_SUSfP_1708() { PracticeID = unit.CMN_STR_Office_RefID }, securityTicket);
            }
            else
            {
                ORM_CMN_BPT_EMP_Employee employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query
                {
                    IsDeleted = false,
                    Tenant_RefID = securityTicket.TenantID,
                    BusinessParticipant_RefID = Parameter.BaseData.CMN_BPT_BusinessParticipantID
                }).Single();

                List<ORM_PPS_TSK_Task_RequiredStaff> existingAppointmentType = ORM_PPS_TSK_Task_RequiredStaff.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_RequiredStaff.Query
                {
                    IsDeleted = false,
                    Tenant_RefID = securityTicket.TenantID,
                    Required_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID
                }).ToList();

                if (existingAppointmentType.Count > 0) //cannot delete
                {
                    List<L6DO_SDaSwDC_1224_UsedInAppointmentType> usedAppointmentTypeList = new List<L6DO_SDaSwDC_1224_UsedInAppointmentType>();

                    foreach (var appointmentType in existingAppointmentType)
                    {
                        ORM_PPS_TSK_Task_Template appointmentTypeName = ORM_PPS_TSK_Task_Template.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_Template.Query{
                            IsDeleted = false,
                            Tenant_RefID = securityTicket.TenantID,
                            PPS_TSK_Task_TemplateID = appointmentType.TaskTemplate_RefID
                        }).Single();

                        usedAppointmentTypeList.Add(new L6DO_SDaSwDC_1224_UsedInAppointmentType { AppointmentTypeName = appointmentTypeName.TaskTemplateName });
                    }
                    returnValue.Result.UsedInAppointmentType = usedAppointmentTypeList.ToArray();
                }

                List<ORM_PPS_TSK_Task_StaffBooking> existingAppointment = ORM_PPS_TSK_Task_StaffBooking.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_StaffBooking.Query
                {
                    IsDeleted = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID
                }).ToList();

                if (existingAppointment.Count > 0) //cannot delete
                {
                    List<L6DO_SDaSwDC_1224_UsedInAppointment> usedAppointmentList = new List<L6DO_SDaSwDC_1224_UsedInAppointment>();

                    foreach (var appointment in existingAppointment)
                    {
                        ORM_PPS_TSK_Task appointmentName = ORM_PPS_TSK_Task.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task.Query
                        {
                            IsDeleted = false,
                            Tenant_RefID = securityTicket.TenantID,
                            PPS_TSK_TaskID = appointment.PPS_TSK_Task_RefID
                        }).Single();

                        usedAppointmentList.Add(new L6DO_SDaSwDC_1224_UsedInAppointment { AppointmentName = appointmentName.DisplayName });
                    }
                    returnValue.Result.UsedInAppointment = usedAppointmentList.ToArray();
                }

                if (existingAppointment.Count == 0 && existingAppointmentType.Count == 0)
                {
                    EmployeeId = cls_Save_Doctors_and_Staff.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
                    var emp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query { BusinessParticipant_RefID = Parameter.BaseData.CMN_BPT_BusinessParticipantID, Tenant_RefID = securityTicket.TenantID }).FirstOrDefault();
                    var orgUnits = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee_2_Office.Query { CMN_BPT_EMP_Employee_RefID = emp.CMN_BPT_EMP_EmployeeID, Tenant_RefID = securityTicket.TenantID });
                    if(Parameter.UpdateSlots)
                        foreach (var unit in orgUnits)
                            cls_CreateUpdate_Slots_for_Practice.Invoke(Connection, Transaction, new P_L5S_SUSfP_1708() { PracticeID = unit.CMN_STR_Office_RefID }, securityTicket);
                }
            }
            returnValue.Result.ID = EmployeeId;

			return returnValue;
			#endregion UserCode
		}
Esempio n. 12
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SE_1657 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


            ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty)
            {
                var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID);
                if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employmentRelationship.Work_StartDate = Parameter.Work_StartDate;

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 13
0
        protected static FR_L5WP_GWPFWPID_1132 Execute(DbConnection Connection, DbTransaction Transaction, P_L5WP_GWPFWPID_1132 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5WP_GWPFWPID_1132();

            returnValue.Result = new L5WP_GWPFWPID_1132();

            L5WP_GWFT_1203 result = new L5WP_GWFT_1203();

            ORM_CMN_STR_PPS_Workplace item = new ORM_CMN_STR_PPS_Workplace();
            if (Parameter.workplaceID != Guid.Empty)
            {
                var resultWorkplace = item.Load(Connection, Transaction, Parameter.workplaceID);
                if (resultWorkplace.Status != FR_Status.Success || item.CMN_STR_PPS_WorkplaceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }
            }
            result.CMN_CAL_CalendarInstance_RefID = item.CMN_CAL_CalendarInstance_RefID;
            result.CMN_STR_PPS_WorkplaceID        = item.CMN_STR_PPS_WorkplaceID;
            result.ShortName            = item.ShortName;
            result.WorkArea_RefID       = item.WorkArea_RefID;
            result.WorkPlaceDescription = item.Description;
            result.WorkPlaceName        = item.Name;


            var responsiblePersonsQuery = new ORM_CMN_STR_PPS_Workplace_ResponsiblePerson.Query();
            responsiblePersonsQuery.Tenant_RefID    = securityTicket.TenantID;
            responsiblePersonsQuery.Workplace_RefID = item.CMN_STR_PPS_WorkplaceID;
            responsiblePersonsQuery.IsDeleted       = false;
            var responsiblePersonsList = ORM_CMN_STR_PPS_Workplace_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
            List <L5WP_GWFT_1203_ResponsiblePerson> responsiblePresonsResultList = new List <L5WP_GWFT_1203_ResponsiblePerson>();
            foreach (var responsiblePerson in responsiblePersonsList)
            {
                L5WP_GWFT_1203_ResponsiblePerson responsiblePersonResult = new L5WP_GWFT_1203_ResponsiblePerson();
                responsiblePersonResult.CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                responsiblePersonResult.CMN_STR_PPS_Workplace_ResponsiblePersonID = responsiblePerson.CMN_STR_PPS_Workplace_ResponsiblePersonID;

                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                responsiblePersonResult.FirstName            = person.FirstName;
                responsiblePersonResult.LastName             = person.LastName;
                responsiblePersonResult.CMN_PER_PersonInfoID = person.CMN_PER_PersonInfoID;
                responsiblePresonsResultList.Add(responsiblePersonResult);
            }

            result.ResponsiblePersons    = responsiblePresonsResultList.ToArray();
            returnValue.Result.workplace = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5US_GAOfA_1742 Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_GAOfA_1742 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5US_GAOfA_1742();
            //Put your code here

            var allOfficesForTenant = cls_Get_AllOffices_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            ORM_USR_Account user = new ORM_USR_Account();
            user.Load(Connection, Transaction, Parameter.UserAccountID);

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            var foundEmployee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).FirstOrDefault();

            if (foundEmployee == null)
            {
                foundEmployee = new ORM_CMN_BPT_EMP_Employee();
                foundEmployee.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
                foundEmployee.Tenant_RefID = securityTicket.TenantID;
                foundEmployee.Save(Connection, Transaction);
            }

            List <L5US_GAOfA_1742a> listOfOfficesWithAssignments = new List <L5US_GAOfA_1742a>();

            foreach (var office in allOfficesForTenant)
            {
                var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                assignmentQuery.CMN_STR_Office_RefID       = office.CMN_STR_OfficeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
                assignmentQuery.IsDeleted    = false;
                var foundAssignment = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery);

                L5US_GAOfA_1742a temp = new L5US_GAOfA_1742a();
                if (foundAssignment.Count > 0)
                {
                    temp.AssignmentID = foundAssignment.First().AssignmentID;
                }
                temp.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                temp.CMN_STR_OfficeID           = office.CMN_STR_OfficeID;
                temp.Office_InternalName        = office.Office_InternalName;
                temp.IsOfficeToAccountDeleted   = foundAssignment.Count == 0;
                temp.Office_Description         = office.Office_Description;
                temp.Office_Name  = office.Office_Name;
                temp.Parent_RefID = office.Parent_RefID;

                temp.USR_AccountID = Parameter.UserAccountID;

                listOfOfficesWithAssignments.Add(temp);
            }

            returnValue.Result = new L5US_GAOfA_1742();
            returnValue.Result.OfficesWithAssignedUser = new List <L5US_GAOfA_1742a>().ToArray();
            returnValue.Result.OfficesWithAssignedUser = listOfOfficesWithAssignments.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Esempio n. 15
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OU_SOUGD_1221 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            #region Save
            if (Parameter.OrgUnitID == null || Parameter.OrgUnitID == Guid.Empty)
            {
                //*******************MedicalPracticeType************************

                var medicalPractice = new ORM_HEC_MedicalPractis();
                medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                medicalPractice.IsDeleted             = false;
                medicalPractice.Save(Connection, Transaction);

                foreach (var item in Parameter.MedicalPracticeType)
                {
                    var medicalPractice2PracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                    medicalPractice2PracticeType.AssignmentID = Guid.NewGuid();
                    medicalPractice2PracticeType.HEC_MedicalPractice_Type_RefID = item.HEC_MedicalPractice_TypeID;
                    medicalPractice2PracticeType.HEC_MedicalPractice_RefID      = medicalPractice.HEC_MedicalPractiseID;
                    medicalPractice2PracticeType.Tenant_RefID = securityTicket.TenantID;
                    medicalPractice2PracticeType.IsDeleted    = false;
                    medicalPractice2PracticeType.Save(Connection, Transaction);
                }

                //******************* Office************************
                var Office = new ORM_CMN_STR_Office();
                Office.CMN_STR_OfficeID = Guid.NewGuid();
                Office.Office_Name      = Parameter.OrgUnitName_DictID;
                Office.Tenant_RefID     = securityTicket.TenantID;
                if (Parameter.ParentID != null && Parameter.ParentID != Guid.Empty)
                {
                    Office.Parent_RefID = Parameter.ParentID;
                }
                Office.Creation_Timestamp = DateTime.Now;

                var officeQuery = new ORM_CMN_STR_Office.Query();
                officeQuery.Tenant_RefID = securityTicket.TenantID;
                int officeCount = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Count;

                Office.Office_InternalNumber       = String.Format("{0:00000}", officeCount + 1);
                Office.Default_PhoneNumber         = Parameter.Telephone;
                Office.DisplayImage_Document_RefID = Parameter.DisplayImage_Document_RefID;
                Office.Default_Email      = Parameter.Email;
                Office.Default_Website    = Parameter.Website;
                Office.Office_Description = new Dict("cmn_str_offices");
                Office.Comment            = Parameter.Notes;
                Office.IsMedicalPractice  = true;
                Office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                Office.Save(Connection, Transaction);

                //*******************Save Address************************

                foreach (var address in Parameter.Adresses)
                {
                    var Office_2_Address = new ORM_CMN_STR_Office_Address();
                    Office_2_Address.CMN_STR_Office_AddressID = Guid.NewGuid();
                    Office_2_Address.IsBillingAddress         = address.IsBillingAddress;
                    Office_2_Address.IsShippingAddress        = address.IsShippingAddress;
                    Office_2_Address.IsSpecialAddress         = address.IsSpecialAddress;
                    Office_2_Address.CMN_Address_RefID        = address.AddressID;
                    Office_2_Address.Office_RefID             = Office.CMN_STR_OfficeID;
                    Office_2_Address.Tenant_RefID             = securityTicket.TenantID;
                    Office_2_Address.Creation_Timestamp       = DateTime.Now;
                    Office_2_Address.IsDefault = address.IsDefault;
                    Office_2_Address.Save(Connection, Transaction);

                    var Address = new ORM_CMN_Address();
                    Address.CMN_AddressID      = Office_2_Address.CMN_Address_RefID;
                    Address.Tenant_RefID       = securityTicket.TenantID;
                    Address.Creation_Timestamp = DateTime.Now;
                    Address.City_Name          = address.City;
                    Address.Street_Name        = address.Street_Name;
                    Address.Street_Number      = address.Street_Number;
                    Address.Country_ISOCode    = address.CountryISO;
                    Address.Country_Name       = address.CountryName;
                    Address.City_PostalCode    = address.ZIP;
                    if (address.IsDefault)
                    {
                        Address.Lattitude = address.Lattitude;
                        Address.Longitude = address.Longitude;
                    }
                    Address.Save(Connection, Transaction);
                }

                //*******************Save Languages************************

                foreach (var item in Parameter.SpokenLanguage)
                {
                    var officeSpokenLanguages = new ORM_CMN_STR_Office_SpokenLanguage();
                    officeSpokenLanguages.CMN_STR_Office_SpokenLanguageID = Guid.NewGuid();
                    officeSpokenLanguages.Office_RefID   = Office.CMN_STR_OfficeID;
                    officeSpokenLanguages.Language_RefID = item.CMN_LanguageID;
                    officeSpokenLanguages.IsDeleted      = item.IsDeleted;
                    officeSpokenLanguages.Tenant_RefID   = securityTicket.TenantID;
                    officeSpokenLanguages.Save(Connection, Transaction);
                }

                //*******************Save Contact Person************************

                var responsiblePerson = new ORM_CMN_STR_Office_ResponsiblePerson();
                responsiblePerson.CMN_STR_Office_ResponsiblePersonID = Guid.NewGuid();
                responsiblePerson.Office_RefID = Office.CMN_STR_OfficeID;
                responsiblePerson.CMN_BPT_EMP_Employee_RefID = Guid.NewGuid();
                responsiblePerson.Tenant_RefID       = securityTicket.TenantID;
                responsiblePerson.Creation_Timestamp = DateTime.Now;
                responsiblePerson.Save(Connection, Transaction);

                var employee = new ORM_CMN_BPT_EMP_Employee();
                employee.CMN_BPT_EMP_EmployeeID    = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                employee.BusinessParticipant_RefID = Guid.NewGuid();
                employee.Creation_Timestamp        = DateTime.Now;
                employee.Tenant_RefID = securityTicket.TenantID;
                employee.Save(Connection, Transaction);

                var businessParticpant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticpant.CMN_BPT_BusinessParticipantID = employee.BusinessParticipant_RefID;
                businessParticpant.IsNaturalPerson    = true;
                businessParticpant.DisplayName        = Parameter.ContactPerson.Title + " " + Parameter.ContactPerson.FirstName + " " + Parameter.ContactPerson.LastName;
                businessParticpant.Tenant_RefID       = securityTicket.TenantID;
                businessParticpant.Creation_Timestamp = DateTime.Now;
                businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businessParticpant.Save(Connection, Transaction);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Title              = Parameter.ContactPerson.Title;
                personInfo.FirstName          = Parameter.ContactPerson.FirstName;
                personInfo.LastName           = Parameter.ContactPerson.LastName;
                personInfo.Tenant_RefID       = securityTicket.TenantID;
                personInfo.Creation_Timestamp = DateTime.Now;
                personInfo.Save(Connection, Transaction);

                //*******************AppointmentType************************

                foreach (var item in Parameter.AppoitmentType)
                {
                    ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability orgUnitToAppointmentType = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability();
                    orgUnitToAppointmentType.PPS_TSK_Task_Template_OrganizationalUnitAvailabilityID = Guid.NewGuid();
                    orgUnitToAppointmentType.CMN_STR_Office_RefID        = Office.CMN_STR_OfficeID;
                    orgUnitToAppointmentType.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                    orgUnitToAppointmentType.Creation_Timestamp          = DateTime.Now;
                    orgUnitToAppointmentType.Tenant_RefID = securityTicket.TenantID;
                    orgUnitToAppointmentType.Save(Connection, Transaction);
                }

                returnValue.Result = Office.CMN_STR_OfficeID;
            }
            #endregion
            #region Delete
            else if (Parameter.IsDeleted)
            {
                List <Guid> guidList = new List <Guid>();
                guidList.Add(Parameter.OrgUnitID);
                cls_Delete_OrgsUnitsGeneralData.Invoke(Connection, Transaction, new P_L5OU_DOUGD_1221 {
                    OrgUnitID = guidList.ToArray()
                }, securityTicket);
            }
            #endregion
            #region Edit
            else
            {
                var officeQuery = new ORM_CMN_STR_Office.Query()
                {
                    Tenant_RefID     = securityTicket.TenantID,
                    IsDeleted        = false,
                    CMN_STR_OfficeID = Parameter.OrgUnitID
                };

                var office = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Single();
                office.Office_Name                 = Parameter.OrgUnitName_DictID;
                office.Default_PhoneNumber         = Parameter.Telephone;
                office.DisplayImage_Document_RefID = Parameter.DisplayImage_Document_RefID;
                office.Default_Email               = Parameter.Email;
                office.Comment         = Parameter.Notes;
                office.Default_Website = Parameter.Website;
                if (Parameter.ParentID != null && Parameter.ParentID != Guid.Empty)
                {
                    office.Parent_RefID = Parameter.ParentID;
                }
                office.IsMedicalPractice = true;
                office.Save(Connection, Transaction);

                //*******************Medical practice type************************

                var medicalPractice2TypeQuery = new ORM_HEC_MedicalPractice_2_PracticeType.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID
                };
                var medicalPractice2Type = ORM_HEC_MedicalPractice_2_PracticeType.Query.Search(Connection, Transaction, medicalPractice2TypeQuery).ToList();

                foreach (var item in Parameter.MedicalPracticeType)
                {
                    if (item.IsDeleted)
                    {
                        foreach (var medicalPractice2TypeItem in medicalPractice2Type)
                        {
                            if (medicalPractice2TypeItem.HEC_MedicalPractice_Type_RefID == item.HEC_MedicalPractice_TypeID)
                            {
                                medicalPractice2TypeItem.Tenant_RefID = securityTicket.TenantID;
                                if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                                {
                                    medicalPractice2TypeItem.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                                }
                                else
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medicalPractice2TypeItem.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                }
                                medicalPractice2TypeItem.IsDeleted = true;
                                medicalPractice2TypeItem.Save(Connection, Transaction);
                                break;
                            }
                        }
                    }
                    else
                    {
                        ORM_HEC_MedicalPractice_2_PracticeType medPracticeType = null;
                        foreach (var medicalPractice2TypeItem in medicalPractice2Type)
                        {
                            if (medicalPractice2TypeItem.HEC_MedicalPractice_Type_RefID == item.HEC_MedicalPractice_TypeID)
                            {
                                medPracticeType = medicalPractice2TypeItem;
                                if (medPracticeType.HEC_MedicalPractice_RefID == Guid.Empty)
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    medPracticeType.Save(Connection, Transaction);
                                }
                                break;
                            }
                        }

                        if (medPracticeType == null)
                        {
                            medPracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                            medPracticeType.Tenant_RefID = securityTicket.TenantID;
                            medPracticeType.IsDeleted    = false;
                            medPracticeType.HEC_MedicalPractice_Type_RefID = item.HEC_MedicalPractice_TypeID;
                            if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                            {
                                medPracticeType.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                            }
                            else
                            {
                                var medicalPractice = new ORM_HEC_MedicalPractis();
                                medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                medicalPractice.IsDeleted             = false;
                                medicalPractice.Save(Connection, Transaction);
                                office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                office.Save(Connection, Transaction);
                                medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                            }
                            medPracticeType.Save(Connection, Transaction);
                        }
                        else
                        {
                            if (medPracticeType.IsDeleted)
                            {
                                medPracticeType.Tenant_RefID = securityTicket.TenantID;
                                medPracticeType.IsDeleted    = true;
                                if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                                {
                                    medPracticeType.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                                }
                                else
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                }
                                medPracticeType.Save(Connection, Transaction);
                            }
                        }
                    }
                }

                //*******************Save Spoken Languages************************

                var office_spoken_languages = new ORM_CMN_STR_Office_SpokenLanguage.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    Office_RefID = office.CMN_STR_OfficeID,
                    IsDeleted    = false
                };

                var officeSpokenLanguageQuery = ORM_CMN_STR_Office_SpokenLanguage.Query.Search(Connection, Transaction, office_spoken_languages);

                foreach (var item in Parameter.SpokenLanguage)
                {
                    ORM_CMN_STR_Office_SpokenLanguage officeSpokenLang = null;
                    foreach (var officeSpokenLanguageItem in officeSpokenLanguageQuery)
                    {
                        if (officeSpokenLanguageItem.Language_RefID == item.CMN_LanguageID && officeSpokenLanguageItem.Office_RefID == office.CMN_STR_OfficeID)
                        {
                            officeSpokenLang = officeSpokenLanguageItem;
                            break;
                        }
                    }
                    if (officeSpokenLang == null)
                    {
                        var officeSpokenLanguage = new ORM_CMN_STR_Office_SpokenLanguage();
                        officeSpokenLanguage.CMN_STR_Office_SpokenLanguageID = Guid.NewGuid();
                        officeSpokenLanguage.Language_RefID = item.CMN_LanguageID;
                        officeSpokenLanguage.IsDeleted      = item.IsDeleted;
                        officeSpokenLanguage.Office_RefID   = office.CMN_STR_OfficeID;
                        officeSpokenLanguage.Tenant_RefID   = securityTicket.TenantID;
                        officeSpokenLanguage.Save(Connection, Transaction);
                    }
                    else
                    {
                        officeSpokenLang.Language_RefID = item.CMN_LanguageID;
                        officeSpokenLang.IsDeleted      = item.IsDeleted;
                        officeSpokenLang.Save(Connection, Transaction);
                    }
                }


                //*******************Save Address************************

                foreach (var address in Parameter.Adresses)
                {
                    var Office_2_Address = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office_Address.Query()
                    {
                        IsBillingAddress  = address.IsBillingAddress,
                        IsShippingAddress = address.IsShippingAddress,
                        IsSpecialAddress  = address.IsSpecialAddress,
                        Office_RefID      = office.CMN_STR_OfficeID,
                        Tenant_RefID      = securityTicket.TenantID,
                        CMN_Address_RefID = address.AddressID,
                        IsDeleted         = false
                    }).SingleOrDefault();

                    if (Office_2_Address == null)
                    {
                        Office_2_Address = new ORM_CMN_STR_Office_Address();
                        Office_2_Address.CMN_STR_Office_AddressID = Guid.NewGuid();
                        Office_2_Address.IsBillingAddress         = address.IsBillingAddress;
                        Office_2_Address.IsShippingAddress        = address.IsShippingAddress;
                        Office_2_Address.IsSpecialAddress         = address.IsSpecialAddress;
                        Office_2_Address.CMN_Address_RefID        = address.AddressID;
                        Office_2_Address.Office_RefID             = office.CMN_STR_OfficeID;
                        Office_2_Address.Tenant_RefID             = securityTicket.TenantID;
                        Office_2_Address.Creation_Timestamp       = DateTime.Now;
                    }

                    Office_2_Address.IsDefault = address.IsDefault;

                    var Address = ORM_CMN_Address.Query.Search(Connection, Transaction, new ORM_CMN_Address.Query()
                    {
                        Tenant_RefID  = securityTicket.TenantID,
                        IsDeleted     = false,
                        CMN_AddressID = Office_2_Address.CMN_Address_RefID
                    }).SingleOrDefault();

                    if (Address == null)
                    {
                        Address = new ORM_CMN_Address();
                        Address.CMN_AddressID      = Office_2_Address.CMN_Address_RefID;
                        Address.Tenant_RefID       = securityTicket.TenantID;
                        Address.Creation_Timestamp = DateTime.Now;
                    }

                    if (address.IsDeleted)
                    {
                        Address.IsDeleted          = true;
                        Office_2_Address.IsDeleted = true;
                    }
                    else
                    {
                        Address.City_Name       = address.City;
                        Address.Street_Name     = address.Street_Name;
                        Address.Street_Number   = address.Street_Number;
                        Address.Country_ISOCode = address.CountryISO;
                        Address.Country_Name    = address.CountryName;
                        Address.City_PostalCode = address.ZIP;
                        if (address.IsDefault)
                        {
                            Address.Lattitude = address.Lattitude;
                            Address.Longitude = address.Longitude;
                        }
                    }
                    Office_2_Address.Save(Connection, Transaction);
                    Address.Save(Connection, Transaction);
                }


                //*******************AppointmentType************************

                foreach (var item in Parameter.AppoitmentType)
                {
                    var orgUnitToAppointmentTypeQuery = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query();
                    orgUnitToAppointmentTypeQuery.CMN_STR_Office_RefID        = Parameter.OrgUnitID;
                    orgUnitToAppointmentTypeQuery.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                    orgUnitToAppointmentTypeQuery.Tenant_RefID = securityTicket.TenantID;
                    orgUnitToAppointmentTypeQuery.IsDeleted    = false;

                    var orgUnitToAppointmentType = ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query.Search(Connection, Transaction, orgUnitToAppointmentTypeQuery).SingleOrDefault();

                    if (orgUnitToAppointmentType == null)
                    {
                        if (!item.IsDeleted)
                        {
                            orgUnitToAppointmentType = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability();
                            orgUnitToAppointmentType.PPS_TSK_Task_Template_OrganizationalUnitAvailabilityID = Guid.NewGuid();
                            orgUnitToAppointmentType.CMN_STR_Office_RefID        = Parameter.OrgUnitID;
                            orgUnitToAppointmentType.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                            orgUnitToAppointmentType.Creation_Timestamp          = DateTime.Now;
                            orgUnitToAppointmentType.Tenant_RefID = securityTicket.TenantID;
                            orgUnitToAppointmentType.Save(Connection, Transaction);
                        }
                    }
                    else
                    {
                        if (item.IsDeleted)
                        {
                            orgUnitToAppointmentType.IsDeleted = true;
                            orgUnitToAppointmentType.Save(Connection, Transaction);
                        }
                    }
                }


                //*******************Save Contact Person************************

                var responsiblePerson = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office_ResponsiblePerson.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    Office_RefID = office.CMN_STR_OfficeID
                }).Single();

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    Tenant_RefID           = securityTicket.TenantID,
                    IsDeleted              = false,
                    CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID
                }).Single();

                var businessParticpant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    CMN_BPT_BusinessParticipantID = employee.BusinessParticipant_RefID
                }).Single();
                businessParticpant.DisplayName = Parameter.ContactPerson.Title + " " + Parameter.ContactPerson.FirstName + " " + Parameter.ContactPerson.LastName;
                businessParticpant.Save(Connection, Transaction);

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                {
                    Tenant_RefID         = securityTicket.TenantID,
                    IsDeleted            = false,
                    CMN_PER_PersonInfoID = businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID
                }).Single();
                personInfo.Title     = Parameter.ContactPerson.Title;
                personInfo.FirstName = Parameter.ContactPerson.FirstName;
                personInfo.LastName  = Parameter.ContactPerson.LastName;
                personInfo.Save(Connection, Transaction);

                returnValue.Result = office.CMN_STR_OfficeID;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }