Пример #1
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
        }
Пример #2
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L6MRMS_SEtR_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();


            List <ORM_MRS_RUN_MeasurementRun_AccountDownloadCode> downloadCodes = ORM_MRS_RUN_MeasurementRun_AccountDownloadCode.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_AccountDownloadCode.Query()
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false,
                MeasurementRun_RefID = Parameter.ReadingSessionId
            });

            foreach (var downloadCode in downloadCodes)
            {
                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                var bpLoad = businessParticipant.Load(Connection, Transaction, downloadCode.Account_RefID);
                if (bpLoad.Status != FR_Status.Success)
                {
                    continue;
                }

                ORM_CMN_BPT_BusinessParticipant_AccessCode bpAccountCode = ORM_CMN_BPT_BusinessParticipant_AccessCode.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_AccessCode.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID
                }).SingleOrDefault();
                if (bpAccountCode == null)
                {
                    continue;
                }

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                var piLoad = personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                if (piLoad.Status != FR_Status.Success)
                {
                    continue;
                }

                //sending email

                string subject = Parameter.EmailSubjectTemplate;
                string body    = String.Format
                                 (
                    Parameter.EmailBodyTemplate,
                    personInfo.FirstName,
                    personInfo.LastName,
                    downloadCode.DownloadCode,
                    bpAccountCode.Code
                                 );
                EmailUtils.SendMail(personInfo.PrimaryEmail, subject, body);
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #3
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3US_SUAI_1642 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            returnValue.Status = FR_Status.Error_Internal;
            //Put your code here

            //EDIT
            if (Parameter.AccountID != null && Parameter.AccountID != Guid.Empty)
            {
                var item = new ORM_USR_Account();
                if (item.Load(Connection, Transaction, Parameter.AccountID) == null)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }

                ORM_CMN_PER_PersonInfo_2_Account.Query searchConnection = new CL1_CMN_PER.ORM_CMN_PER_PersonInfo_2_Account.Query();
                searchConnection.IsDeleted         = false;
                searchConnection.Tenant_RefID      = securityTicket.TenantID;
                searchConnection.USR_Account_RefID = Parameter.AccountID;

                ORM_CMN_PER_PersonInfo_2_Account personInfo2Account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, searchConnection).FirstOrDefault();

                if (personInfo2Account != null)
                {
                    ORM_CMN_PER_PersonInfo PersonInfo = new ORM_CMN_PER_PersonInfo();
                    PersonInfo.Load(Connection, Transaction, personInfo2Account.CMN_PER_PersonInfo_RefID);

                    if (PersonInfo != null)
                    {
                        PersonInfo.FirstName = Parameter.FirstName;
                        PersonInfo.LastName  = Parameter.LastName;

                        PersonInfo.Save(Connection, Transaction);

                        returnValue.Status = FR_Status.Success;
                        return(returnValue);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Пример #4
0
        protected static FR_L6WS_GSCDfSCID_1458 Execute(DbConnection Connection, DbTransaction Transaction, P_L6WS_GSCDfSCID_1458 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6WS_GSCDfSCID_1458();

            //Put your code here
            if (Parameter.ShoppingCartID == Guid.Empty)
            {
                return(null);
            }

            returnValue.Result = new L6WS_GSCDfSCID_1458();

            #region ShoppingCart

            returnValue.Result.ShoppingCart = cls_Get_ShoppingCart_for_ShoppingCartID.Invoke(Connection, Transaction, new P_L6WS_GSCfSCID_1448()
            {
                ShoppingCartID = Parameter.ShoppingCartID
            }, securityTicket).Result;
            if (returnValue.Result.ShoppingCart == null)
            {
                return(null);
            }
            #endregion

            #region ShoppingCart_Notes

            returnValue.Result.ShoppingCart_Notes = cls_Get_ShoppingCart_Notes_for_ShoppingCartID.Invoke(Connection, Transaction, new P_L5AWSAR_GSCNfSC_1454()
            {
                ShoppingCartID = Parameter.ShoppingCartID
            }, securityTicket).Result.OrderBy(i => i.UpdatedOn).ToArray();

            #endregion

            #region Articles

            ORM_ORD_PRC_ShoppingCart_Product.Query shoppingCartProductsQuery = new ORM_ORD_PRC_ShoppingCart_Product.Query();
            shoppingCartProductsQuery.ORD_PRC_ShoppingCart_RefID = returnValue.Result.ShoppingCart.ORD_PRC_ShoppingCartID;
            shoppingCartProductsQuery.IsDeleted    = false;
            shoppingCartProductsQuery.IsCanceled   = false;
            shoppingCartProductsQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_ORD_PRC_ShoppingCart_Product> productList = ORM_ORD_PRC_ShoppingCart_Product.Query.Search(Connection, Transaction, shoppingCartProductsQuery);

            List <Guid> articleIds = new List <Guid>();
            if (productList != null && productList.Count > 0)
            {
                articleIds.AddRange(productList.Select(i => i.CMN_PRO_Product_RefID));
            }

            List <L3AR_GAfAL_0942> articleInfos = new List <L3AR_GAfAL_0942>();

            if (articleIds.Count > 0)
            {
                articleInfos = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction,
                                                                       new P_L3AR_GAfAL_0942()
                {
                    ProductID_List = articleIds.ToArray()
                }, securityTicket).Result.ToList();
            }


            List <L6WS_GSCDfSCID_1458_Product> products = new List <L6WS_GSCDfSCID_1458_Product>();
            L6WS_GSCDfSCID_1458_Product        product;
            L3AR_GAfAL_0942 articleInfo;
            double          taxRate = 0;
            #region ORM and Querie objects
            ORM_CMN_PRO_Product     orm_product;
            ORM_CMN_SLS_Price.Query priceQuery;
            ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query taxAssignmentQuery;
            ORM_ACC_TAX_Tax orm_tax;
            #endregion
            foreach (var productItem in productList)
            {
                #region check procurement order date and number
                if (returnValue.Result.OrderDate == null || returnValue.Result.OrderDate.Ticks == 0)
                {
                    ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query shoppingCartOrderPositionQuery = new ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query();
                    shoppingCartOrderPositionQuery.IsDeleted    = false;
                    shoppingCartOrderPositionQuery.Tenant_RefID = securityTicket.TenantID;
                    shoppingCartOrderPositionQuery.ORD_PRC_ShoppingCart_Product_RefID = productItem.ORD_PRC_ShoppingCart_ProductID;
                    List <ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition> shoppingCartOrderPositionList = ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query.Search(Connection, Transaction, shoppingCartOrderPositionQuery);
                    foreach (var shoppingCartOrderPosition in shoppingCartOrderPositionList)
                    {
                        ORM_ORD_PRC_ProcurementOrder_Position procurementOrder_Position = new ORM_ORD_PRC_ProcurementOrder_Position();
                        var procurementOrder_PositionResult = procurementOrder_Position.Load(Connection, Transaction, shoppingCartOrderPosition.ORD_PRC_ProcurementOrder_Position_RefID);

                        if (procurementOrder_PositionResult.Status != FR_Status.Success || procurementOrder_Position.ORD_PRC_ProcurementOrder_PositionID == Guid.Empty)
                        {
                            continue;
                        }

                        ORM_ORD_PRC_ProcurementOrder_Header procurementOrder_Header = new ORM_ORD_PRC_ProcurementOrder_Header();
                        var procurementOrder_HeaderResult = procurementOrder_Header.Load(Connection, Transaction, procurementOrder_Position.ProcurementOrder_Header_RefID);

                        if (procurementOrder_HeaderResult.Status != FR_Status.Success || procurementOrder_Header.ORD_PRC_ProcurementOrder_HeaderID == Guid.Empty)
                        {
                            continue;
                        }

                        returnValue.Result.OrderDate   = procurementOrder_Header.ProcurementOrder_Date;
                        returnValue.Result.OrderNumber = procurementOrder_Header.ProcurementOrder_Number;
                        break;
                    }
                }
                #endregion

                #region get product
                orm_product = new ORM_CMN_PRO_Product();
                var productResult = orm_product.Load(Connection, Transaction, productItem.CMN_PRO_Product_RefID);
                if (productResult.Status != FR_Status.Success || orm_product.CMN_PRO_ProductID == Guid.Empty)
                {
                    continue;
                }
                #endregion

                #region get price
                ORM_CMN_PRO_SubscribedCatalog.Query catalogQuery = new ORM_CMN_PRO_SubscribedCatalog.Query();
                catalogQuery.Tenant_RefID = securityTicket.TenantID;
                catalogQuery.IsDeleted    = false;
                List <ORM_CMN_PRO_SubscribedCatalog> catalogList = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, catalogQuery);

                priceQuery = new ORM_CMN_SLS_Price.Query();
                priceQuery.CMN_PRO_Product_RefID = orm_product.CMN_PRO_ProductID;
                priceQuery.Tenant_RefID          = securityTicket.TenantID;
                priceQuery.IsDeleted             = false;
                List <ORM_CMN_SLS_Price> prices = ORM_CMN_SLS_Price.Query.Search(Connection, Transaction, priceQuery);
                ORM_CMN_SLS_Price        price  = prices.Where(i => catalogList.Select(j => j.SubscribedCatalog_PricelistRelease_RefID).Contains(i.PricelistRelease_RefID)).FirstOrDefault();
                #endregion

                #region get taxes
                taxRate            = 0;
                taxAssignmentQuery = new ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query();
                taxAssignmentQuery.Product_RefID = orm_product.CMN_PRO_ProductID;
                taxAssignmentQuery.Tenant_RefID  = securityTicket.TenantID;
                taxAssignmentQuery.IsDeleted     = false;
                List <ORM_CMN_PRO_Product_SalesTaxAssignmnet> taxAssignmentList = ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query.Search(Connection, Transaction, taxAssignmentQuery);

                foreach (var taxAssignment in taxAssignmentList)
                {
                    orm_tax = new ORM_ACC_TAX_Tax();
                    var taxResult = orm_tax.Load(Connection, Transaction, taxAssignment.ApplicableSalesTax_RefID);
                    if (taxResult.Status == FR_Status.Success && orm_tax.ACC_TAX_TaxeID != Guid.Empty)
                    {
                        taxRate += orm_tax.TaxRate;
                    }
                }
                #endregion

                #region set product item
                product = new L6WS_GSCDfSCID_1458_Product();
                product.CMN_PRO_Product_RefID = orm_product.CMN_PRO_ProductID;
                product.PriceAmount           = price == null ? 0 : (price.PriceAmount == null ? 0 : Double.Parse(price.PriceAmount.ToString()));
                product.TaxRate           = taxRate;
                product.Quantity          = productItem.Quantity.ToString();
                product.IsProductCanceled = productItem.IsCanceled;
                if (!String.IsNullOrEmpty(productItem.Comment))
                {
                    string[] comments = productItem.Comment.Split('@');
                    if (comments.Length == 2)
                    {
                        product.ProductComment = comments[1];
                    }
                }
                product.IsProductReplacementAllowed = productItem.IsProductReplacementAllowed;

                articleInfo = articleInfos.FirstOrDefault(i => i.CMN_PRO_ProductID == orm_product.CMN_PRO_ProductID);
                if (articleInfo != null)
                {
                    product.Product_Name    = articleInfo.Product_Name;
                    product.Product_Number  = articleInfo.Product_Number;
                    product.UnitAmount      = articleInfo.UnitAmount.ToString();
                    product.UnitIsoCode     = articleInfo.UnitIsoCode;
                    product.DossageFormName = articleInfo.DossageFormName;
                }
                #endregion

                products.Add(product);
            }

            returnValue.Result.Products = products.ToArray();

            #endregion

            #region Person info
            // current user
            ORM_CMN_PER_PersonInfo_2_Account.Query accountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
            accountQuery.USR_Account_RefID = securityTicket.AccountID;
            accountQuery.Tenant_RefID      = securityTicket.TenantID;
            accountQuery.IsDeleted         = false;
            ORM_CMN_PER_PersonInfo_2_Account account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();

            if (account != null)
            {
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID);
                if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    returnValue.Result.CurrentUser = personInfo.FirstName + " " + personInfo.LastName;
                }
            }

            #region Approved by user

            ORM_ORD_PRC_ShoppingCart_Status.Query stusesQuery = new ORM_ORD_PRC_ShoppingCart_Status.Query();
            stusesQuery.Tenant_RefID = securityTicket.TenantID;
            stusesQuery.IsDeleted    = false;
            List <ORM_ORD_PRC_ShoppingCart_Status> statuses       = ORM_ORD_PRC_ShoppingCart_Status.Query.Search(Connection, Transaction, stusesQuery);
            ORM_ORD_PRC_ShoppingCart_Status        approvedStatus = statuses.FirstOrDefault(i => i.GlobalPropertyMatchingID.Contains("approved"));

            if (approvedStatus != null)
            {
                ORM_ORD_PRC_ShoppingCartStatus_History.Query statusHistoryQuery = new ORM_ORD_PRC_ShoppingCartStatus_History.Query();
                statusHistoryQuery.Tenant_RefID = securityTicket.TenantID;
                statusHistoryQuery.IsDeleted    = false;
                statusHistoryQuery.ORD_PRC_ShoppingCart_RefID        = returnValue.Result.ShoppingCart.ORD_PRC_ShoppingCartID;
                statusHistoryQuery.ORD_PRC_ShoppingCart_Status_RefID = approvedStatus.ORD_PRC_ShoppingCart_StatusID;
                ORM_ORD_PRC_ShoppingCartStatus_History statusHistory = ORM_ORD_PRC_ShoppingCartStatus_History.Query.Search(Connection, Transaction, statusHistoryQuery).FirstOrDefault();
                if (statusHistory != null)
                {
                    accountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    accountQuery.USR_Account_RefID = statusHistory.PerformedBy_Account_RefID;
                    accountQuery.Tenant_RefID      = securityTicket.TenantID;
                    accountQuery.IsDeleted         = false;
                    account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();

                    if (account != null)
                    {
                        ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                        var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID);
                        if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty)
                        {
                            returnValue.Result.ApprovedByUser = personInfo.FirstName + " " + personInfo.LastName;
                            returnValue.Result.DateOfApproval = statusHistory.Creation_Timestamp;
                        }
                    }
                }
            }

            #endregion

            #endregion

            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
        }
Пример #6
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
        }
Пример #7
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_MD_SAU_1236 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            IAccountServiceProvider accountService;
            var _providerFactory = ProviderFactory.Instance;
            accountService = _providerFactory.CreateAccountServiceProvider();

            var accId = Guid.NewGuid();
            if (Parameter.UserID == Guid.Empty)
            {
                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    Person UserAccount = new Person();
                    UserAccount.FirstName = Parameter.FirstName;
                    UserAccount.LastName  = Parameter.LastName;
                    UserAccount.Title     = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title;
                    Account account = new Account();
                    account.Person       = UserAccount;
                    account.ID           = accId;
                    account.TenantID     = securityTicket.TenantID;
                    account.Email        = Parameter.LoginEmail;
                    account.PasswordHash = Parameter.inPassword;
                    account.Username     = usernameStr;
                    account.AccountType  = EAccountType.Standard;
                    account.Verified     = true;
                    accountService.CreateAccount(account, securityTicket.SessionTicket);
                    accountService.VerifyAccount(account.ID);

                    try
                    {
                        string emailTo  = Parameter.LoginEmail;
                        string appName  = WebConfigurationManager.AppSettings["mmAppUrl"];
                        var    prefix   = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://";
                        var    imageUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png";

                        var     email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/NewUserTemplate.html"));
                        var     subjectsJson   = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json"));
                        dynamic subjects       = Newtonsoft.Json.JsonConvert.DeserializeObject(subjectsJson);
                        var     subjectMail    = subjects["NewUserSubject"].ToString();

                        email_template = EmailTemplater.SetTemplateData(email_template, new
                        {
                            first_name = Parameter.FirstName,
                            salutation = Parameter.Salutation,
                            last_name  = Parameter.LastName,
                            title      = Parameter.Title,
                            password   = Parameter.inPasswordMail,
                            mm_app_url = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName,
                            medios_connect_logo_url = imageUrl
                        }, "{{", "}}");

                        //string mailFrom = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result.Email;
                        string mailFrom = WebConfigurationManager.AppSettings["mailFrom"];
                        EmailNotificationSenderUtil.SendEmail(mailFrom, emailTo, subjectMail, email_template);
                    }
                    catch (Exception ex)
                    {
                        LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Add new user: Email sending failed."), "EmailExceptions");
                    }
                    var userAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        USR_AccountID = accId
                    }).Single();


                    var businesParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = userAccountInfo.BusinessParticipant_RefID
                    }).SingleOrDefault();
                    if (businesParticipant != null)
                    {
                        businesParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastName;
                        businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                        businesParticipant.IsNaturalPerson        = true;
                        businesParticipant.Modification_Timestamp = DateTime.Now;
                        businesParticipant.Save(Connection, Transaction);

                        var companyInfoUser = new ORM_CMN_PER_PersonInfo();
                        companyInfoUser.IsDeleted            = false;
                        companyInfoUser.Tenant_RefID         = securityTicket.TenantID;
                        companyInfoUser.CMN_PER_PersonInfoID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        companyInfoUser.FirstName            = Parameter.FirstName;
                        companyInfoUser.LastName             = Parameter.LastName;
                        companyInfoUser.Salutation_General   = Parameter.Salutation;
                        companyInfoUser.Title = Parameter.Title;
                        companyInfoUser.Save(Connection, Transaction);

                        var communicationContact = new ORM_CMN_PER_CommunicationContact();
                        communicationContact.IsDeleted              = false;
                        communicationContact.Contact_Type           = Guid.NewGuid();
                        communicationContact.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        communicationContact.Content = Parameter.Email;
                        communicationContact.Save(Connection, Transaction);

                        var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType.IsDeleted    = false;
                        communicationContactType.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType.CMN_PER_CommunicationContact_TypeID = communicationContact.Contact_Type;
                        communicationContactType.Type = "Email";
                        communicationContactType.Save(Connection, Transaction);

                        var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                        communicationContactPhone.IsDeleted              = false;
                        communicationContactPhone.Contact_Type           = Guid.NewGuid();
                        communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                        communicationContactPhone.Modification_Timestamp = DateTime.Now;
                        communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        communicationContactPhone.Content = Parameter.Phone;
                        communicationContactPhone.Save(Connection, Transaction);

                        var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactTypePhone.IsDeleted    = false;
                        communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                        communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                        communicationContactTypePhone.Type = "Phone";
                        communicationContactTypePhone.Save(Connection, Transaction);

                        var accountAppSettings = new ORM_USR_Account_ApplicationSetting();
                        accountAppSettings.IsDeleted          = false;
                        accountAppSettings.Account_RefID      = accId;
                        accountAppSettings.Creation_Timestamp = DateTime.Now;
                        accountAppSettings.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettings.ItemValue          = Parameter.ReceiveNotification.ToString();
                        accountAppSettings.ApplicationSetting_Definition_RefID = Guid.NewGuid();
                        accountAppSettings.Save(Connection, Transaction);

                        var accountAppSettingsDefinitions = new ORM_USR_Account_ApplicationSetting_Definition();
                        accountAppSettingsDefinitions.IsDeleted          = false;
                        accountAppSettingsDefinitions.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettingsDefinitions.Creation_Timestamp = DateTime.Now;
                        accountAppSettingsDefinitions.USR_Account_ApplicationSetting_DefinitionID = accountAppSettings.ApplicationSetting_Definition_RefID;
                        accountAppSettingsDefinitions.ItemKey = "ReceiveNotification";
                        accountAppSettingsDefinitions.Save(Connection, Transaction);
                    }
                }
            }
            else
            { //Edit existing user
                accId = Parameter.UserID;
                var userAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                {
                    IsDeleted     = false,
                    Tenant_RefID  = securityTicket.TenantID,
                    USR_AccountID = Parameter.UserID
                }).Single();

                var businesParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_BPT_BusinessParticipantID = userAccountInfo.BusinessParticipant_RefID
                }).SingleOrDefault();
                if (businesParticipant != null)
                {
                    businesParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastName;
                    businesParticipant.Modification_Timestamp = DateTime.Now;
                    businesParticipant.Save(Connection, Transaction);

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                    {
                        IsDeleted            = false,
                        Tenant_RefID         = securityTicket.TenantID,
                        CMN_PER_PersonInfoID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID
                    }).SingleOrDefault();
                    if (personInfo != null)
                    {
                        personInfo.FirstName          = Parameter.FirstName;
                        personInfo.LastName           = Parameter.LastName;
                        personInfo.Salutation_General = Parameter.Salutation;
                        personInfo.Title = Parameter.Title;
                        personInfo.Save(Connection, Transaction);


                        var phone = cls_Get_Communication_Contact_Info_for_User_Person_Info.Invoke(Connection, Transaction, new P_MD_GCCIFUPID_1716()
                        {
                            CommunicationType = "Phone", PersonRefID = personInfo.CMN_PER_PersonInfoID
                        }, securityTicket).Result;
                        if (phone != null)
                        {
                            var communicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, new ORM_CMN_PER_CommunicationContact.Query()
                            {
                                IsDeleted        = false,
                                Tenant_RefID     = securityTicket.TenantID,
                                PersonInfo_RefID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                                CMN_PER_CommunicationContactID = phone.CMN_PER_CommunicationContactID
                            }).SingleOrDefault();
                            communicationContact.Content = Parameter.Phone;
                            communicationContact.Save(Connection, Transaction);
                        }
                        else
                        {
                            var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                            communicationContactPhone.IsDeleted              = false;
                            communicationContactPhone.Contact_Type           = Guid.NewGuid();
                            communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                            communicationContactPhone.Modification_Timestamp = DateTime.Now;
                            communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                            communicationContactPhone.Content = Parameter.Phone;
                            communicationContactPhone.Save(Connection, Transaction);

                            var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                            communicationContactTypePhone.IsDeleted    = false;
                            communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                            communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                            communicationContactTypePhone.Type = "Phone";
                            communicationContactTypePhone.Save(Connection, Transaction);
                        }


                        var email = cls_Get_Communication_Contact_Info_for_User_Person_Info.Invoke(Connection, Transaction, new P_MD_GCCIFUPID_1716()
                        {
                            CommunicationType = "Email", PersonRefID = personInfo.CMN_PER_PersonInfoID
                        }, securityTicket).Result;
                        if (email != null)
                        {
                            var communicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, new ORM_CMN_PER_CommunicationContact.Query()
                            {
                                IsDeleted        = false,
                                Tenant_RefID     = securityTicket.TenantID,
                                PersonInfo_RefID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                                CMN_PER_CommunicationContactID = email.CMN_PER_CommunicationContactID
                            }).SingleOrDefault();
                            communicationContact.Content = Parameter.Email;
                            communicationContact.Save(Connection, Transaction);
                        }
                        else
                        {
                            var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                            communicationContactPhone.IsDeleted              = false;
                            communicationContactPhone.Contact_Type           = Guid.NewGuid();
                            communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                            communicationContactPhone.Modification_Timestamp = DateTime.Now;
                            communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                            communicationContactPhone.Content = Parameter.Email;
                            communicationContactPhone.Save(Connection, Transaction);

                            var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                            communicationContactTypePhone.IsDeleted    = false;
                            communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                            communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                            communicationContactTypePhone.Type = "Email";
                            communicationContactTypePhone.Save(Connection, Transaction);
                        }
                    }

                    var appSettings = ORM_USR_Account_ApplicationSetting.Query.Search(Connection, Transaction, new ORM_USR_Account_ApplicationSetting.Query()
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        Account_RefID = accId
                    }).SingleOrDefault();

                    if (appSettings == null)
                    {
                        var accountAppSettings = new ORM_USR_Account_ApplicationSetting();
                        accountAppSettings.IsDeleted          = false;
                        accountAppSettings.Account_RefID      = accId;
                        accountAppSettings.Creation_Timestamp = DateTime.Now;
                        accountAppSettings.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettings.ItemValue          = Parameter.ReceiveNotification.ToString();
                        accountAppSettings.ApplicationSetting_Definition_RefID = Guid.NewGuid();
                        accountAppSettings.Save(Connection, Transaction);

                        var accountAppSettingsDefinitions = new ORM_USR_Account_ApplicationSetting_Definition();
                        accountAppSettingsDefinitions.IsDeleted          = false;
                        accountAppSettingsDefinitions.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettingsDefinitions.Creation_Timestamp = DateTime.Now;
                        accountAppSettingsDefinitions.USR_Account_ApplicationSetting_DefinitionID = accountAppSettings.ApplicationSetting_Definition_RefID;
                        accountAppSettingsDefinitions.ItemKey = "ReceiveNotification";
                        accountAppSettingsDefinitions.Save(Connection, Transaction);
                    }
                    else
                    {
                        appSettings.ItemValue = Parameter.ReceiveNotification.ToString();
                        appSettings.Save(Connection, Transaction);
                    }

                    var accountStatus = accountService.GetAccountStatusHistory(securityTicket.TenantID, Parameter.UserID).OrderBy(sth => sth.CreationTimestamp).Reverse().FirstOrDefault();
                    if (Parameter.isDeactivated == true)
                    {
                        if (accountStatus.Status != EAccountStatus.BANNED)
                        {
                            accountService.BanAccount(Parameter.UserID, "Konto wurde vom Administrator deaktiviert");
                        }
                    }
                    else
                    {
                        if (accountStatus.Status == EAccountStatus.BANNED)
                        {
                            accountService.UnbanAccount(Parameter.UserID);
                        }
                    }
                }
            }
            P_MD_SPtMU_1433 PSaveUserPermisions = new P_MD_SPtMU_1433();
            PSaveUserPermisions.AccountID = accId;
            PSaveUserPermisions.Role      = Parameter.isAdmin ? Properties.Settings.Default.MasterAccountMMApp : Properties.Settings.Default.RegularAccountMMApp;
            PSaveUserPermisions.GroupName = Properties.Settings.Default.MMAppGroup;
            cls_Save_Permisions_to_User.Invoke(Connection, Transaction, PSaveUserPermisions, securityTicket);
            return(returnValue);

            #endregion UserCode
        }
Пример #8
0
        public static void Save_Doctors_to_DB(Doctor_model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;

            if (cleanupConnection == true)
            {
                Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString);
                Connection.Open();
            }
            if (cleanupTransaction == true)
            {
                Transaction = Connection.BeginTransaction();
            }
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
                Guid   BusinessParticipantID         = Guid.NewGuid();
                Guid   personInfoID                  = Guid.NewGuid();
                Guid   PracticeCustomerID            = Guid.NewGuid();
                Guid   PracticeBusinessParticipantID = Guid.NewGuid();
                Guid   PracticeCompanyInfoID         = Guid.NewGuid();
                String PracticeName                  = "";
                Guid   BankAccountID                 = Guid.Empty;
                Guid   doctor_id    = Parameter.DoctorID;
                var    isOpPractice = false;

                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                //uncomment this if you've created account
                //  if (false)
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    try
                    {
                        var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            AccountSignInEmailAddress = Parameter.LoginEmail,
                        }).Single();

                        var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                        accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                        accountGroupQuery.IsDeleted                = false;
                        accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                        var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                        if (accountGroup == null)
                        {
                            accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                            accountGroup.Tenant_RefID             = securityTicket.TenantID;
                            accountGroup.Label                    = "mm.docconect.doc.app.group";
                            accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                            accountGroup.Creation_Timestamp       = DateTime.Now;
                            accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                            accountGroup.Save(Connection, Transaction);
                        }

                        var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).ToList();

                        List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>();
                        foreach (var item in PracticeAccount2UniversalProperty)
                        {
                            var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID
                            }).Single();
                            PracticeUniversalPropertyList.Add(PracticeUniversalProperty);
                        }
                        ;

                        P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522();
                        practiceAccountIDParameter.PracticeID = Parameter.PracticeID;

                        var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query();
                        practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID;
                        practiceAccountToFunctionLevelRightQ.Tenant_RefID  = securityTicket.TenantID;
                        practiceAccountToFunctionLevelRightQ.IsDeleted     = false;

                        var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault();

                        if (practiceAccountToFunctionLevelRight != null)
                        {
                            var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                            practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID;
                            practiceAccountFunctionLevelRightQ.IsDeleted    = false;
                            practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID;

                            var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault();

                            if (practiceAccountFunctionLevelRight != null)
                            {
                                isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice");
                            }
                        }

                        var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                        functionLevelRightQ.IsDeleted                = false;
                        functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                        var existingFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault();

                        var tempFunctionLevelRightID = Guid.Empty;

                        if (existingFunctionLevelRight == null)
                        {
                            ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                            functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                            functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                            functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                            functionLevelRight.Creation_Timestamp = DateTime.Now;

                            functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";
                            functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                            functionLevelRight.Save(Connection, Transaction);

                            tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                        }
                        else
                        {
                            tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID;
                        }

                        var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                        accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                        accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                        accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                        accountToFunctionLevelRight.Account_RefID            = doctorAccountInfo.USR_AccountID;
                        accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID;

                        accountToFunctionLevelRight.Save(Connection, Transaction);

                        var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

                        businessParticipantQ.IsDeleted    = false;
                        businessParticipantQ.Tenant_RefID = securityTicket.TenantID;
                        businessParticipantQ.CMN_BPT_BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;
                        BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;

                        var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();
                        DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                        DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                        DoctorBusinessParticipant.IsNaturalPerson        = true;
                        DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                        DoctorBusinessParticipant.Save(Connection, Transaction);
                        personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;


                        var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                        companyInfoPractice.IsDeleted            = false;
                        companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                        companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                        companyInfoPractice.FirstName            = Parameter.FirstName;
                        companyInfoPractice.LastName             = Parameter.LastNAme;
                        companyInfoPractice.Salutation_General   = Parameter.Salutation;
                        companyInfoPractice.Title = Parameter.Title;
                        companyInfoPractice.Save(Connection, Transaction);

                        var communicationContact = new ORM_CMN_PER_CommunicationContact();
                        communicationContact.IsDeleted              = false;
                        communicationContact.Contact_Type           = Guid.NewGuid();
                        communicationContact.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.PersonInfo_RefID       = personInfoID;
                        communicationContact.Content = Parameter.Email;
                        communicationContact.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID = communicationContact.Contact_Type;


                        var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType.IsDeleted    = false;
                        communicationContactType.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                        communicationContactType.Type = "Email";
                        communicationContactType.Save(Connection, Transaction);

                        var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                        communicationContact2.IsDeleted              = false;
                        communicationContact2.Contact_Type           = Guid.NewGuid();
                        communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact2.Modification_Timestamp = DateTime.Now;
                        communicationContact2.PersonInfo_RefID       = personInfoID;
                        communicationContact2.Content = Parameter.Phone;
                        communicationContact2.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                        var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType2.IsDeleted    = false;
                        communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                        communicationContactType2.Type = "Phone";
                        communicationContactType2.Save(Connection, Transaction);

                        var doctor = new ORM_HEC_Doctor();
                        doctor.HEC_DoctorID = Guid.NewGuid();
                        doctor.IsDeleted    = false;
                        doctor.Tenant_RefID = securityTicket.TenantID;
                        doctor.BusinessParticipant_RefID = BusinessParticipantID;
                        doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                        doctor.Account_RefID             = Parameter.account_id;

                        doctor.Save(Connection, Transaction);

                        doctor_id = doctor.HEC_DoctorID;

                        var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).Single();


                        var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                        organizationalunit_Staff.IsDeleted    = false;
                        organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                        organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                        organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                        organizationalunit_Staff.Save(Connection, Transaction);

                        var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                        {
                            IsDeleted              = false,
                            Tenant_RefID           = securityTicket.TenantID,
                            CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                        }).Single();
                        var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                        }).Single();

                        PracticeName = PracticeBusinessParticipant.DisplayName;
                        PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                        PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                        if (Parameter.IsUsePracticeBank)
                        {
                            var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                            }).Single();


                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            //end of save bank data if inherited from practice
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                                business2bankAccount.IsDeleted    = false;
                                business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                                business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                                business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                                business2bankAccount.Creation_Timestamp = DateTime.Now;
                                business2bankAccount.Save(Connection, Transaction);

                                var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                                bankAccountDoctor.IsDeleted             = false;
                                bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                                bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                                bankAccountDoctor.IBAN               = Parameter.IBAN;
                                bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                                bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                                bankAccountDoctor.Save(Connection, Transaction);

                                if (!String.IsNullOrEmpty(Parameter.Bank))
                                {
                                    var bank = new ORM_ACC_BNK_Bank();
                                    bank.IsDeleted          = false;
                                    bank.Tenant_RefID       = securityTicket.TenantID;
                                    bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                    bank.BICCode            = Parameter.Bic;
                                    bank.BankName           = Parameter.Bank;
                                    bank.Creation_Timestamp = DateTime.Now;
                                    bank.Save(Connection, Transaction);
                                }

                                BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                // end save bank data
                            }
                        }
                    }
                    catch
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                    DoctorBusinessParticipant.IsDeleted    = false;
                    DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                    DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                    DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                    DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                    DoctorBusinessParticipant.IsNaturalPerson        = true;
                    DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                    DoctorBusinessParticipant.Save(Connection, Transaction);
                    personInfoID          = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID;

                    var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                    companyInfoPractice.IsDeleted            = false;
                    companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                    companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                    companyInfoPractice.FirstName            = Parameter.FirstName;
                    companyInfoPractice.LastName             = Parameter.LastNAme;
                    companyInfoPractice.Salutation_General   = Parameter.Salutation;
                    companyInfoPractice.Title = Parameter.Title;
                    companyInfoPractice.Save(Connection, Transaction);

                    var communicationContact = new ORM_CMN_PER_CommunicationContact();
                    communicationContact.IsDeleted              = false;
                    communicationContact.Contact_Type           = Guid.NewGuid();
                    communicationContact.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact.Modification_Timestamp = DateTime.Now;
                    communicationContact.PersonInfo_RefID       = personInfoID;
                    communicationContact.Content = Parameter.Email;
                    communicationContact.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID = communicationContact.Contact_Type;

                    var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType.IsDeleted    = false;
                    communicationContactType.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                    communicationContactType.Type = "Email";
                    communicationContactType.Save(Connection, Transaction);

                    var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                    communicationContact2.IsDeleted              = false;
                    communicationContact2.Contact_Type           = Guid.NewGuid();
                    communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact2.Modification_Timestamp = DateTime.Now;
                    communicationContact2.PersonInfo_RefID       = personInfoID;
                    communicationContact2.Content = Parameter.Phone;
                    communicationContact2.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                    var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType2.IsDeleted    = false;
                    communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                    communicationContactType2.Type = "Phone";
                    communicationContactType2.Save(Connection, Transaction);

                    var doctor = new ORM_HEC_Doctor();
                    doctor.HEC_DoctorID = Guid.NewGuid();
                    doctor.IsDeleted    = false;
                    doctor.Tenant_RefID = securityTicket.TenantID;
                    doctor.BusinessParticipant_RefID = BusinessParticipantID;
                    doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                    doctor.Account_RefID             = Parameter.account_id;

                    doctor.Save(Connection, Transaction);

                    doctor_id = doctor.HEC_DoctorID;

                    var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).Single();


                    var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                    organizationalunit_Staff.IsDeleted    = false;
                    organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                    organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                    organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                    organizationalunit_Staff.Save(Connection, Transaction);


                    var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        IsDeleted              = false,
                        Tenant_RefID           = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                    }).Single();
                    var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                    }).Single();
                    PracticeName = PracticeBusinessParticipant.DisplayName;
                    PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                    PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    if (Parameter.IsUsePracticeBank == true)
                    {
                        var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                        }).Single();


                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        //end of save bank data if inherited from practice
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                            bankAccountDoctor.IsDeleted             = false;
                            bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                            bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                            bankAccountDoctor.IBAN               = Parameter.IBAN;
                            bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                            bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                            bankAccountDoctor.Save(Connection, Transaction);

                            if (!String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var bank = new ORM_ACC_BNK_Bank();
                                bank.IsDeleted          = false;
                                bank.Tenant_RefID       = securityTicket.TenantID;
                                bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                bank.BICCode            = Parameter.Bic;
                                bank.BankName           = Parameter.Bank;
                                bank.Creation_Timestamp = DateTime.Now;
                                bank.Save(Connection, Transaction);
                            }

                            BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            // end save bank data
                        }
                    }
                }
                var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query()
                {
                    IsDeleted           = false,
                    Tenant_RefID        = securityTicket.TenantID,
                    CompanyInfo_RefID   = PracticeCompanyInfoID,
                    Address_Description = "Standard address for billing, shipping",
                }).SingleOrDefault();



                Practice_Doctors_Model DPModel = new Practice_Doctors_Model();

                if (PracticeCompanyInfoAddress != null)
                {
                    var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID,
                    }).SingleOrDefault();
                    DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number;
                    DPModel.zip     = PracticeUCD.ZIP;
                    DPModel.city    = PracticeUCD.Town;
                }

                DPModel.account_status = "aktiv";
                DPModel.id             = doctor_id.ToString();

                var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim();

                DPModel.name              = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.name_untouched    = Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.bsnr_lanr         = Parameter.LANR.ToString();
                DPModel.autocomplete_name = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.salutation        = title;

                DPModel.type = "Doctor";

                DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;

                DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;


                DPModel.phone = Parameter.Phone;

                DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email;

                DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN;

                DPModel.bic = string.IsNullOrEmpty(Parameter.Bic) ? "" : Parameter.Bic;

                DPModel.bank_id             = BankAccountID.ToString();
                DPModel.bank_info_inherited = Parameter.IsUsePracticeBank;
                DPModel.aditional_info      = "";
                DPModel.contract            = 0;


                DPModel.tenantid = securityTicket.TenantID.ToString();
                DPModel.practice_name_for_doctor = PracticeName;
                DPModel.practice_for_doctor_id   = Parameter.PracticeID.ToString();

                DPModel.role = isOpPractice ? "op" : "ac";

                List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
                DPModelL.Add(DPModel);

                Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());

                #region Assignment to Contract

                var contractIvi = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    ContractName = "IVI-Vertrag"
                }).SingleOrDefault();
                if (contractIvi != null)
                {
                    Guid AssignmentID = Guid.NewGuid();
                    var  insuranceTobrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query()
                    {
                        Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false,
                    }).SingleOrDefault();
                    if (insuranceTobrokerContract != null)
                    {
                        AssignmentID = insuranceTobrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    else
                    {
                        var insuranceTobrokerContractNew = new ORM_HEC_CRT_InsuranceToBrokerContract();
                        insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID = Guid.NewGuid();
                        insuranceTobrokerContractNew.Creation_Timestamp         = DateTime.Now;
                        insuranceTobrokerContractNew.IsDeleted                  = false;
                        insuranceTobrokerContractNew.Tenant_RefID               = securityTicket.TenantID;
                        insuranceTobrokerContractNew.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID;
                        insuranceTobrokerContractNew.Save(Connection, Transaction);
                        AssignmentID = insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    var insuranceTobrokerContract2doctor = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctor();
                    insuranceTobrokerContract2doctor.Creation_Timestamp = DateTime.Now;
                    insuranceTobrokerContract2doctor.HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctorID = Guid.NewGuid();
                    insuranceTobrokerContract2doctor.InsuranceToBrokerContract_RefID = AssignmentID;
                    insuranceTobrokerContract2doctor.Tenant_RefID = securityTicket.TenantID;
                    insuranceTobrokerContract2doctor.IsDeleted    = false;
                    insuranceTobrokerContract2doctor.Doctor_RefID = doctor_id;
                    insuranceTobrokerContract2doctor.ValidFrom    = new DateTime(2013, 6, 15);
                    insuranceTobrokerContract2doctor.ValidThrough = DateTime.MinValue;
                    insuranceTobrokerContract2doctor.Save(Connection, Transaction);

                    P_DO_CDCD_1505 ParameterDoctorID = new P_DO_CDCD_1505();
                    ParameterDoctorID.DoctorID = doctor_id;
                    var data = cls_Get_Doctor_Contract_Numbers.Invoke(Connection, Transaction, ParameterDoctorID, securityTicket).Result;

                    int DoctorContracts = data.Count();
                    Doctor_Contracts ParameterDoctor = new Doctor_Contracts();
                    ParameterDoctor.DocID = doctor_id;

                    Practice_Doctors_Model DoctorFound = Get_Doctors_for_PracticeID.Set_Contract_Number_for_DoctorID(ParameterDoctor, securityTicket);

                    if (DoctorFound != null)
                    {
                        List <Practice_Doctors_Model> DoctorFoundL = new List <Practice_Doctors_Model>();
                        DoctorFound.contract = DoctorContracts;
                        DoctorFoundL.Add(DoctorFound);
                        Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DoctorFoundL, securityTicket.TenantID.ToString());
                    }


                    P_DO_GPIDfDID_1353 ParametarDocID = new P_DO_GPIDfDID_1353();
                    ParametarDocID.DoctorID = doctor_id;
                    DO_GPIDfDID_1353[] data2 = cls_Get_PracticeID_for_DoctorID.Invoke(Connection, Transaction, ParametarDocID, securityTicket).Result;

                    P_DO_GCfPID_1507 ParametarPractice = new P_DO_GCfPID_1507();

                    ParametarPractice.PracticeID = data2.First().HEC_MedicalPractiseID;
                    DO_GCfPID_1507[] Contracts       = cls_Get_all_Doctors_Contract_Assignment_for_PracticeID.Invoke(Connection, Transaction, ParametarPractice, securityTicket).Result;
                    int NumberOfContractsForPractice = Contracts.Count();
                    Practice_Doctors_Model practice  = new Practice_Doctors_Model();
                    practice.id = ParametarPractice.PracticeID.ToString();

                    Practice_Doctors_Model        PracticeFound = Get_Doctors_for_PracticeID.Get_Practice_for_PracticeID(practice, securityTicket);
                    List <Practice_Doctors_Model> practiceL     = new List <Practice_Doctors_Model>();
                    PracticeFound.contract = NumberOfContractsForPractice;
                    practiceL.Add(PracticeFound);
                    Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(practiceL, securityTicket.TenantID.ToString());
                }
                #endregion



                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
            }



            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }
        }
Пример #9
0
        public static void Save_Patients_to_DB(Patient_Model_xls Parameter, bool create_consents, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;
            Guid          patient_id         = Guid.NewGuid();

            if (cleanupConnection == true)
            {
                Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString);
                Connection.Open();
            }
            if (cleanupTransaction == true)
            {
                Transaction = Connection.BeginTransaction();
            }

            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");

                ORM_HEC_Patient patients = new ORM_HEC_Patient();
                patients.HEC_PatientID                     = Guid.NewGuid();
                patients.Tenant_RefID                      = securityTicket.TenantID;
                patients.Creation_Timestamp                = DateTime.Now;
                patients.Modification_Timestamp            = DateTime.Now;
                patients.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid();
                patients.Save(Connection, Transaction);
                patient_id = patients.HEC_PatientID;

                ORM_CMN_BPT_BusinessParticipant businesParticipantPatient = new ORM_CMN_BPT_BusinessParticipant();
                businesParticipantPatient.CMN_BPT_BusinessParticipantID = patients.CMN_BPT_BusinessParticipant_RefID;
                businesParticipantPatient.Tenant_RefID           = securityTicket.TenantID;
                businesParticipantPatient.Creation_Timestamp     = DateTime.Now;
                businesParticipantPatient.Modification_Timestamp = DateTime.Now;
                businesParticipantPatient.IsNaturalPerson        = true;
                businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businesParticipantPatient.Save(Connection, Transaction);
                int PatientSex = 0;
                switch (Parameter.sex)
                {
                case "M":
                    PatientSex = 0;
                    break;

                case "W":
                    PatientSex = 1;
                    break;

                case "o.A.":
                    PatientSex = 2;
                    break;
                }

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID   = businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Tenant_RefID           = securityTicket.TenantID;
                personInfo.Creation_Timestamp     = DateTime.Now;
                personInfo.Modification_Timestamp = DateTime.Now;
                personInfo.FirstName = Parameter.name;
                personInfo.LastName  = Parameter.LastName;
                personInfo.BirthDate = Parameter.birthday;
                personInfo.Gender    = PatientSex;
                personInfo.Save(Connection, Transaction);

                ORM_HEC_Patient_MedicalPractice medical_practice_to_patient = new ORM_HEC_Patient_MedicalPractice();
                medical_practice_to_patient.HEC_Patient_MedicalPracticeID = Guid.NewGuid();
                medical_practice_to_patient.HEC_Patient_RefID             = patients.HEC_PatientID;
                medical_practice_to_patient.HEC_MedicalPractices_RefID    = Guid.Parse(Parameter.practice_id);//
                medical_practice_to_patient.Tenant_RefID       = securityTicket.TenantID;
                medical_practice_to_patient.Creation_Timestamp = DateTime.Now;
                medical_practice_to_patient.Save(Connection, Transaction);


                var medicalPracticeQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
                medicalPracticeQuery.IsDeleted    = false;
                medicalPracticeQuery.Tenant_RefID = securityTicket.TenantID;

                var HIPList = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, medicalPracticeQuery).ToList();

                if (Parameter.isPrivatelyInsured)
                {
                    Parameter.health_insurance_providerNumber = "000000000";
                }

                var GetHip = HIPList.Where(hp => hp.HealthInsurance_IKNumber == Parameter.health_insurance_providerNumber).SingleOrDefault();
                if (GetHip == null)
                {
                    var businessParticipantHIP = new ORM_CMN_BPT_BusinessParticipant();
                    businessParticipantHIP.IsCompany              = true;
                    businessParticipantHIP.Tenant_RefID           = securityTicket.TenantID;
                    businessParticipantHIP.Modification_Timestamp = DateTime.Now;
                    businessParticipantHIP.DisplayName            = Parameter.health_insurance_provider;

                    businessParticipantHIP.Save(Connection, Transaction);

                    GetHip = new ORM_HEC_HIS_HealthInsurance_Company();
                    GetHip.Tenant_RefID = securityTicket.TenantID;
                    GetHip.CMN_BPT_BusinessParticipant_RefID = businessParticipantHIP.CMN_BPT_BusinessParticipantID;
                    GetHip.HealthInsurance_IKNumber          = String.IsNullOrEmpty(Parameter.health_insurance_provider) ? "privat versichert" : Parameter.health_insurance_provider;

                    GetHip.Save(Connection, Transaction);
                }

                ORM_HEC_Patient_HealthInsurance patientHealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                patientHealthInsurance.HEC_Patient_HealthInsurancesID = Guid.NewGuid();
                patientHealthInsurance.Patient_RefID                     = patients.HEC_PatientID;
                patientHealthInsurance.HealthInsurance_Number            = Parameter.insurance_id;     //
                patientHealthInsurance.Tenant_RefID                      = securityTicket.TenantID;
                patientHealthInsurance.InsuranceStateCode                = Parameter.insurance_status; //
                patientHealthInsurance.HIS_HealthInsurance_Company_RefID = GetHip.HEC_HealthInsurance_CompanyID;
                patientHealthInsurance.Save(Connection, Transaction);

                #region import Patient to Elastic
                Patient_Model patientModel = new Patient_Model();


                patientModel.birthday                  = Parameter.birthday;
                patientModel.birthday_string           = Parameter.birthday.ToString("dd.MM.yyyy");
                patientModel.name                      = Parameter.LastName + ", " + Parameter.name;
                patientModel.health_insurance_provider = String.IsNullOrEmpty(Parameter.health_insurance_provider) ? "privat versichert" : Parameter.health_insurance_provider;
                patientModel.name_with_birthdate       = Parameter.name + " " + Parameter.LastName + " (" + Parameter.birthday.ToString("dd.MM.yyyy") + ")";
                patientModel.id               = patients.HEC_PatientID.ToString();
                patientModel.insurance_id     = String.IsNullOrEmpty(Parameter.insurance_id) ? "-" : Parameter.insurance_id;
                patientModel.insurance_status = String.IsNullOrEmpty(Parameter.insurance_status) ? "-" : Parameter.insurance_status;
                patientModel.practice_id      = Parameter.practice_id.ToString();

                if (PatientSex == 0)
                {
                    patientModel.sex = "M";
                }
                else if (PatientSex == 1)
                {
                    patientModel.sex = "W";
                }
                else if (PatientSex == 2)
                {
                    patientModel.sex = "o.A.";
                }

                Add_New_Patient.Import_Patients_to_ElasticDB(patientModel, securityTicket.TenantID.ToString());
                if (create_consents)
                {
                    #region Participation Consent
                    var contractIvi = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        ContractName = "IVI-Vertrag"
                    }).SingleOrDefault();

                    if (contractIvi != null)
                    {
                        var InsuranceToBrokerContractQuery = new ORM_HEC_CRT_InsuranceToBrokerContract.Query();
                        InsuranceToBrokerContractQuery.Tenant_RefID = securityTicket.TenantID;
                        InsuranceToBrokerContractQuery.IsDeleted    = false;
                        InsuranceToBrokerContractQuery.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID;

                        ORM_HEC_CRT_InsuranceToBrokerContract InsuranceToBrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, InsuranceToBrokerContractQuery).Single();

                        List <DateTime> TimeFrom = new List <DateTime>();
                        DateTime        time1    = new DateTime(2013, 6, 15);
                        DateTime        time2    = new DateTime(2014, 6, 15);
                        DateTime        time3    = new DateTime(2015, 6, 15);

                        TimeFrom.Add(time1);
                        TimeFrom.Add(time2);
                        TimeFrom.Add(time3);
                        foreach (var date in TimeFrom)
                        {
                            ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient InsuranceToBrokerContract_ParticipatingPatient = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient();
                            InsuranceToBrokerContract_ParticipatingPatient.HEC_CRT_InsuranceToBrokerContract_ParticipatingPatientID = Guid.NewGuid();
                            InsuranceToBrokerContract_ParticipatingPatient.InsuranceToBrokerContract_RefID = InsuranceToBrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                            InsuranceToBrokerContract_ParticipatingPatient.Creation_Timestamp     = DateTime.Now;
                            InsuranceToBrokerContract_ParticipatingPatient.Modification_Timestamp = DateTime.Now;
                            InsuranceToBrokerContract_ParticipatingPatient.Tenant_RefID           = securityTicket.TenantID;
                            InsuranceToBrokerContract_ParticipatingPatient.ValidFrom     = date;
                            InsuranceToBrokerContract_ParticipatingPatient.ValidThrough  = DateTime.MinValue;
                            InsuranceToBrokerContract_ParticipatingPatient.Patient_RefID = patient_id;
                            InsuranceToBrokerContract_ParticipatingPatient.Save(Connection, Transaction);

                            Patient_Model patientModel2 = new Patient_Model();
                            patientModel2 = Retrieve_Patients.Get_Patient_for_PatientID(patient_id.ToString(), securityTicket);

                            var InsuranceToBrokerContract_ParticipatingPatientQuery = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query();
                            InsuranceToBrokerContract_ParticipatingPatientQuery.IsDeleted     = false;
                            InsuranceToBrokerContract_ParticipatingPatientQuery.Tenant_RefID  = securityTicket.TenantID;
                            InsuranceToBrokerContract_ParticipatingPatientQuery.Patient_RefID = patient_id;

                            var allInsuranceToBrokerContract_ParticipatingPatient = ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query.Search(Connection, Transaction, InsuranceToBrokerContract_ParticipatingPatientQuery).ToList();
                            var latest_participation_date = allInsuranceToBrokerContract_ParticipatingPatient.OrderByDescending(m => m.ValidFrom).FirstOrDefault();

                            patientModel2.participation_consent_from = latest_participation_date.ValidFrom;
                            patientModel2.participation_consent_to   = latest_participation_date.ValidThrough;
                            patientModel2.has_participation_consent  = true;

                            Add_New_Patient.Import_Patients_to_ElasticDB(patientModel2, securityTicket.TenantID.ToString());
                        }
                    }
                }

                #endregion
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }

            #endregion
        }
Пример #10
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PH_SP_1226 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_Pharmacy item = new ORM_HEC_Pharmacy();


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

                #region Delete

                if (Parameter.IsDeleted)
                {
                    //Contact person data finding and deleting
                    var query_BusinessParticipant_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                    query_BusinessParticipant_ContactPerson_del.Tenant_RefID = item.Tenant_RefID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson_del).First();
                    found_BusinessParticipant_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;

                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_BusinessParticipant_ContactPerson_del.Save(Connection, Transaction);
                    found_CommunicationContact_del.Save(Connection, Transaction);
                    found_PersonInfo_del.Save(Connection, Transaction);


                    //Company (pharmacy) finding and deleting

                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    ORM_CMN_COM_CompanyInfo found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    var query_CompanyContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_CompanyContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    ORM_CMN_UniversalContactDetail found_CompanyContactDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails_del).First();
                    found_CompanyContactDetails_del.IsDeleted = true;

                    var query_BusinessParticipant_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company_del).First();
                    found_BusinessParticipant_Company_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);
                    found_CompanyContactDetails_del.Save(Connection, Transaction);
                    found_BusinessParticipant_Company_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_PharmacyID));
                }

                #endregion

                #region Edit

                //Contact person data finding and edit

                var query_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_ContactPerson.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                query_BusinessParticipant_ContactPerson.Tenant_RefID = item.Tenant_RefID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant();
                if (item.ContactPerson_BusinessParticipant_RefID != null && item.ContactPerson_BusinessParticipant_RefID != Guid.Empty)
                {
                    found_BusinessParticipant_ContactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson).First();
                }
                else
                {
                    found_BusinessParticipant_ContactPerson = null;
                }
                if (found_BusinessParticipant_ContactPerson != null)
                {
                    var query_PersonInfo = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo).First();
                    found_PersonInfo.FirstName    = Parameter.ContactFirstName;
                    found_PersonInfo.LastName     = Parameter.ContactLastName;
                    found_PersonInfo.PrimaryEmail = Parameter.ContactEmail;

                    var query_CommunicationContact = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact.PersonInfo_RefID = found_PersonInfo.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact).First();
                    found_CommunicationContact.Content = Parameter.ContactPhoneNumber;

                    found_CommunicationContact.Save(Connection, Transaction);
                    found_PersonInfo.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                    Guid businessParticipantID = Guid.NewGuid();

                    contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                    contactPerson.IsCompany          = false;
                    contactPerson.IsNaturalPerson    = true;
                    contactPerson.IsTenant           = false;
                    contactPerson.Creation_Timestamp = DateTime.Now;
                    contactPerson.Tenant_RefID       = securityTicket.TenantID;

                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                    //person info
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    Guid personInfoID = Guid.NewGuid();

                    contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                    contactPerson.Save(Connection, Transaction);

                    personInfo.CMN_PER_PersonInfoID = personInfoID;
                    personInfo.FirstName            = Parameter.ContactFirstName;
                    personInfo.LastName             = Parameter.ContactLastName;
                    personInfo.PrimaryEmail         = Parameter.ContactEmail;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Tenant_RefID         = securityTicket.TenantID;

                    personInfo.Save(Connection, Transaction);

                    //Communication Contact
                    ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                    communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                    communicationContacts.PersonInfo_RefID   = personInfoID;
                    communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                    communicationContacts.Content            = Parameter.ContactPhoneNumber;
                    communicationContacts.Creation_Timestamp = DateTime.Now;
                    communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                    communicationContacts.Save(Connection, Transaction);


                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;
                    item.Save(Connection, Transaction);
                }

                //Company (pharmacy) finding and edit

                var query_CompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                query_CompanyInfo.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                ORM_CMN_COM_CompanyInfo found_CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo).First();

                var query_CompanyContactDetails = new ORM_CMN_UniversalContactDetail.Query();
                query_CompanyContactDetails.CMN_UniversalContactDetailID = found_CompanyInfo.Contact_UCD_RefID;

                ORM_CMN_UniversalContactDetail found_CompanyContactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails).FirstOrDefault();
                if (found_CompanyContactDetails != null)
                {
                    found_CompanyContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    found_CompanyContactDetails.Contact_Email     = Parameter.MainEmail;
                    found_CompanyContactDetails.Street_Name       = Parameter.Street;
                    found_CompanyContactDetails.Street_Number     = Parameter.Number;
                    found_CompanyContactDetails.Street_Name_Line2 = Parameter.Street2;
                    found_CompanyContactDetails.Town = Parameter.Town;
                    found_CompanyContactDetails.ZIP  = Parameter.ZIP;
                    found_CompanyContactDetails.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                    universalContactDetails.CMN_UniversalContactDetailID = Guid.NewGuid();
                    universalContactDetails.IsCompany         = true;
                    universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    universalContactDetails.Street_Name       = Parameter.Street;
                    universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                    universalContactDetails.Street_Number     = Parameter.Number;
                    universalContactDetails.Contact_Email     = Parameter.MainEmail;
                    universalContactDetails.ZIP          = Parameter.ZIP;
                    universalContactDetails.Town         = Parameter.Town;
                    universalContactDetails.Tenant_RefID = securityTicket.TenantID;


                    universalContactDetails.Save(Connection, Transaction);

                    found_CompanyInfo.Contact_UCD_RefID = universalContactDetails.CMN_UniversalContactDetailID;
                    found_CompanyInfo.Save(Connection, Transaction);
                }

                var query_BusinessParticipant_Company = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_Company.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo.CMN_COM_CompanyInfoID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company).First();
                found_BusinessParticipant_Company.DisplayName = Parameter.PharmacyName;


                found_BusinessParticipant_Company.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                #region Save

                item.HEC_PharmacyID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;

                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactFirstName;
                personInfo.LastName             = Parameter.ContactLastName;
                personInfo.PrimaryEmail         = Parameter.ContactEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);

                //ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                //Guid companyInfoID = Guid.NewGuid();

                ORM_CMN_COM_CompanyInfo extCompanyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid extCompanyInfoID = Guid.NewGuid();
                extCompanyInfo.CMN_COM_CompanyInfoID = extCompanyInfoID;
                Guid contactUCDID = Guid.NewGuid();
                extCompanyInfo.Contact_UCD_RefID  = contactUCDID;
                extCompanyInfo.Creation_Timestamp = DateTime.Now;
                extCompanyInfo.Tenant_RefID       = securityTicket.TenantID;

                item.Ext_CompanyInfo_RefID = extCompanyInfoID;

                ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                universalContactDetails.CMN_UniversalContactDetailID = contactUCDID;
                universalContactDetails.IsCompany         = true;
                universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                universalContactDetails.Street_Name       = Parameter.Street;
                universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                universalContactDetails.Street_Number     = Parameter.Number;
                universalContactDetails.Contact_Email     = Parameter.MainEmail;
                universalContactDetails.ZIP          = Parameter.ZIP;
                universalContactDetails.Town         = Parameter.Town;
                universalContactDetails.Tenant_RefID = securityTicket.TenantID;

                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PharmacyName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = extCompanyInfoID;

                extCompany.Save(Connection, Transaction);
                extCompanyInfo.Save(Connection, Transaction);
                universalContactDetails.Save(Connection, Transaction);
                item.Save(Connection, Transaction);

                returnValue.Result = item.HEC_PharmacyID;
                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #11
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SBBVP_1223 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_Patient patient = new ORM_HEC_Patient();
            if (Parameter.HEC_PatientID != Guid.Empty)
            {
                var result = patient.Load(Connection, Transaction, Parameter.HEC_PatientID);
                if (result.Status != FR_Status.Success || patient.HEC_PatientID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            patient.IsPatientParticipationPolicyValidated = Parameter.HasFulfilledParticipationPolicyRequirements;
            patient.PatientComment = Parameter.Comment;
            patient.Tenant_RefID   = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (patient.CMN_BPT_BusinessParticipant_RefID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, patient.CMN_BPT_BusinessParticipant_RefID);
                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.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;


            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                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.FirstName          = Parameter.FirstName;
            person.LastName           = Parameter.LastName;
            person.PrimaryEmail       = Parameter.Mail;
            person.Tenant_RefID       = securityTicket.TenantID;
            person.Salutation_General = Parameter.Salutation;
            person.Save(Connection, Transaction);

            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.Save(Connection, Transaction);

            patient.CMN_BPT_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            patient.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact.Query contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.IsDeleted        = false;
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            var contactQueryRes = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, contactQuery);
            ORM_CMN_PER_CommunicationContact contactPhone = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Phone);
            ORM_CMN_PER_CommunicationContact contactFax   = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Fax);

            if (contactPhone == null)
            {
                contactPhone = new ORM_CMN_PER_CommunicationContact();
                contactPhone.Contact_Type     = STLD_ContactTypes.Phone;
                contactPhone.Tenant_RefID     = securityTicket.TenantID;
                contactPhone.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            }
            contactPhone.Content = Parameter.Phone;
            contactPhone.Save(Connection, Transaction);

            if (contactFax == null)
            {
                contactFax                  = new ORM_CMN_PER_CommunicationContact();
                contactFax.Content          = Parameter.Fax;
                contactFax.Contact_Type     = STLD_ContactTypes.Fax;
                contactFax.Tenant_RefID     = securityTicket.TenantID;
                contactFax.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contactFax.Save(Connection, Transaction);
            }
            contactFax.Content = Parameter.Fax;
            contactFax.Save(Connection, Transaction);

            ORM_HEC_Patient_HealthInsurance.Query Patient_HealthInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query();
            Patient_HealthInsuranceQuery.Tenant_RefID  = securityTicket.TenantID;
            Patient_HealthInsuranceQuery.IsDeleted     = false;
            Patient_HealthInsuranceQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_Patient_HealthInsurance Patient_HealthInsurance;
            var Patient_HealthInsuranceQueryRes = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, Patient_HealthInsuranceQuery);
            if (Patient_HealthInsuranceQueryRes.Count == 1)
            {
                Patient_HealthInsurance = Patient_HealthInsuranceQueryRes[0];
            }
            else
            {
                Patient_HealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                Patient_HealthInsurance.Patient_RefID = patient.HEC_PatientID;
                Patient_HealthInsurance.Tenant_RefID  = securityTicket.TenantID;
                Patient_HealthInsurance.IsPrimary     = true;
            }
            Patient_HealthInsurance.HealthInsurance_Number = Parameter.HealthcareNumber;
            Patient_HealthInsurance.Save(Connection, Transaction);

            ORM_HEC_STU_Study_ParticipatingPatient.Query Study_ParticipatingPatientsQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query();
            Study_ParticipatingPatientsQuery.Tenant_RefID  = securityTicket.TenantID;
            Study_ParticipatingPatientsQuery.IsDeleted     = false;
            Study_ParticipatingPatientsQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_STU_Study_ParticipatingPatient Study_ParticipatingPatients;

            var Study_ParticipatingPatientsQueryRes = ORM_HEC_STU_Study_ParticipatingPatient.Query.Search(Connection, Transaction, Study_ParticipatingPatientsQuery);
            if (Study_ParticipatingPatientsQueryRes.Count == 1)
            {
                Study_ParticipatingPatients = Study_ParticipatingPatientsQueryRes[0];
            }
            else
            {
                Study_ParticipatingPatients = new ORM_HEC_STU_Study_ParticipatingPatient();
                Study_ParticipatingPatients.Patient_RefID = patient.HEC_PatientID;
                Study_ParticipatingPatients.Tenant_RefID  = securityTicket.TenantID;
            }
            Study_ParticipatingPatients.HasFulfilledParticipationPolicyRequirements = Parameter.HasFulfilledParticipationPolicyRequirements;
            Study_ParticipatingPatients.Save(Connection, Transaction);

            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }
Пример #12
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SMSP_1548 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var             returnValue = new FR_Guid();
            ORM_HEC_Patient patient     = new ORM_HEC_Patient();
            if (Parameter.HEC_PatientID != Guid.Empty)
            {
                var result = patient.Load(Connection, Transaction, Parameter.HEC_PatientID);
                if (result.Status != FR_Status.Success || patient.HEC_PatientID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            patient.IsPatientParticipationPolicyValidated = Parameter.HasFulfilledParticipationPolicyRequirements;
            patient.PatientComment = Parameter.Comment;
            patient.Tenant_RefID   = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (patient.CMN_BPT_BusinessParticipant_RefID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, patient.CMN_BPT_BusinessParticipant_RefID);
                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.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;


            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                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.FirstName          = Parameter.FirstName;
            person.LastName           = Parameter.LastName;
            person.PrimaryEmail       = Parameter.Mail;
            person.Tenant_RefID       = securityTicket.TenantID;
            person.Salutation_General = Parameter.Salutation;
            person.Save(Connection, Transaction);

            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.Save(Connection, Transaction);

            patient.CMN_BPT_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            patient.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact.Query contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.IsDeleted        = false;
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            var contactQueryRes = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, contactQuery);
            ORM_CMN_PER_CommunicationContact contactPhone = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Phone);
            ORM_CMN_PER_CommunicationContact contactFax   = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Fax);

            if (contactPhone == null)
            {
                contactPhone = new ORM_CMN_PER_CommunicationContact();
                contactPhone.Contact_Type     = STLD_ContactTypes.Phone;
                contactPhone.Tenant_RefID     = securityTicket.TenantID;
                contactPhone.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            }
            contactPhone.Content = Parameter.Phone;
            contactPhone.Save(Connection, Transaction);

            if (contactFax == null)
            {
                contactFax                  = new ORM_CMN_PER_CommunicationContact();
                contactFax.Content          = Parameter.Fax;
                contactFax.Contact_Type     = STLD_ContactTypes.Fax;
                contactFax.Tenant_RefID     = securityTicket.TenantID;
                contactFax.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contactFax.Save(Connection, Transaction);
            }
            contactFax.Content = Parameter.Fax;
            contactFax.Save(Connection, Transaction);

            ORM_HEC_Patient_HealthInsurance.Query Patient_HealthInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query();
            Patient_HealthInsuranceQuery.Tenant_RefID  = securityTicket.TenantID;
            Patient_HealthInsuranceQuery.IsDeleted     = false;
            Patient_HealthInsuranceQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_Patient_HealthInsurance Patient_HealthInsurance;
            var Patient_HealthInsuranceQueryRes = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, Patient_HealthInsuranceQuery);
            if (Patient_HealthInsuranceQueryRes.Count == 1)
            {
                Patient_HealthInsurance = Patient_HealthInsuranceQueryRes[0];
            }
            else
            {
                Patient_HealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                Patient_HealthInsurance.Patient_RefID = patient.HEC_PatientID;
                Patient_HealthInsurance.Tenant_RefID  = securityTicket.TenantID;
                Patient_HealthInsurance.IsPrimary     = true;
            }
            Patient_HealthInsurance.HealthInsurance_Number = Parameter.HealthcareNumber;
            Patient_HealthInsurance.Save(Connection, Transaction);

            ORM_HEC_STU_Study_ParticipatingPatient.Query Study_ParticipatingPatientsQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query();
            Study_ParticipatingPatientsQuery.Tenant_RefID  = securityTicket.TenantID;
            Study_ParticipatingPatientsQuery.IsDeleted     = false;
            Study_ParticipatingPatientsQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_STU_Study_ParticipatingPatient Study_ParticipatingPatients;

            var Study_ParticipatingPatientsQueryRes = ORM_HEC_STU_Study_ParticipatingPatient.Query.Search(Connection, Transaction, Study_ParticipatingPatientsQuery);
            if (Study_ParticipatingPatientsQueryRes.Count == 1)
            {
                Study_ParticipatingPatients = Study_ParticipatingPatientsQueryRes[0];
            }
            else
            {
                Study_ParticipatingPatients = new ORM_HEC_STU_Study_ParticipatingPatient();
                Study_ParticipatingPatients.Patient_RefID = patient.HEC_PatientID;
                Study_ParticipatingPatients.Tenant_RefID  = securityTicket.TenantID;
            }
            Study_ParticipatingPatients.HasFulfilledParticipationPolicyRequirements = Parameter.HasFulfilledParticipationPolicyRequirements;
            Study_ParticipatingPatients.Save(Connection, Transaction);


            ORM_USR_Account       account;
            ORM_USR_Account.Query ORM_USR_AccountQuery = new ORM_USR_Account.Query();
            ORM_USR_AccountQuery.IsDeleted    = false;
            ORM_USR_AccountQuery.Tenant_RefID = securityTicket.TenantID;
            ORM_USR_AccountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            var accountRes = ORM_USR_Account.Query.Search(Connection, Transaction, ORM_USR_AccountQuery);
            if (accountRes.Count == 1)
            {
                account = accountRes[0];
            }
            else
            {
                account = new ORM_USR_Account();
                account.Tenant_RefID = securityTicket.TenantID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.AccountType = 3;
                account.Save(Connection, Transaction);
            }

            ORM_USR_Device_AccountCode.Query ORM_USR_Device_AccountCodeQuery = new ORM_USR_Device_AccountCode.Query();
            ORM_USR_Device_AccountCodeQuery.IsDeleted     = false;
            ORM_USR_Device_AccountCodeQuery.Tenant_RefID  = securityTicket.TenantID;
            ORM_USR_Device_AccountCodeQuery.Account_RefID = account.USR_AccountID;
            var accountCodeRes = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, ORM_USR_Device_AccountCodeQuery);
            if (accountCodeRes.Count == 0)
            {
                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode_StatusHistory AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                AccountCode_StatusHistory.Tenant_RefID         = securityTicket.TenantID;
                AccountCode_StatusHistory.IsAccountCode_Active = true;
                AccountCode_StatusHistory.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode devoceAccpimtCpde = new ORM_USR_Device_AccountCode();
                devoceAccpimtCpde.Account_RefID                   = account.USR_AccountID;
                devoceAccpimtCpde.Tenant_RefID                    = securityTicket.TenantID;
                devoceAccpimtCpde.AccountCode_Value               = checkCodeValue.CodeValue;
                devoceAccpimtCpde.IsAccountCode_Expirable         = false;
                devoceAccpimtCpde.AccountCode_CurrentStatus_RefID = AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID;
                devoceAccpimtCpde.Save(Connection, Transaction);

                AccountCode_StatusHistory.Device_AccountCode_RefID = devoceAccpimtCpde.USR_Device_AccountCodeID;
                AccountCode_StatusHistory.Save(Connection, Transaction);
            }

            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }
Пример #13
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SPC_1047 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty))
            {
                return(returnValue);
            }

            ORM_CMN_BPT_CTM_Customer customer;
            if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty)
            {
                var customerQ = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQ.Tenant_RefID           = securityTicket.TenantID;
                customerQ.IsDeleted              = false;
                customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID;
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First();
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }
            else
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.Tenant_RefID           = securityTicket.TenantID;
                customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }

            ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType;

            var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query();
            customer2PaymentTypeQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentTypeQ.IsDeleted      = false;
            customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault();
            if (customer2PaymentType == null)
            {
                customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType();
                customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid();
                customer2PaymentType.Tenant_RefID       = securityTicket.TenantID;
                customer2PaymentType.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID;
            customer2PaymentType.Save(Connection, Transaction);

            #region payment condition

            ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition;

            var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query();
            customer2PaymentConditionQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentConditionQ.IsDeleted      = false;
            customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault();
            if (customer2PaymentCondition == null)
            {
                customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition();
                customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid();
                customer2PaymentCondition.Tenant_RefID            = securityTicket.TenantID;
                customer2PaymentCondition.Customer_RefID          = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID;
            customer2PaymentCondition.Save(Connection, Transaction);

            #endregion

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            if (customer.Ext_BusinessParticipant_RefID != Guid.Empty)
            {
                var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();
                bParticipantQ.Tenant_RefID = securityTicket.TenantID;
                bParticipantQ.IsDeleted    = false;
                bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
                bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First();
            }
            else
            {
                bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Tenant_RefID = securityTicket.TenantID;
                bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bParticipant.IsNaturalPerson           = true;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }

            bParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastName;

            ORM_CMN_PER_PersonInfo personInfo;
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var personInfoQ = new ORM_CMN_PER_PersonInfo.Query();
                personInfoQ.Tenant_RefID         = securityTicket.TenantID;
                personInfoQ.IsDeleted            = false;
                personInfoQ.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQ).First();
            }
            else
            {
                personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
            }

            #region connection with legal guardian
            //checking is there allready legal guardian associated with this business participant

            ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query LGCheckQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
            LGCheckQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            LGCheckQuery.IsDeleted = false;

            Boolean oldLegalGuardianConnectionExist = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Exists(Connection, Transaction, LGCheckQuery);

            if (Parameter.IsRepresentedByLegalGuardian)
            {
                if (oldLegalGuardianConnectionExist)
                {
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First();
                    ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID;
                    oldLegalGuardianQuery.IsDeleted = false;

                    ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First();
                    oldLegalGuardian.DisplayName = Parameter.LegalGuardianName;
                    oldLegalGuardian.Save(Connection, Transaction);
                }
                else
                {
                    // creating a new legal guardian
                    ORM_CMN_BPT_BusinessParticipant newLegalGuardian = new ORM_CMN_BPT_BusinessParticipant();
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant legalGuardianLink = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();

                    newLegalGuardian.DisplayName = Parameter.LegalGuardianName;
                    legalGuardianLink.AssociatedBusinessParticipant_RefID = newLegalGuardian.CMN_BPT_BusinessParticipantID;
                    legalGuardianLink.BusinessParticipant_RefID           = bParticipant.CMN_BPT_BusinessParticipantID;
                    newLegalGuardian.Save(Connection, Transaction);
                    legalGuardianLink.Save(Connection, Transaction);
                }
            }
            else
            {
                //delete old legal guardian if there is an old legal guardian
                if (oldLegalGuardianConnectionExist)
                {
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First();
                    ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID;
                    oldLegalGuardianQuery.IsDeleted = false;

                    //deleting old legal guardian from business participant table
                    if (ORM_CMN_BPT_BusinessParticipant.Query.Exists(Connection, Transaction, oldLegalGuardianQuery))
                    {
                        ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First();
                        oldLegalGuardian.IsDeleted = true;
                        oldLegalGuardian.Save(Connection, Transaction);
                    }
                    // deleting connenction beetwen customer and legal guardian
                    oldLegalGuardianConnection.IsDeleted = true;
                    oldLegalGuardianConnection.Save(Connection, Transaction);
                }
            }

            #endregion

            personInfo.FirstName = Parameter.FirstName;
            personInfo.LastName  = Parameter.LastName;
            personInfo.BirthDate = Parameter.BirthDate;
            personInfo.IsRepresentedByLegalGuardian = Parameter.IsRepresentedByLegalGuardian;

            personInfo.IsDeleted   = Parameter.IsDelete;
            bParticipant.IsDeleted = Parameter.IsDelete;
            customer.IsDeleted     = Parameter.IsDelete;

            personInfo.Save(Connection, Transaction);
            bParticipant.Save(Connection, Transaction);
            customer.Save(Connection, Transaction);

            returnValue.Result = customer.CMN_BPT_CTM_CustomerID;

            return(returnValue);

            #endregion UserCode
        }
Пример #14
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
        }
Пример #15
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_DO_SD_1517 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            Guid   BusinessParticipantID         = Guid.NewGuid();
            Guid   personInfoID                  = Guid.NewGuid();
            Guid   PracticeCustomerID            = Guid.NewGuid();
            Guid   PracticeBusinessParticipantID = Guid.NewGuid();
            Guid   PracticeCompanyInfoID         = Guid.NewGuid();
            String PracticeName                  = "";
            Guid   BankAccountID                 = Guid.Empty;
            Guid   doctor_id    = Parameter.DoctorID;
            var    isOpPractice = false;

            //if (!String.IsNullOrEmpty(Parameter.Login_Email))
            //uncomment this if you've created account
            if (false)
            {
                string[] stringUser  = Parameter.Login_Email.Split('@');
                string   usernameStr = stringUser[0];

                try
                {
                    var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        AccountSignInEmailAddress = Parameter.Login_Email,
                    }).Single();

                    var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                    accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                    accountGroupQuery.IsDeleted                = false;
                    accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                    var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                    if (accountGroup == null)
                    {
                        accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                        accountGroup.Tenant_RefID             = securityTicket.TenantID;
                        accountGroup.Label                    = "mm.docconect.doc.app.group";
                        accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                        accountGroup.Creation_Timestamp       = DateTime.Now;
                        accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                        accountGroup.Save(Connection, Transaction);
                    }

                    var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).ToList();

                    List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>();
                    foreach (var item in PracticeAccount2UniversalProperty)
                    {
                        var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID
                        }).Single();
                        PracticeUniversalPropertyList.Add(PracticeUniversalProperty);
                    }
                    ;

                    P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522();
                    practiceAccountIDParameter.PracticeID = Parameter.PracticeID;

                    var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query();
                    practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID;
                    practiceAccountToFunctionLevelRightQ.Tenant_RefID  = securityTicket.TenantID;
                    practiceAccountToFunctionLevelRightQ.IsDeleted     = false;

                    var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault();

                    if (practiceAccountToFunctionLevelRight != null)
                    {
                        var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID;
                        practiceAccountFunctionLevelRightQ.IsDeleted    = false;
                        practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID;

                        var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault();

                        if (practiceAccountFunctionLevelRight != null)
                        {
                            isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice");
                        }
                    }

                    var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                    functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                    functionLevelRightQ.IsDeleted                = false;
                    functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                    var existingFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault();

                    var tempFunctionLevelRightID = Guid.Empty;

                    if (existingFunctionLevelRight == null)
                    {
                        ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                        functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                        functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                        functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                        functionLevelRight.Creation_Timestamp = DateTime.Now;

                        functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";
                        functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                        functionLevelRight.Save(Connection, Transaction);

                        tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                    }
                    else
                    {
                        tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID;
                    }

                    var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                    accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                    accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                    accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                    accountToFunctionLevelRight.Account_RefID            = doctorAccountInfo.USR_AccountID;
                    accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID;

                    accountToFunctionLevelRight.Save(Connection, Transaction);

                    var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

                    businessParticipantQ.IsDeleted    = false;
                    businessParticipantQ.Tenant_RefID = securityTicket.TenantID;
                    businessParticipantQ.CMN_BPT_BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;
                    BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;

                    var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();
                    DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                    DoctorBusinessParticipant.DisplayName            = Parameter.First_Name + " " + Parameter.Last_Name;
                    DoctorBusinessParticipant.IsNaturalPerson        = true;
                    DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                    DoctorBusinessParticipant.Save(Connection, Transaction);
                    personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;


                    var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                    companyInfoPractice.IsDeleted            = false;
                    companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                    companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                    companyInfoPractice.FirstName            = Parameter.First_Name;
                    companyInfoPractice.LastName             = Parameter.Last_Name;
                    companyInfoPractice.Salutation_General   = Parameter.Salutation;
                    companyInfoPractice.Title = Parameter.Title;
                    companyInfoPractice.Save(Connection, Transaction);

                    var communicationContact = new ORM_CMN_PER_CommunicationContact();
                    communicationContact.IsDeleted              = false;
                    communicationContact.Contact_Type           = Guid.NewGuid();
                    communicationContact.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact.Modification_Timestamp = DateTime.Now;
                    communicationContact.PersonInfo_RefID       = personInfoID;
                    communicationContact.Content = Parameter.Email;
                    communicationContact.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID = communicationContact.Contact_Type;


                    var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType.IsDeleted    = false;
                    communicationContactType.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                    communicationContactType.Type = "Email";
                    communicationContactType.Save(Connection, Transaction);

                    var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                    communicationContact2.IsDeleted              = false;
                    communicationContact2.Contact_Type           = Guid.NewGuid();
                    communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact2.Modification_Timestamp = DateTime.Now;
                    communicationContact2.PersonInfo_RefID       = personInfoID;
                    communicationContact2.Content = Parameter.Phone;
                    communicationContact2.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                    var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType2.IsDeleted    = false;
                    communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                    communicationContactType2.Type = "Phone";
                    communicationContactType2.Save(Connection, Transaction);

                    var doctor = new ORM_HEC_Doctor();
                    doctor.HEC_DoctorID = Guid.NewGuid();
                    doctor.IsDeleted    = false;
                    doctor.Tenant_RefID = securityTicket.TenantID;
                    doctor.BusinessParticipant_RefID = BusinessParticipantID;
                    doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                    doctor.Save(Connection, Transaction);

                    doctor_id = doctor.HEC_DoctorID;

                    var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).Single();


                    var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                    organizationalunit_Staff.IsDeleted    = false;
                    organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                    organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                    organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                    organizationalunit_Staff.Save(Connection, Transaction);

                    var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        IsDeleted              = false,
                        Tenant_RefID           = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                    }).Single();
                    var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                    }).Single();

                    PracticeName = PracticeBusinessParticipant.DisplayName;
                    PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                    PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                    if (Parameter.From_Practice_Bank)
                    {
                        var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                        }).Single();


                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        //end of save bank data if inherited from practice
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                            bankAccountDoctor.IsDeleted             = false;
                            bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                            bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            bankAccountDoctor.OwnerText             = Parameter.Account_Holder;
                            bankAccountDoctor.IBAN               = Parameter.IBAN;
                            bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                            bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                            bankAccountDoctor.Save(Connection, Transaction);

                            if (!String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var bank = new ORM_ACC_BNK_Bank();
                                bank.IsDeleted          = false;
                                bank.Tenant_RefID       = securityTicket.TenantID;
                                bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                bank.BICCode            = Parameter.BIC;
                                bank.BankName           = Parameter.Bank;
                                bank.Creation_Timestamp = DateTime.Now;
                                bank.Save(Connection, Transaction);
                            }

                            BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            // end save bank data
                        }
                    }
                }
                catch
                {
                    throw new Exception();
                }
            }
            else
            {
                var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                DoctorBusinessParticipant.IsDeleted    = false;
                DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                DoctorBusinessParticipant.DisplayName            = Parameter.First_Name + " " + Parameter.Last_Name;
                DoctorBusinessParticipant.IsNaturalPerson        = true;
                DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                DoctorBusinessParticipant.Save(Connection, Transaction);
                personInfoID          = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID;

                var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                companyInfoPractice.IsDeleted            = false;
                companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                companyInfoPractice.FirstName            = Parameter.First_Name;
                companyInfoPractice.LastName             = Parameter.Last_Name;
                companyInfoPractice.Salutation_General   = Parameter.Salutation;
                companyInfoPractice.Title = Parameter.Title;
                companyInfoPractice.Save(Connection, Transaction);

                var communicationContact = new ORM_CMN_PER_CommunicationContact();
                communicationContact.IsDeleted              = false;
                communicationContact.Contact_Type           = Guid.NewGuid();
                communicationContact.Tenant_RefID           = securityTicket.TenantID;
                communicationContact.Modification_Timestamp = DateTime.Now;
                communicationContact.PersonInfo_RefID       = personInfoID;
                communicationContact.Content = Parameter.Email;
                communicationContact.Save(Connection, Transaction);
                Guid CommunicationContactTypeID = communicationContact.Contact_Type;

                var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                communicationContactType.IsDeleted    = false;
                communicationContactType.Tenant_RefID = securityTicket.TenantID;
                communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                communicationContactType.Type = "Email";
                communicationContactType.Save(Connection, Transaction);

                var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                communicationContact2.IsDeleted              = false;
                communicationContact2.Contact_Type           = Guid.NewGuid();
                communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                communicationContact2.Modification_Timestamp = DateTime.Now;
                communicationContact2.PersonInfo_RefID       = personInfoID;
                communicationContact2.Content = Parameter.Phone;
                communicationContact2.Save(Connection, Transaction);
                Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                communicationContactType2.IsDeleted    = false;
                communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                communicationContactType2.Type = "Phone";
                communicationContactType2.Save(Connection, Transaction);

                var doctor = new ORM_HEC_Doctor();
                doctor.HEC_DoctorID = Guid.NewGuid();
                doctor.IsDeleted    = false;
                doctor.Tenant_RefID = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = BusinessParticipantID;
                doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                doctor.Save(Connection, Transaction);

                doctor_id = doctor.HEC_DoctorID;

                var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                }).Single();


                var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                organizationalunit_Staff.IsDeleted    = false;
                organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                organizationalunit_Staff.Save(Connection, Transaction);


                var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                {
                    IsDeleted              = false,
                    Tenant_RefID           = securityTicket.TenantID,
                    CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                }).Single();
                var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                }).Single();
                PracticeName = PracticeBusinessParticipant.DisplayName;
                PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                if (Parameter.From_Practice_Bank == true)
                {
                    var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                    }).Single();


                    var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                    business2bankAccount.IsDeleted    = false;
                    business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                    business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                    business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                    business2bankAccount.Creation_Timestamp = DateTime.Now;
                    business2bankAccount.Save(Connection, Transaction);

                    BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                    //end of save bank data if inherited from practice
                }
                else
                {
                    if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                    {
                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                        bankAccountDoctor.IsDeleted             = false;
                        bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                        bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                        bankAccountDoctor.OwnerText             = Parameter.Account_Holder;
                        bankAccountDoctor.IBAN               = Parameter.IBAN;
                        bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                        bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                        bankAccountDoctor.Save(Connection, Transaction);

                        if (!String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var bank = new ORM_ACC_BNK_Bank();
                            bank.IsDeleted          = false;
                            bank.Tenant_RefID       = securityTicket.TenantID;
                            bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                            bank.BICCode            = Parameter.BIC;
                            bank.BankName           = Parameter.Bank;
                            bank.Creation_Timestamp = DateTime.Now;
                            bank.Save(Connection, Transaction);
                        }

                        BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                        // end save bank data
                    }
                }
            }
            var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query()
            {
                IsDeleted           = false,
                Tenant_RefID        = securityTicket.TenantID,
                CompanyInfo_RefID   = PracticeCompanyInfoID,
                Address_Description = "Standard address for billing, shipping",
            }).SingleOrDefault();

            Practice_Doctors_Model DPModel = new Practice_Doctors_Model();

            if (PracticeCompanyInfoAddress != null)
            {
                var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID,
                }).SingleOrDefault();
                DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number;
                DPModel.zip     = PracticeUCD.ZIP;
                DPModel.city    = PracticeUCD.Town;
            }

            DPModel.account_status = "aktiv";
            DPModel.id             = doctor_id.ToString();

            var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim();

            DPModel.name           = title + " " + Parameter.Last_Name + " " + Parameter.First_Name;
            DPModel.name_untouched = Parameter.Last_Name + " " + Parameter.First_Name;
            DPModel.bsnr_lanr      = Parameter.LANR.ToString();

            DPModel.salutation = title;

            DPModel.type = "Doctor";

            DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;

            DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;


            DPModel.phone = Parameter.Phone;

            DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email;

            DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN;

            DPModel.bic = string.IsNullOrEmpty(Parameter.BIC) ? "" : Parameter.BIC;

            DPModel.bank_id             = BankAccountID.ToString();
            DPModel.bank_info_inherited = Parameter.From_Practice_Bank;
            DPModel.aditional_info      = "";
            DPModel.contract            = 0;


            DPModel.tenantid = securityTicket.TenantID.ToString();
            DPModel.practice_name_for_doctor = PracticeName;
            DPModel.practice_for_doctor_id   = Parameter.PracticeID.ToString();

            DPModel.role = isOpPractice ? "op" : "ac";

            List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
            DPModelL.Add(DPModel);

            Add_New_Practice.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());
            return(returnValue);

            #endregion UserCode
        }
Пример #16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5AC_SA_1046 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            var bp = new ORM_CMN_BPT_BusinessParticipant()
            {
                CMN_BPT_BusinessParticipantID = Guid.NewGuid(),
                Tenant_RefID    = securityTicket.TenantID,
                IsNaturalPerson = true,
                IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(),
                DisplayName = Parameter.Title + " " + Parameter.FirstName + " " + Parameter.LastName
            };
            bp.Save(Connection, Transaction);

            var personInfo = new ORM_CMN_PER_PersonInfo()
            {
                CMN_PER_PersonInfoID = bp.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                Tenant_RefID         = securityTicket.TenantID,
                Title         = Parameter.Title,
                FirstName     = Parameter.FirstName,
                LastName      = Parameter.LastName,
                PrimaryEmail  = Parameter.Email,
                Address_RefID = Guid.NewGuid()
            };
            personInfo.Save(Connection, Transaction);

            var address = new ORM_CMN_Address()
            {
                CMN_AddressID   = personInfo.Address_RefID,
                Tenant_RefID    = securityTicket.TenantID,
                Street_Name     = Parameter.StreetName,
                Street_Number   = Parameter.StreetNumber,
                City_Name       = Parameter.CityName,
                City_PostalCode = Parameter.CityPostalCode,
                Country_Name    = Parameter.CountryName
            };
            address.Save(Connection, Transaction);

            var bptUser = new ORM_CMN_BPT_USR_User()
            {
                CMN_BPT_USR_UserID        = Guid.NewGuid(),
                Tenant_RefID              = securityTicket.TenantID,
                BusinessParticipant_RefID = bp.CMN_BPT_BusinessParticipantID,
                Username = Parameter.Email
            };

            bptUser.Save(Connection, Transaction);

            var    cryptoUtils = new CryptoUtils();
            string passSalt    = cryptoUtils.GenerateRandomSalt(32);

            var bptUserPass = new ORM_CMN_BPT_USR_User_Password()
            {
                CMN_BPT_USR_User_PasswordID = Guid.NewGuid(),
                CMN_BPT_USR_User_RefID      = bptUser.CMN_BPT_USR_UserID,
                Tenant_RefID       = securityTicket.TenantID,
                Password_Salt      = passSalt,
                Password_Hash      = cryptoUtils.GenerateSaltedHash(Parameter.Password, passSalt),
                Password_Algorithm = cryptoUtils.GetHashAlgorithName(),
                IsActive           = Parameter.IsActivated
            };

            bptUserPass.Save(Connection, Transaction);

            var community = ORM_HEC_CMT_Community.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                IsCommunityOperatedByThisTenant = true
            }).Single();


            var membershipType = ORM_HEC_CMT_Community_OfferedMembershipType.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community_OfferedMembershipType.Query()
            {
                Tenant_RefID           = securityTicket.TenantID,
                IsDeleted              = false,
                IsAvailableFor_Tenants = Parameter.IsTenant,
                IsAvailableFor_Doctors = !Parameter.IsTenant
            }).Single();

            var member = new ORM_HEC_CMT_Membership()
            {
                CommunityMembershipITL    = Guid.NewGuid().ToString(),
                HEC_CMT_MembershipID      = Guid.NewGuid(),
                Tenant_RefID              = securityTicket.TenantID,
                Community_RefID           = community.HEC_CMT_CommunityID,
                MembershipType_RefID      = membershipType.HEC_CMT_Community_OfferedMembershipTypeID,
                BusinessParticipant_RefID = bp.CMN_BPT_BusinessParticipantID
            };
            member.Save(Connection, Transaction);

            returnValue.Result = bptUser.CMN_BPT_USR_UserID;

            return(returnValue);

            #endregion UserCode
        }
Пример #17
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
        }
Пример #18
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_DO_SAHD_1815 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            #region EMAIL
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");

            string        urlMM        = System.Configuration.ConfigurationManager.AppSettings["mmdocconnect.dashboard.url"];
            List <String> mailToL      = new List <String>();
            var           accountMails = cls_Get_All_Account_LoginEmails_Who_Receive_Notifications.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            foreach (var mail in accountMails)
            {
                mailToL.Add(mail.LoginEmail);
            }

            string appName  = WebConfigurationManager.AppSettings["mmAppUrl"];
            var    prefix   = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://";
            var    imageUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png";

            var     email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/NewTemporaryDoctorEmailTemplate.html"));
            var     subjectsJson   = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json"));
            dynamic subjects       = Newtonsoft.Json.JsonConvert.DeserializeObject(subjectsJson);
            var     subjectMail    = subjects["NewTemporaryDoctorSubject"].ToString();

            email_template = EmailTemplater.SetTemplateData(email_template, new
            {
                name                    = Parameter.name,
                street                  = String.IsNullOrEmpty(Parameter.street) ? "-" : Parameter.street,
                house_number            = String.IsNullOrEmpty(Parameter.house_number) ? "-" : Parameter.house_number,
                zip                     = String.IsNullOrEmpty(Parameter.zip) ? "-" : Parameter.zip,
                city                    = String.IsNullOrEmpty(Parameter.city) ? "-" : Parameter.city,
                phone                   = String.IsNullOrEmpty(Parameter.phone) ? "-" : Parameter.phone,
                fax                     = String.IsNullOrEmpty(Parameter.fax) ? "-" : Parameter.fax,
                email                   = String.IsNullOrEmpty(Parameter.email) ? "-" : Parameter.email,
                comment                 = String.IsNullOrEmpty(Parameter.comment) ? "-" : Parameter.comment,
                doc_app_url             = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName,
                medios_connect_logo_url = imageUrl
            }, "{{", "}}");

            try
            {
                // string mailFrom = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result.Email;
                string mailFrom      = WebConfigurationManager.AppSettings["mailFrom"];
                var    mailsDistinct = mailToL.Distinct().ToList();
                foreach (var mailTo in mailsDistinct)
                {
                    EmailNotificationSenderUtil.SendEmail(mailFrom, mailTo, subjectMail, email_template);
                }
            }
            catch (Exception ex)
            {
                LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Temporary doctor creation: Email sending failed."), "EmailExceptions");
            }
            #endregion

            #region PERSON INFO
            ORM_CMN_PER_PersonInfo temporary_doctor_person_info = new ORM_CMN_PER_PersonInfo();
            temporary_doctor_person_info.LastName = Parameter.name;
            temporary_doctor_person_info.Modification_Timestamp = DateTime.Now;
            temporary_doctor_person_info.Tenant_RefID           = securityTicket.TenantID;

            temporary_doctor_person_info.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_email = new ORM_CMN_PER_CommunicationContact_Type();
            temporary_doctor_communication_contact_type_email.Tenant_RefID = securityTicket.TenantID;
            temporary_doctor_communication_contact_type_email.Type         = "Email";

            temporary_doctor_communication_contact_type_email.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_email = new ORM_CMN_PER_CommunicationContact();
            temporary_doctor_communication_contact_email.Tenant_RefID           = securityTicket.TenantID;
            temporary_doctor_communication_contact_email.Modification_Timestamp = DateTime.Now;
            temporary_doctor_communication_contact_email.PersonInfo_RefID       = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_communication_contact_email.Content      = Parameter.email;
            temporary_doctor_communication_contact_email.Contact_Type = temporary_doctor_communication_contact_type_email.CMN_PER_CommunicationContact_TypeID;

            temporary_doctor_communication_contact_email.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_phone = new ORM_CMN_PER_CommunicationContact_Type();
            temporary_doctor_communication_contact_type_phone.Tenant_RefID = securityTicket.TenantID;
            temporary_doctor_communication_contact_type_phone.Type         = "Phone";

            temporary_doctor_communication_contact_type_phone.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_phone = new ORM_CMN_PER_CommunicationContact();
            temporary_doctor_communication_contact_phone.Tenant_RefID           = securityTicket.TenantID;
            temporary_doctor_communication_contact_phone.Modification_Timestamp = DateTime.Now;
            temporary_doctor_communication_contact_phone.PersonInfo_RefID       = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_communication_contact_phone.Content      = Parameter.phone;
            temporary_doctor_communication_contact_phone.Contact_Type = temporary_doctor_communication_contact_type_phone.CMN_PER_CommunicationContact_TypeID;

            temporary_doctor_communication_contact_phone.Save(Connection, Transaction);
            #endregion

            #region BPT
            ORM_CMN_BPT_BusinessParticipant temporary_doctor_bpt = new ORM_CMN_BPT_BusinessParticipant();
            temporary_doctor_bpt.IfNaturalPerson_CMN_PER_PersonInfo_RefID = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_bpt.IsNaturalPerson        = true;
            temporary_doctor_bpt.Modification_Timestamp = DateTime.Now;
            temporary_doctor_bpt.Tenant_RefID           = securityTicket.TenantID;

            temporary_doctor_bpt.Save(Connection, Transaction);
            #endregion

            #region DOCTOR
            ORM_HEC_Doctor temporary_doctor = new ORM_HEC_Doctor();
            // account ref. id = guid empty means that this is a temporary doctor with no account
            temporary_doctor.Account_RefID                     = Guid.Empty;
            temporary_doctor.BusinessParticipant_RefID         = temporary_doctor_bpt.CMN_BPT_BusinessParticipantID;
            temporary_doctor.DoctorIDNumber                    = "";
            temporary_doctor.IsDoctorForFollowupTreatmentsOnly = true;
            temporary_doctor.Tenant_RefID = securityTicket.TenantID;

            temporary_doctor.Save(Connection, Transaction);

            ORM_HEC_Doctor_UniversalProperty temporary_doctor_universal_property = new ORM_HEC_Doctor_UniversalProperty();
            temporary_doctor_universal_property.GlobalPropertyMatchingID = "mm.docconnect.temporary.aftercare.doctor.comment";
            temporary_doctor_universal_property.IsValue_String           = true;
            temporary_doctor_universal_property.Modification_Timestamp   = DateTime.Now;
            temporary_doctor_universal_property.PropertyName             = "Comment";
            temporary_doctor_universal_property.Tenant_RefID             = securityTicket.TenantID;

            temporary_doctor_universal_property.Save(Connection, Transaction);

            ORM_HEC_Doctor_UniversalPropertyValue temporary_doctor_universal_property_value = new ORM_HEC_Doctor_UniversalPropertyValue();
            temporary_doctor_universal_property_value.HEC_Doctor_RefID        = temporary_doctor.HEC_DoctorID;
            temporary_doctor_universal_property_value.Modification_Timestamp  = DateTime.Now;
            temporary_doctor_universal_property_value.Value_String            = Parameter.comment;
            temporary_doctor_universal_property_value.UniversalProperty_RefID = temporary_doctor_universal_property.HEC_Doctor_UniversalPropertyID;
            temporary_doctor_universal_property_value.Tenant_RefID            = securityTicket.TenantID;

            temporary_doctor_universal_property_value.Save(Connection, Transaction);
            #endregion

            #region IMPORT TO ELASTIC

            Practice_Doctors_Model temporary_doctor_elastic_model = new Practice_Doctors_Model();
            temporary_doctor_elastic_model.autocomplete_name = Parameter.name;
            temporary_doctor_elastic_model.name                   = Parameter.name;
            temporary_doctor_elastic_model.name_untouched         = Parameter.name;
            temporary_doctor_elastic_model.address                = Parameter.street + " " + Parameter.house_number;
            temporary_doctor_elastic_model.zip                    = Parameter.zip;
            temporary_doctor_elastic_model.city                   = Parameter.city;
            temporary_doctor_elastic_model.email                  = Parameter.email;
            temporary_doctor_elastic_model.phone                  = Parameter.phone;
            temporary_doctor_elastic_model.account_status         = "temp";
            temporary_doctor_elastic_model.id                     = temporary_doctor.HEC_DoctorID.ToString();
            temporary_doctor_elastic_model.practice_for_doctor_id = Parameter.practice_id.ToString();
            temporary_doctor_elastic_model.tenantid               = securityTicket.TenantID.ToString();
            temporary_doctor_elastic_model.type                   = "Doctor";

            Add_New_Practice.Import_Practice_Data_to_ElasticDB(new List <Practice_Doctors_Model>()
            {
                temporary_doctor_elastic_model
            }, securityTicket.TenantID.ToString());
            #endregion

            returnValue.Result = temporary_doctor.HEC_DoctorID;
            return(returnValue);

            #endregion UserCode
        }
Пример #19
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_SDBI_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            var doctor = new ORM_HEC_Doctor();

            if (Parameter.DoctorID != Guid.Empty)
            {
                var result = doctor.Load(Connection, Transaction, Parameter.DoctorID);
                if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                #region Edit

                bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true;

                doctor.Account_RefID = Parameter.Account_RefID;
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Save(Connection, Transaction);

                //bussinessParticipant
                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID;

                var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First();

                if (!bopAccIsChenged)
                {
                    //personInfo
                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                    }
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (communicationContactsList != null)
                    {
                        foreach (var c in communicationContactsList)
                        {
                            c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                            c.Save(Connection, Transaction);
                        }
                    }

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }

                    bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    bussinessParticipant.Save(Connection, Transaction);
                }
                if (Parameter.isLucentisSave)
                {
                    foreach (var practice in Parameter.Practices)
                    {
                        //if (practice.PracticeID != Guid.Empty) {

                        var medPract = new ORM_HEC_MedicalPractis.Query();
                        medPract.HEC_MedicalPractiseID = practice.PracticeID;

                        var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                        var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                        queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;

                        var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                        var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                        practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                        var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                        var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                        query3.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                        query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                        query3.IsDeleted = false;

                        var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault();
                        if (associatedbusinessparticipantsOriginal != null)
                        {
                            associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted;
                            associatedbusinessparticipantsOriginal.Save(Connection, Transaction);
                        }
                        else
                        {
                            var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                            associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                            associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                            associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                            associatedbusinessparticipants.Save(Connection, Transaction);


                            // }
                        }
                    }
                }
                if (Parameter.isOphthalSave && Parameter.Practices.Length == 1)
                {
                    var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                    query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    query3.IsDeleted = false;
                    var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3);
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice;

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID;
                    var medicalPractice  = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();
                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo   = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();
                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    if (associatedbusinessparticipantsRes.Count > 0)
                    {
                        associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList();
                        firstPractice = associatedbusinessparticipantsRes.First();
                        foreach (var item in associatedbusinessparticipantsRes)
                        {
                            if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID)
                            {
                                item.IsDeleted = true;
                                item.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                        firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                        firstPractice.Tenant_RefID = securityTicket.TenantID;
                        firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    }
                    firstPractice.AssociatedParticipant_FunctionName  = Parameter.Practices[0].AssociatedParticipant_FunctionName;
                    firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    firstPractice.Save(Connection, Transaction);
                }
                #endregion
            }
            else
            {
                #region Save

                //personInfo
                Guid personInfoID;
                if (Parameter.Account_RefID == Guid.Empty)
                {
                    var personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.FirstName            = Parameter.FirstName;
                    personInfo.LastName             = Parameter.LastName;
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Title = Parameter.Title;
                    personInfo.Creation_Timestamp = DateTime.Now;
                    personInfo.Tenant_RefID       = securityTicket.TenantID;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                    }
                    personInfo.Save(Connection, Transaction);
                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                //bussinessParticipants
                var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant();
                bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bussinessParticipantTable.IsNaturalPerson    = true;
                bussinessParticipantTable.IsTenant           = false;
                bussinessParticipantTable.IsCompany          = false;
                bussinessParticipantTable.IsDeleted          = false;
                bussinessParticipantTable.Creation_Timestamp = DateTime.Now;
                bussinessParticipantTable.Tenant_RefID       = securityTicket.TenantID;
                bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                bussinessParticipantTable.Save(Connection, Transaction);

                doctor.HEC_DoctorID = Guid.NewGuid();
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Creation_Timestamp        = DateTime.Now;
                doctor.Tenant_RefID              = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                doctor.Account_RefID             = Parameter.Account_RefID;
                doctor.Save(Connection, Transaction);

                if (Parameter.Contacts != null)
                {
                    foreach (var contact in Parameter.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();
                        communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                        communicationContacts.PersonInfo_RefID   = personInfoID;
                        communicationContacts.Contact_Type       = contact.CMN_PER_CommunicationContact_TypeID;
                        communicationContacts.Content            = contact.Content;
                        communicationContacts.Creation_Timestamp = DateTime.Now;
                        communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                        communicationContacts.Save(Connection, Transaction);
                    }
                }

                foreach (var practice in Parameter.Practices)
                {
                    if (practice.isDeleted == true)
                    {
                        continue;
                    }

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = practice.PracticeID;
                    var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    //associatedbusinessparticipants
                    var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                    associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                    associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                    associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                    associatedbusinessparticipants.Save(Connection, Transaction);
                }
                #endregion
            }

            returnValue.Result = doctor.HEC_DoctorID;
            return(returnValue);

            #endregion UserCode
        }
Пример #20
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_SP__1122 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_MedicalPractis item = new ORM_HEC_MedicalPractis();

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

                #region Delete

                if (Parameter.isDeleted == true)
                {
                    var query_BP_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                    query_BP_ContactPerson_del.Tenant_RefID = securityTicket.TenantID;

                    var found_BP_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_ContactPerson_del).First();
                    found_BP_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BP_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;
                    found_PersonInfo_del.Save(Connection, Transaction);


                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;


                    var found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_CommunicationContact_del.Save(Connection, Transaction);


                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    var found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);

                    var query_BP_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    var found_BP_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_Company_del).First();
                    found_BP_Company_del.IsDeleted = true;
                    found_BP_Company_del.Save(Connection, Transaction);

                    var query_UniversalContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_UniversalContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    var found_UniversalCompanyDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_UniversalContactDetails_del).First();

                    found_UniversalCompanyDetails_del.IsDeleted = true;
                    found_UniversalCompanyDetails_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_MedicalPractiseID));
                }

                #endregion
                #region Edit

                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                query1.Tenant_RefID    = securityTicket.TenantID;
                query1.IsCompany       = false;
                query1.IsNaturalPerson = true;
                query1.IsTenant        = false;

                var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First();


                var query2 = new ORM_CMN_PER_PersonInfo.Query();
                query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();

                personInfo.FirstName    = Parameter.ContactPersonFirstName;
                personInfo.LastName     = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail = Parameter.ContactPersonEmail;
                personInfo.Save(Connection, Transaction);


                var query3 = new ORM_CMN_PER_CommunicationContact.Query();
                query3.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;


                var communicationContacts = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query3).First();
                communicationContacts.Contact_Type = Parameter.ContactTypePhone;
                communicationContacts.Content      = Parameter.ContactPersonPhoneNumber;

                communicationContacts.Save(Connection, Transaction);


                var query4 = new ORM_CMN_COM_CompanyInfo.Query();
                query4.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query4).First();
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                companyInfo.Save(Connection, Transaction);

                var query5 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query5.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                var extCompany = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query5).First();
                extCompany.DisplayName = Parameter.PracticeName;
                extCompany.Save(Connection, Transaction);

                var query6 = new ORM_CMN_UniversalContactDetail.Query();
                query6.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;

                var companyDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query6).First();

                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;

                companyDetails.Save(Connection, Transaction);
                #endregion
            }
            else
            {
                #region Save

                item.HEC_MedicalPractiseID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;


                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantsID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantsID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_RefID = businessParticipantsID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactPersonFirstName;
                personInfo.LastName             = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail         = Parameter.ContactPersonEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPersonPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid companyInfoID = Guid.NewGuid();
                companyInfo.CMN_COM_CompanyInfoID           = companyInfoID;
                companyInfo.Creation_Timestamp              = DateTime.Now;
                companyInfo.Tenant_RefID                    = securityTicket.TenantID;
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                item.Ext_CompanyInfo_RefID = companyInfoID;


                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PracticeName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfoID;

                extCompany.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail companyDetails = new ORM_CMN_UniversalContactDetail();
                Guid companyDetailsID = Guid.NewGuid();

                companyInfo.Contact_UCD_RefID = companyDetailsID;
                companyInfo.Save(Connection, Transaction);

                companyDetails.CMN_UniversalContactDetailID = companyDetailsID;
                companyDetails.Tenant_RefID       = securityTicket.TenantID;
                companyDetails.Creation_Timestamp = DateTime.Now;
                companyDetails.IsCompany          = true;
                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;
                companyDetails.IsDeleted         = false;
                companyDetails.Save(Connection, Transaction);

                item.Save(Connection, Transaction);


                #endregion
            }

            returnValue.Result = item.HEC_MedicalPractiseID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3CU_CCaMR_1308 Execute(DbConnection Connection, DbTransaction Transaction, P_L3CU_CCaMR_1308 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3CU_CCaMR_1308();
            returnValue.Status = FR_Status.Error_Internal;
            returnValue.Result = new L3CU_CCaMR_1308();

            #region Load or Create Customer Tenant Initial Table Structure
            var customerTenantStructure = cls_Create_Tenant_Initial_Table_Structure.Invoke(
                Connection,
                Transaction,
                new P_L3TE_CTITS_1108()
            {
                TenantITL = Parameter.Customer_TenantITL,
                BusinessParticipantITL               = Parameter.Customer_BusinessParticipantITL,
                TenantUniversalContactDetailITL      = Parameter.Customer_TenantUniversalContactDetailITL,
                CompanyInfoUniversalContactDetailITL = Parameter.Customer_CompanyInfoUniversalContactDetailITL,
                CompanyName  = Parameter.Customer_CompanyName,
                ContactEmail = Parameter.Customer_ContactEmail
            },
                securityTicket);
            #endregion
            if (customerTenantStructure.Status != FR_Status.Success)
            {
                return(returnValue);
            }

            #region Load or Create Customer
            var cust = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
            {
                Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (cust == default(ORM_CMN_BPT_CTM_Customer))
            {
                cust = new ORM_CMN_BPT_CTM_Customer();
                cust.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                cust.Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID;
                cust.Tenant_RefID       = securityTicket.TenantID;
                cust.Creation_Timestamp = DateTime.Now;
                cust.Save(Connection, Transaction);
            }
            #endregion

            #region Create booking account
            var fiscalYear = cls_Get_Current_FiscalYear.Invoke(Connection, Transaction, securityTicket).Result;

            var bookingAccountParam = new P_L3BA_CCAfBP_1655()
            {
                BusinessParticipantIDs = new Guid[1] {
                    customerTenantStructure.Result.BusinessParticipantID
                },
                FiscalYearID = fiscalYear.ACC_FiscalYearID
            };

            var result = cls_Create_Customer_Account_for_BusinessParticipants.Invoke(Connection, Transaction, bookingAccountParam, securityTicket).Result;
            #endregion

            #region create defaultPerson for customer

            var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = cust.Ext_BusinessParticipant_RefID;
            businessParticipantQuery.IsDeleted = false;
            var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            if (businessParticipant.IsNaturalPerson)
            {
                if (businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == null || businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty)
                {
                    var personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.Tenant_RefID         = securityTicket.TenantID;
                    personInfo.IsDeleted            = false;
                    personInfo.FirstName            = businessParticipant.DisplayName;
                    personInfo.LastName             = businessParticipant.DisplayName;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Save(Connection, Transaction);

                    businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                }
            }
            else if (businessParticipant.IsCompany)
            {
                Boolean needDefaultPerson = true;
                var     associatedBPQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associatedBPQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                associatedBPQuery.Tenant_RefID = securityTicket.TenantID;
                associatedBPQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations =
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBPQuery);
                if (associations.Count > 0)
                {
                    foreach (var assotiation in associations)
                    {
                        if (assotiation.BusinessParticipant_RefID != Guid.Empty)
                        {
                            ORM_CMN_BPT_BusinessParticipant.Query businessParticipantPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                            businessParticipantPersonQuery.CMN_BPT_BusinessParticipantID = assotiation.BusinessParticipant_RefID;
                            businessParticipantPersonQuery.IsDeleted       = false;
                            businessParticipantPersonQuery.IsNaturalPerson = true;
                            List <ORM_CMN_BPT_BusinessParticipant> businessParticipantsPerson =
                                ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantPersonQuery);
                            foreach (var person in businessParticipantsPerson)
                            {
                                if (person.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty)
                                {
                                    ORM_CMN_PER_PersonInfo personInfoNew = new ORM_CMN_PER_PersonInfo();
                                    personInfoNew.CMN_PER_PersonInfoID = Guid.NewGuid();
                                    personInfoNew.Tenant_RefID         = securityTicket.TenantID;
                                    personInfoNew.IsDeleted            = false;
                                    personInfoNew.FirstName            = person.DisplayName;
                                    personInfoNew.LastName             = person.DisplayName;
                                    personInfoNew.Creation_Timestamp   = DateTime.Now;
                                    personInfoNew.Save(Connection, Transaction);

                                    person.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoNew.CMN_PER_PersonInfoID;
                                }

                                needDefaultPerson = false;
                                break;
                            }
                        }
                    }
                }

                if (needDefaultPerson)
                {
                    #region create personalInfo
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.Tenant_RefID         = securityTicket.TenantID;
                    personInfo.IsDeleted            = false;
                    personInfo.FirstName            = businessParticipant.DisplayName;
                    personInfo.LastName             = businessParticipant.DisplayName;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Save(Connection, Transaction);
                    #endregion

                    #region create new businessParticipiant
                    ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                    bParticipant.Tenant_RefID    = securityTicket.TenantID;
                    bParticipant.IsNaturalPerson = true;
                    bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    bParticipant.DisplayName        = businessParticipant.DisplayName;
                    bParticipant.Creation_Timestamp = DateTime.Now;
                    bParticipant.Save(Connection, Transaction);
                    #endregion

                    #region create associated businessParticipant table
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                    associatedBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                    associatedBP.IsDeleted = false;
                    associatedBP.BusinessParticipant_RefID           = bParticipant.CMN_BPT_BusinessParticipantID;
                    associatedBP.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    associatedBP.Creation_Timestamp = DateTime.Now;
                    associatedBP.Tenant_RefID       = securityTicket.TenantID;
                    associatedBP.Save(Connection, Transaction);
                    #endregion
                }
            }
            #endregion


            returnValue.Result.Customer_TenantID = customerTenantStructure.Result.TenantID;
            returnValue.Result.Customer_BusinessParticipantID = customerTenantStructure.Result.BusinessParticipantID;
            returnValue.Result.Customer_CompanyInfo_UniversalContactDetailID = customerTenantStructure.Result.CompanyInfoUniversalContactDetailID;
            returnValue.Result.Customer_Tenant_UniversalContactDetailID      = customerTenantStructure.Result.TenantUniversalContactDetailID;
            returnValue.Result.Customer_CustomerID    = cust.CMN_BPT_CTM_CustomerID;
            returnValue.Result.Customer_CompanyInfoID = customerTenantStructure.Result.CompanyInfoID;
            returnValue.Result.IsCustomerOrderAutomaticallyApprovedOnReceipt = cust.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            returnValue.Status = FR_Status.Success;

            return(returnValue);


            #endregion UserCode
        }
Пример #22
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_CL5CO_SC_1724 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            Guid personInfoID = Guid.Empty;

            ORM_CMN_BPT_CTM_Customer.Query customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.CMN_BPT_CTM_CustomerID = Parameter.CustomerID;
            customerQuery.IsDeleted = false;
            ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).Single();

            ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
            businessParticipantQuery.IsDeleted = false;
            ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            if (businessParticipant.IsNaturalPerson)
            {
                personInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;
                List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery);

                foreach (var association in associations)
                {
                    ORM_CMN_BPT_BusinessParticipant.Query bpQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    bpQuery.CMN_BPT_BusinessParticipantID = association.BusinessParticipant_RefID;
                    bpQuery.IsDeleted       = false;
                    bpQuery.IsNaturalPerson = true;
                    ORM_CMN_BPT_BusinessParticipant bp = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpQuery).First();
                    if (bp != null)
                    {
                        personInfoID = bp.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        break;
                    }
                }
            }

            if (personInfoID != Guid.Empty)
            {
                if (Parameter.Correspondences.Any(x => x.IsDefaultCorrespondence) && !Parameter.Correspondences.Any(x => x.IsDeleted))
                {
                    var findDefaultCorrespondenceQuery = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction,
                                                                                                            new ORM_CMN_PER_PersonInfo_Correspondence.Query
                    {
                        CMN_PER_PersonInfo_RefID = personInfoID,
                        IsDefaultCorrespondence  = true,
                        IsDeleted    = false,
                        Tenant_RefID = customer.Tenant_RefID
                    });

                    if (findDefaultCorrespondenceQuery != null && findDefaultCorrespondenceQuery.Any())
                    {
                        foreach (var item in findDefaultCorrespondenceQuery)
                        {
                            item.IsDefaultCorrespondence = false;
                            item.Save(Connection, Transaction);
                        }
                    }
                }

                foreach (var item in Parameter.Correspondences)
                {
                    ORM_CMN_PER_PersonInfo_Correspondence.Query correspondenceQuery = new ORM_CMN_PER_PersonInfo_Correspondence.Query();
                    correspondenceQuery.IsDeleted = false;
                    correspondenceQuery.CMN_PER_PersonInfo_CorrespondenceID = item.CorrespondenceID;
                    List <ORM_CMN_PER_PersonInfo_Correspondence> correspondences = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction, correspondenceQuery);

                    if (item.IsDeleted && correspondences.Count > 0)
                    {
                        correspondences.First().IsDeleted = true;
                        correspondences.First().Save(Connection, Transaction);
                    }
                    else if (!item.IsDeleted)
                    {
                        if (correspondences.Count > 0)
                        {
                            correspondences.First().CorrespondenceText = item.CorrespondenceText;

                            correspondences.First().IsDefaultCorrespondence  = item.IsDefaultCorrespondence;
                            correspondences.First().CorrespondenceType_RefID = item.CorrespondenceTypeRefId;

                            correspondences.First().Save(Connection, Transaction);

                            // save name in correspodencetype
                            //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{
                            //    CMN_PER_PersonInfo_CorrespondenceTypeID = correspondences.First().CorrespondenceType_RefID,
                            //    Tenant_RefID = customer.Tenant_RefID
                            //}).SingleOrDefault()

                            //if (correspodenceTypeQuery != null)
                            //{
                            //    correspodenceTypeQuery.DisplayName = item.CorrespondenceName;
                            //    correspodenceTypeQuery.Save(Connection, Transaction);
                            //}
                        }
                        else
                        {
                            ORM_CMN_PER_PersonInfo.Query personQuery = new ORM_CMN_PER_PersonInfo.Query();
                            personQuery.CMN_PER_PersonInfoID = personInfoID;
                            personQuery.IsDeleted            = false;
                            ORM_CMN_PER_PersonInfo person = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personQuery).First();

                            ORM_CMN_PER_PersonInfo_Correspondence newCorrespondance = new ORM_CMN_PER_PersonInfo_Correspondence();
                            newCorrespondance.CorrespondenceText       = item.CorrespondenceText;
                            newCorrespondance.IsDefaultCorrespondence  = item.IsDefaultCorrespondence;
                            newCorrespondance.CorrespondenceType_RefID = item.CorrespondenceTypeRefId;
                            newCorrespondance.IsDeleted          = false;
                            newCorrespondance.Creation_Timestamp = DateTime.Now;
                            newCorrespondance.CMN_PER_PersonInfo_CorrespondenceID = Guid.NewGuid();
                            newCorrespondance.CMN_PER_PersonInfo_RefID            = person.CMN_PER_PersonInfoID;
                            newCorrespondance.Tenant_RefID = customer.Tenant_RefID;
                            newCorrespondance.Save(Connection, Transaction);

                            //  We will need some of this code later
                            //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{
                            //    CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID,
                            //    Tenant_RefID = customer.Tenant_RefID
                            //}).SingleOrDefault()

                            //if (correspodenceTypeQuery != null)
                            //{
                            //    correspodenceTypeQuery.DisplayName = item.CorrespondenceName;
                            //    correspodenceTypeQuery.Save(Connection,Transaction);
                            //}
                            //else
                            //{
                            //    ORM_CMN_PER_PersonInfo_CorrespondenceType newCorrespodenceType = new ORM_CMN_PER_PersonInfo_CorrespondenceType();
                            //    newCorrespodenceType.Tenant_RefID = customer.Tenant_RefID;
                            //    newCorrespodenceType.CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID;
                            //    newCorrespodenceType.DisplayName = item.CorrespondenceName;
                            //}
                        }
                    }
                }
            }
            return(returnValue);

            #endregion UserCode
        }
Пример #23
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
        }
Пример #24
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_L5DD_GRGFRP_1403_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5DD_GRGFRP_1403 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5DD_GRGFRP_1403_Array();
            var retVal      = new List <L5DD_GRGFRP_1403>();
            L5DD_GRGFRP_1403 revisionGroupItem;

            //Put your code here
            #region Realestate
            ORM_RES_RealestateProperty realestateProperty = new ORM_RES_RealestateProperty();
            if (Parameter.RealestatePropertyID != Guid.Empty)
            {
                var realestatePropertyResult = realestateProperty.Load(Connection, Transaction, Parameter.RealestatePropertyID);
                if (realestatePropertyResult.Status != FR_Status.Success || realestateProperty.RES_RealestatePropertyID == Guid.Empty)
                {
                    return(null);
                }
            }
            #endregion

            #region Address
            ORM_CMN_Address address = new ORM_CMN_Address();

            ORM_CMN_LOC_Location location = new ORM_CMN_LOC_Location();
            var locationResult            = location.Load(Connection, Transaction, realestateProperty.RealestateProperty_Location_RefID);
            if (locationResult.Status == FR_Status.Success && location.CMN_LOC_LocationID != Guid.Empty)
            {
                var addressResult = address.Load(Connection, Transaction, location.Address_RefID);
                if (locationResult.Status != FR_Status.Success || location.CMN_LOC_LocationID == Guid.Empty)
                {
                    address = null;
                }
            }
            #endregion

            #region Revision groups for realestrate
            ORM_RES_DUD_RevisionGroup.Query revisionGroupQuery = new ORM_RES_DUD_RevisionGroup.Query();
            revisionGroupQuery.Tenant_RefID             = securityTicket.TenantID;
            revisionGroupQuery.IsDeleted                = false;
            revisionGroupQuery.RealestateProperty_RefID = realestateProperty.RES_RealestatePropertyID;
            List <ORM_RES_DUD_RevisionGroup> revisionGroupList = ORM_RES_DUD_RevisionGroup.Query.Search(Connection, Transaction, revisionGroupQuery);
            #endregion

            #region Buildings for realestate
            ORM_RES_BLD_Building_RevisionHeader.Query revisionHeaderQuery = new ORM_RES_BLD_Building_RevisionHeader.Query();
            revisionHeaderQuery.Tenant_RefID             = securityTicket.TenantID;
            revisionHeaderQuery.IsDeleted                = false;
            revisionHeaderQuery.RealestateProperty_RefID = realestateProperty.RES_RealestatePropertyID;
            ORM_RES_BLD_Building_RevisionHeader revisionHeader = ORM_RES_BLD_Building_RevisionHeader.Query.Search(Connection, Transaction, revisionHeaderQuery).FirstOrDefault();

            List <ORM_RES_BLD_Building> buildings = new List <ORM_RES_BLD_Building>();
            List <ORM_RES_DUD_Revision> revisions = new List <ORM_RES_DUD_Revision>();
            List <ORM_RES_BLD_Building_2_BuildingType>         buildingTypes = new List <ORM_RES_BLD_Building_2_BuildingType>();
            List <ORM_RES_BLD_Building_2_GarbageContainerType> buildingGarbageContainerType = new List <ORM_RES_BLD_Building_2_GarbageContainerType>();
            if (revisionHeader != null)
            {
                ORM_RES_BLD_Building.Query buildingQuery = new ORM_RES_BLD_Building.Query();
                buildingQuery.Tenant_RefID = securityTicket.TenantID;
                buildingQuery.IsDeleted    = false;
                buildingQuery.BuildingRevisionHeader_RefID = revisionHeader.RES_BLD_Building_RevisionHeaderID;
                buildings = ORM_RES_BLD_Building.Query.Search(Connection, Transaction, buildingQuery);

                if (buildings == null)
                {
                    buildings = new List <ORM_RES_BLD_Building>();
                }

                #region revisions and building types for every building
                foreach (var buildingItem in buildings)
                {
                    ORM_RES_DUD_Revision.Query revisionQuery = new ORM_RES_DUD_Revision.Query();
                    revisionQuery.Tenant_RefID           = securityTicket.TenantID;
                    revisionQuery.IsDeleted              = false;
                    revisionQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    revisions.AddRange(ORM_RES_DUD_Revision.Query.Search(Connection, Transaction, revisionQuery));

                    ORM_RES_BLD_Building_2_BuildingType.Query buildingTypeQuery = new ORM_RES_BLD_Building_2_BuildingType.Query();
                    buildingTypeQuery.Tenant_RefID           = securityTicket.TenantID;
                    buildingTypeQuery.IsDeleted              = false;
                    buildingTypeQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    buildingTypes.AddRange(ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, buildingTypeQuery));

                    ORM_RES_BLD_Building_2_GarbageContainerType.Query buildingGarbageContainerTypeQuery = new ORM_RES_BLD_Building_2_GarbageContainerType.Query();
                    buildingGarbageContainerTypeQuery.Tenant_RefID           = securityTicket.TenantID;
                    buildingGarbageContainerTypeQuery.IsDeleted              = false;
                    buildingGarbageContainerTypeQuery.RES_BLD_Building_RefID = buildingItem.RES_BLD_BuildingID;
                    buildingGarbageContainerType.AddRange(ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, buildingGarbageContainerTypeQuery));
                }
                #endregion
            }
            #endregion

            #region Revision groups
            List <L5DD_GRGFRP_1403_Buildings> buildingsResult;
            L5DD_GRGFRP_1403_Buildings        buildingResult;
            foreach (var revisionGroup in revisionGroupList)
            {
                revisionGroupItem = new L5DD_GRGFRP_1403();
                revisionGroupItem.RES_DUD_Revision_GroupID = revisionGroup.RES_DUD_Revision_GroupID;
                revisionGroupItem.RevisionGroup_Name       = revisionGroup.RevisionGroup_Name;
                revisionGroupItem.RevisionGroup_SubmittedBy_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
                revisionGroupItem.Creation_Timestamp       = revisionGroup.Creation_Timestamp;
                revisionGroupItem.Tenant_RefID             = revisionGroup.Tenant_RefID;
                revisionGroupItem.IsDeleted                = revisionGroup.IsDeleted;
                revisionGroupItem.RealestateProperty_RefID = revisionGroup.RealestateProperty_RefID;
                revisionGroupItem.RevisionGroup_Comment    = revisionGroup.RevisionGroup_Comment;

                #region Person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();

                ORM_CMN_PER_PersonInfo_2_Account.Query personInfoAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personInfoAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personInfoAccountQuery.IsDeleted         = false;
                personInfoAccountQuery.USR_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
                ORM_CMN_PER_PersonInfo_2_Account account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personInfoAccountQuery).FirstOrDefault();

                if (account != null)
                {
                    var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID);
                    if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty)
                    {
                        revisionGroupItem.FirstName = personInfo.FirstName;
                        revisionGroupItem.LastName  = personInfo.LastName;
                    }
                }
                #endregion

                #region set address info
                if (address != null)
                {
                    revisionGroupItem.Country_Name    = address.Country_Name;
                    revisionGroupItem.City_Region     = address.City_Region;
                    revisionGroupItem.City_PostalCode = address.City_PostalCode;
                    revisionGroupItem.City_Name       = address.City_Name;
                    revisionGroupItem.Street_Name     = address.Street_Name;
                    revisionGroupItem.Street_Number   = address.Street_Number;
                }
                #endregion

                #region set building info
                buildingsResult = new List <L5DD_GRGFRP_1403_Buildings>();

                // get revisions for revision group
                var revisionsForRetVal = revisions.Where(i => i.RevisionGroup_RefID == revisionGroup.RES_DUD_Revision_GroupID).ToList();
                ORM_RES_DUD_Revision revisionForBuildingID;

                // get buildings for list of revision
                List <ORM_RES_BLD_Building> buildingForRetVal = new List <ORM_RES_BLD_Building>();
                buildingForRetVal.AddRange(buildings.Where(i => revisionsForRetVal.Any(j => j.RES_BLD_Building_RefID == i.RES_BLD_BuildingID)).ToList());

                foreach (var buildingForRetValItem in buildingForRetVal)
                {
                    revisionForBuildingID = revisionsForRetVal.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID);

                    buildingResult = new L5DD_GRGFRP_1403_Buildings();
                    buildingResult.Building_Name              = buildingForRetValItem.Building_Name;
                    buildingResult.RES_BLD_BuildingID         = buildingForRetValItem.RES_BLD_BuildingID;
                    buildingResult.RES_DUD_RevisionID         = revisionForBuildingID.RES_DUD_RevisionID;
                    buildingResult.QuestionnaireVersion_RefID = revisionForBuildingID.QuestionnaireVersion_RefID;

                    buildingResult.RES_BLD_Building_Type_RefID        = buildingTypes.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID).RES_BLD_Building_Type_RefID;
                    buildingResult.RES_BLD_GarbageContainerType_RefID = buildingGarbageContainerType.FirstOrDefault(i => i.RES_BLD_Building_RefID == buildingForRetValItem.RES_BLD_BuildingID).RES_BLD_GarbageContainerType_RefID;

                    buildingsResult.Add(buildingResult);
                }
                #endregion

                revisionGroupItem.Buildings = buildingsResult.ToArray();
                retVal.Add(revisionGroupItem);
            }
            #endregion

            returnValue.Result = retVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Пример #26
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
        }
Пример #27
0
        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
        }
Пример #28
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                #region Create Mode

                #region BusinessParticipant


                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                bParticipant.IsNaturalPerson    = true;
                bParticipant.Tenant_RefID       = securityTicket.TenantID;
                bParticipant.Creation_Timestamp = DateTime.Now;
                bParticipant.Save(Connection, Transaction);

                #endregion

                #region Account

                ORM_USR_Account account = new ORM_USR_Account();

                account.Username    = Parameter.FirstName + "_" + Parameter.LastName;
                account.AccountType = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID       = securityTicket.TenantID;
                account.Creation_Timestamp = DateTime.Now;
                account.Save(Connection, Transaction);

                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                accountCode.Account_RefID                   = account.USR_AccountID;
                accountCode.AccountCode_Value               = checkCodeValue.CodeValue;
                accountCode.AccountCode_ValidFrom           = DateTime.Now;
                accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid();
                accountCode.IsAccountCode_Expirable         = false;
                accountCode.Tenant_RefID       = securityTicket.TenantID;
                accountCode.Creation_Timestamp = DateTime.Now;
                accountCode.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID;
                Device_AccountCode_StatusHistory.IsAccountCode_Active     = true;
                Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_StatusHistory.Tenant_RefID             = securityTicket.TenantID;
                Device_AccountCode_StatusHistory.Creation_Timestamp       = DateTime.Now;
                Device_AccountCode_StatusHistory.Save(Connection, Transaction);


                ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory();
                USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid();
                USR_Device_AccountCode_UsageHistory.Tenant_RefID             = securityTicket.TenantID;
                USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                USR_Device_AccountCode_UsageHistory.Creation_Timestamp       = DateTime.Now;
                USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction);


                #endregion

                #region PersonInfo and Adresses

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Salutation_General   = Parameter.Salutation_General;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryMail;
                personInfo.Address_RefID        = Guid.NewGuid();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address();
                personAdress.AssignmentID             = Guid.NewGuid();
                personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                personAdress.CMN_Address_RefID        = personInfo.Address_RefID;
                personAdress.IsPrimary    = true;
                personAdress.Tenant_RefID = securityTicket.TenantID;
                personAdress.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.CMN_AddressID   = personInfo.Address_RefID;
                adress.City_Name       = Parameter.City_Name;
                adress.Province_Name   = Parameter.Province_Name;
                adress.Street_Name     = Parameter.Street_Name;
                adress.Street_Number   = Parameter.Street_Number;
                adress.City_PostalCode = Parameter.City_PostalCode;
                adress.Tenant_RefID    = securityTicket.TenantID;
                adress.Save(Connection, Transaction);

                #endregion

                #region Contacts

                foreach (var parContact in Parameter.Contacts)
                {
                    ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                    contact.Content          = parContact.Content;
                    contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Tenant_RefID     = securityTicket.TenantID;
                    contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    contact.Save(Connection, Transaction);
                }

                #endregion

                #region Driver To Employer

                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                bpt_asBP.BusinessParticipant_RefID          = bParticipant.CMN_BPT_BusinessParticipantID;
                bpt_asBP.AssociatedParticipant_FunctionName = "Driver";
                bpt_asBP.Tenant_RefID = securityTicket.TenantID;
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);

                #endregion

                #endregion
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                personInfo.Salutation_General = Parameter.Salutation_General;
                personInfo.FirstName          = Parameter.FirstName;
                personInfo.LastName           = Parameter.LastName;
                personInfo.PrimaryEmail       = Parameter.PrimaryMail;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.Load(Connection, Transaction, personInfo.Address_RefID);
                adress.City_Name     = Parameter.City_Name;
                adress.Province_Name = Parameter.Province_Name;
                adress.Street_Name   = Parameter.Street_Name;
                adress.Street_Number = Parameter.Street_Number;
                adress.Save(Connection, Transaction);

                foreach (var parContact in Parameter.Contacts)
                {
                    var query = new ORM_CMN_PER_CommunicationContact.Query();
                    query.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    query.IsDeleted        = false;
                    query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First();
                    contact.Content      = parContact.Content;
                    contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Save(Connection, Transaction);
                }

                var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;

                var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First();
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
Пример #29
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
        }
Пример #30
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.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.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.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.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            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.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID);
                    if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    asossBParticipant.IsDeleted = true;
                    asossBParticipant.Save(Connection, Transaction);
                }


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }