protected static FR_L5DD_GDDFDD_1402 Execute(DbConnection Connection, DbTransaction Transaction, P_L5DD_GDDFDD_1402 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5DD_GDDFDD_1402();

            L5DD_GDDFDD_1402          result        = new L5DD_GDDFDD_1402();
            ORM_RES_DUD_RevisionGroup revisionGroup = new ORM_RES_DUD_RevisionGroup();
            revisionGroup.Load(Connection, Transaction, Parameter.RevisionGroupID);

            ORM_CMN_PER_PersonInfo_2_Account.Query infoToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
            infoToAccountQuery.IsDeleted         = false;
            infoToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
            infoToAccountQuery.USR_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
            List <ORM_CMN_PER_PersonInfo_2_Account> infoToAccountList = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, infoToAccountQuery);


            ORM_CMN_PER_PersonInfo.Query personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
            personInfoQuery.IsDeleted            = false;
            personInfoQuery.Tenant_RefID         = securityTicket.TenantID;
            personInfoQuery.CMN_PER_PersonInfoID = infoToAccountList[0].CMN_PER_PersonInfo_RefID;
            List <ORM_CMN_PER_PersonInfo> personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery);

            result.Creation_Timestamp       = revisionGroup.Creation_Timestamp;
            result.FirstName                = personInfo[0].FirstName;
            result.LastName                 = personInfo[0].LastName;
            result.RealestateProperty_RefID = revisionGroup.RealestateProperty_RefID;
            result.RES_DUD_Revision_GroupID = revisionGroup.RES_DUD_Revision_GroupID;
            result.RevisionGroup_Comment    = revisionGroup.RevisionGroup_Comment;
            result.RevisionGroup_Name       = revisionGroup.RevisionGroup_Name;
            result.RevisionGroup_SubmittedBy_Account_RefID = revisionGroup.RevisionGroup_SubmittedBy_Account_RefID;
            result.Tenant_RefID = securityTicket.TenantID;
            returnValue.Result  = result;
            //Put your code here
            return(returnValue);

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


            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.PrimaryEmail = null;
            personInfo.Save(Connection, Transaction);

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 3
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
        }
Exemplo n.º 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_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
        }
Exemplo n.º 6
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
        }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_DDbID_1031 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #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);
                }
                doctor.IsDeleted = true;
                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();
                bussinessParticipant.IsDeleted = true;
                bussinessParticipant.Save(Connection, Transaction);

                if (doctor.Account_RefID != Guid.Empty)
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = doctor.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).FirstOrDefault();
                    if (account2personInfo != null)
                    {
                        account2personInfo.IsDeleted = true;
                        account2personInfo.Save(Connection, Transaction);

                        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.IsDeleted = true;
                        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();

                    foreach (var contact in communicationContactsList)
                    {
                        contact.IsDeleted = true;
                        contact.Save(Connection, Transaction);
                    }
                }

                var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                query3.IsDeleted = false;
                var abpRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3);
                foreach (ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant assigned in abpRes)
                {
                    assigned.IsDeleted = true;
                    assigned.Save(Connection, Transaction);
                }

                #endregion

                ORM_CMN_BPT_CTM_Customer customer;
                ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative;
                var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQuery.Ext_BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);
                if (customerRes.Count != 0)
                {
                    customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First();
                    var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
                    SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;
                    SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First();

                    customer.IsDeleted = true;
                    customer.Save(Connection, Transaction);
                    SalesRepresentative.IsDeleted = true;
                    SalesRepresentative.Save(Connection, Transaction);
                }

                var accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                accountQuery.AccountType = 3;
                var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery);
                if (accountQueryRes.Count != 0)
                {
                    var account = accountQueryRes.First();
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);

                    var codeQuery = new ORM_USR_Device_AccountCode.Query();
                    codeQuery.Account_RefID = account.USR_AccountID;
                    var code = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, codeQuery).First();
                    code.IsDeleted = true;
                    code.Save(Connection, Transaction);

                    var codeStatusQuery = new ORM_USR_Device_AccountCode_StatusHistory.Query();
                    codeStatusQuery.Device_AccountCode_RefID = code.USR_Device_AccountCodeID;
                    var codeStatus = ORM_USR_Device_AccountCode_StatusHistory.Query.Search(Connection, Transaction, codeStatusQuery).First();
                    codeStatus.IsDeleted = true;
                    codeStatus.Save(Connection, Transaction);
                }
            }

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