protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_DBBVAFP_1703 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #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);
                }
                else
                {
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);

                    ORM_CMN_PER_PersonInfo_2_Address.Query query = new ORM_CMN_PER_PersonInfo_2_Address.Query();
                    query.CMN_Address_RefID = address.CMN_AddressID;
                    query.Tenant_RefID      = securityTicket.TenantID;
                    query.IsDeleted         = false;

                    var queryRes = ORM_CMN_PER_PersonInfo_2_Address.Query.SoftDelete(Connection, Transaction, query);
                }
            }

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2AD_SA_1755 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            var returnValue = new FR_Guid();

            var item = new ORM_CMN_Address();

            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                item.Load(Connection, Transaction, Parameter.CMN_AddressID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_AddressID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_AddressID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
            }

            item.Street_Name   = Parameter.Street_Name;
            item.Street_Number = Parameter.Street_Number;
            item.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            item.City_Region     = Parameter.City_Region;
            item.City_Name       = Parameter.City_Name;
            item.City_PostalCode = Parameter.City_PostalCode;
            item.Province_Name   = Parameter.Province_Name;
            item.Country_Name    = Parameter.Country_Name;
            item.CareOf          = Parameter.CareOf;
            item.Country_ISOCode = Parameter.Country_ISOCode;
            item.Province_EconomicRegion_RefID = Parameter.Province_EconomicRegion_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_AddressID));
        }
Exemplo n.º 3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2OF_SOA_1410 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.IsDefaultAddress)
            {
                //set previous flags as non default
                ORM_CMN_STR_Office_Address.Query.Update(Connection, Transaction,
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    Office_RefID      = Parameter.OfficeID,
                    IsDefault         = true,
                    IsShippingAddress = Parameter.IsShippingAddress,
                    IsBillingAddress  = Parameter.IsBillingAddress
                },
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    IsDefault = false
                }
                                                        );
            }

            var addressID = Guid.Empty;
            if (Parameter.AddressID == Guid.Empty)
            {
                //Create
                var saveAddressParam = new P_L2AD_SA_1755();
                saveAddressParam.CMN_AddressID   = Parameter.Address_Save.CMN_AddressID;
                saveAddressParam.CareOf          = Parameter.Address_Save.CareOf;
                saveAddressParam.Street_Name     = Parameter.Address_Save.Street_Name;
                saveAddressParam.Street_Number   = Parameter.Address_Save.Street_Number;
                saveAddressParam.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                saveAddressParam.City_Name       = Parameter.Address_Save.City_Name;
                saveAddressParam.Country_Name    = Parameter.Address_Save.Country_Name;
                saveAddressParam.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                addressID = cls_Save_Address.Invoke(Connection, Transaction, saveAddressParam, securityTicket).Result;

                var OfficeAddress = new ORM_CMN_STR_Office_Address();

                OfficeAddress.CMN_Address_RefID     = addressID;
                OfficeAddress.Office_RefID          = Parameter.OfficeID;
                OfficeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                OfficeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                OfficeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                OfficeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;
                OfficeAddress.IsDefault             = Parameter.IsDefaultAddress;
                OfficeAddress.Tenant_RefID          = securityTicket.TenantID;
                OfficeAddress.Save(Connection, Transaction);
            }
            else
            {
                //Update
                addressID = Parameter.AddressID;

                var address = new ORM_CMN_Address();
                address.Load(Connection, Transaction, Parameter.AddressID);
                address.CareOf          = Parameter.Address_Save.CareOf;
                address.Street_Name     = Parameter.Address_Save.Street_Name;
                address.Street_Number   = Parameter.Address_Save.Street_Number;
                address.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                address.City_Name       = Parameter.Address_Save.City_Name;
                address.Country_Name    = Parameter.Address_Save.Country_Name;
                address.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                address.Save(Connection, Transaction);

                var queryOfficeAddress = new ORM_CMN_STR_Office_Address.Query();
                queryOfficeAddress.CMN_Address_RefID = Parameter.AddressID;
                queryOfficeAddress.Office_RefID      = Parameter.OfficeID;
                queryOfficeAddress.IsDeleted         = false;
                var officeAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, queryOfficeAddress).FirstOrDefault();

                officeAddress.IsDefault             = Parameter.IsDefaultAddress;
                officeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                officeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                officeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                officeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;

                officeAddress.Save(Connection, Transaction);
            }


            #region Update DefaultAdresses

            var defaultShippingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultShippingAddressQuery.Office_RefID      = Parameter.OfficeID;
            defaultShippingAddressQuery.IsDeleted         = false;
            defaultShippingAddressQuery.IsDefault         = true;
            defaultShippingAddressQuery.IsShippingAddress = true;
            var defaultShippingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultShippingAddressQuery).SingleOrDefault();

            var defaultBillingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultBillingAddressQuery.Office_RefID     = Parameter.OfficeID;
            defaultBillingAddressQuery.IsDeleted        = false;
            defaultBillingAddressQuery.IsDefault        = true;
            defaultBillingAddressQuery.IsBillingAddress = true;
            var defaultBillingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultBillingAddressQuery).SingleOrDefault();

            var office = new ORM_CMN_STR_Office();
            office.Load(Connection, Transaction, Parameter.OfficeID);

            office.Default_BillingAddress_RefID  = (defaultBillingAddress != null) ? defaultBillingAddress.CMN_Address_RefID : Guid.Empty;
            office.Default_ShippingAddress_RefID = (defaultShippingAddress != null) ? defaultShippingAddress.CMN_Address_RefID : Guid.Empty;
            office.Save(Connection, Transaction);

            #endregion

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 4
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
        }
Exemplo n.º 5
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
        }
Exemplo n.º 6
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
        }
Exemplo n.º 7
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
        }
Exemplo n.º 8
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.º 9
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_GPBD_1613 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            returnValue.Result = new Guid();
            var patient = new ORM_HEC_Patient();
            //var serializer = new JsonNetSerializer();
            //var connection = new ElasticConnection((String)HttpContext.GetGlobalResourceObject("Global", "ElasticConnection"), 9200);

            #region Save

            if (Parameter.ID == null || Parameter.ID == Guid.Empty)
            {
                //ORM_HEC_Patient
                patient.HEC_PatientID      = Guid.NewGuid();
                patient.Tenant_RefID       = securityTicket.TenantID;
                patient.Creation_Timestamp = DateTime.Now;
                patient.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid();
                patient.Save(Connection, Transaction);

                //ORM_CMN_BPT_BusinessParticipant
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID;
                businessParticipant.IsNaturalPerson        = true;
                businessParticipant.Tenant_RefID           = securityTicket.TenantID;
                businessParticipant.Creation_Timestamp     = DateTime.Now;
                businessParticipant.Modification_Timestamp = DateTime.Now;
                businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businessParticipant.Save(Connection, Transaction);

                //ORM_CMN_PER_PersonInfo
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryEmail;
                personInfo.Title = Parameter.Title;
                personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID;
                personInfo.BirthDate                  = Parameter.BirthDate;
                personInfo.Gender                     = Int32.Parse(Parameter.Gender);
                personInfo.Salutation_General         = Parameter.AcademicTitle;
                personInfo.Address_RefID              = Guid.NewGuid();
                personInfo.Tenant_RefID               = securityTicket.TenantID;
                personInfo.Creation_Timestamp         = DateTime.Now;
                personInfo.Modification_Timestamp     = DateTime.Now;
                personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year;
                personInfo.Save(Connection, Transaction);

                //ORM_CMN_Address
                var address = new ORM_CMN_Address();
                address.CMN_AddressID      = personInfo.Address_RefID;
                address.Street_Name        = Parameter.Street_Name;
                address.Street_Number      = Parameter.Street_Number;
                address.City_Name          = Parameter.City_Name;
                address.City_PostalCode    = Parameter.City_PostalCode;
                address.Country_ISOCode    = Parameter.Country_ISOCode;
                address.Tenant_RefID       = securityTicket.TenantID;
                address.Creation_Timestamp = DateTime.Now;
                address.Save(Connection, Transaction);

                //ORM_CMN_PER_PersonInfo_SocialSecurityNumber
                var socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber();
                socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid();
                socialSecurityNumber.PersonInfo_RefID     = personInfo.CMN_PER_PersonInfoID;
                socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber;
                socialSecurityNumber.Tenant_RefID         = securityTicket.TenantID;
                socialSecurityNumber.Creation_Timestamp   = DateTime.Now;
                socialSecurityNumber.Save(Connection, Transaction);

                var TelephoneCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                                          new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                var MobileCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                                       new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();
                var EmailType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                               new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();
                //add into database
                //var UrlType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                //      new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                //      {
                //          Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL),
                //          Tenant_RefID = securityTicket.TenantID,
                //          IsDeleted = false
                //      }).Single();
                var FaxType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                             new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Fax),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();



                ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact();

                communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsPhone.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsPhone.Contact_Type           = TelephoneCompanyType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsPhone.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content;
                communicationContactsPhone.Creation_Timestamp     = DateTime.Now;
                communicationContactsPhone.Modification_Timestamp = DateTime.Now;
                communicationContactsPhone.Tenant_RefID           = securityTicket.TenantID;
                communicationContactsPhone.Save(Connection, Transaction);

                ORM_CMN_PER_CommunicationContact communicationContactsMobile = new ORM_CMN_PER_CommunicationContact();

                communicationContactsMobile.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsMobile.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsMobile.Contact_Type           = MobileCompanyType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsMobile.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile)).Single().Content;
                communicationContactsMobile.Creation_Timestamp     = DateTime.Now;
                communicationContactsMobile.Modification_Timestamp = DateTime.Now;
                communicationContactsMobile.Tenant_RefID           = securityTicket.TenantID;

                communicationContactsMobile.Save(Connection, Transaction);

                ORM_CMN_PER_CommunicationContact communicationContactsEmail = new ORM_CMN_PER_CommunicationContact();

                communicationContactsEmail.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsEmail.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsEmail.Contact_Type           = EmailType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsEmail.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email)).Single().Content;
                communicationContactsEmail.Creation_Timestamp     = DateTime.Now;
                communicationContactsEmail.Modification_Timestamp = DateTime.Now;
                communicationContactsEmail.Tenant_RefID           = securityTicket.TenantID;

                communicationContactsEmail.Save(Connection, Transaction);

                //*******************Save languages to patient************************

                if (Parameter.Languages != null && Parameter.Languages.Count() != 0)
                {
                    foreach (var language in Parameter.Languages)
                    {
                        ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage();
                        bpLanguage.CMN_BPT_BusinessParticipant_RefID            = businessParticipant.CMN_BPT_BusinessParticipantID;
                        bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid();
                        bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID;
                        bpLanguage.IsDeleted          = false;
                        bpLanguage.Tenant_RefID       = securityTicket.TenantID;
                        bpLanguage.Save(Connection, Transaction);
                    }
                }

                //#region Upload To Elastic

                //bool indexExists = true;
                //#region set Mapping
                //string jsonPatientMapping = new MapBuilder<Patient>()
                //             .RootObject("patient", ro => ro
                //             .Properties(pr => pr
                //                 .MultiField("name", mfp => mfp.Fields(f => f
                //                     .String("name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                     )
                //                 )
                //                  .MultiField("last_name", mfp => mfp.Fields(f => f
                //                                     .String("last_name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                    .MultiField("birthday", mfp => mfp.Fields(f => f
                //                                     .String("birthday", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                 .MultiField("age", mfp => mfp.Fields(f => f
                //                                     .String("age", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                 )).BuildBeautified();
                //#endregion


                //try
                //{
                //    connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString()));
                //}
                //catch (OperationException ex)
                //{
                //    if (ex.HttpStatusCode == 404)
                //        indexExists = false;
                //}

                //if (!indexExists)
                //{

                //    #region set index settings
                //    string settings = new IndexSettingsBuilder()
                //                          .Analysis(anl => anl
                //                              .Filter(fil => fil
                //                                  .EdgeNGram("autocomplete_filter", gr => gr.MinGram(1).MaxGram(20)))
                //                              .Analyzer(a => a
                //                                  .Custom("caseinsensitive", custom => custom
                //                                      .Tokenizer(DefaultTokenizers.keyword)
                //                                      .Filter("lowercase")
                //                                  )
                //                                  .Custom("autocomplete", custom => custom
                //                                      .Tokenizer(DefaultTokenizers.standard)
                //                                      .Filter("lowercase", "autocomplete_filter")
                //                                  )
                //                              )
                //                          )
                //                          .BuildBeautified();
                //    #endregion
                //    connection.Put(securityTicket.TenantID.ToString(), settings);

                //}


                //#region check if type exists

                //bool typeExists = true;

                //try
                //{
                //    connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString() + "/patient"));
                //}
                //catch (OperationException ex)
                //{
                //    if (ex.HttpStatusCode == 404)
                //        typeExists = false;
                //}
                //#endregion


                //if (!typeExists)
                //    connection.Put(new PutMappingCommand(securityTicket.TenantID.ToString(), "patient"), jsonPatientMapping);

                //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh();

                //List<Patient> patientList = new List<Patient>();
                //Patient patient_elastic = new Patient();
                //patient_elastic.id = patient.HEC_PatientID.ToString();
                //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString();
                //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString();
                //patient_elastic.last_name = Parameter.LastName;
                //patient_elastic.name = Parameter.FirstName;
                //patientList.Add(patient_elastic);

                //string bulkJson = new BulkBuilder(serializer)
                //    .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id)
                //    );
                //connection.Post(bulkCommand, bulkJson);

                //#endregion
            }
            #endregion
            else
            {
                #region Delete
                if (Parameter.isDeleted)
                {
                    var patientQuery = new ORM_HEC_Patient.Query();
                    patientQuery.HEC_PatientID = Parameter.ID;
                    patientQuery.IsDeleted     = false;
                    patientQuery.Tenant_RefID  = securityTicket.TenantID;

                    patient           = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single();
                    patient.IsDeleted = true;
                    patient.Save(Connection, Transaction);

                    var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID;
                    businessParticipantQuery.IsDeleted    = false;
                    businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;

                    var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();
                    businessParticipant.IsDeleted = true;
                    businessParticipant.Save(Connection, Transaction);

                    var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                    personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    personInfoQuery.IsDeleted            = false;
                    personInfoQuery.Tenant_RefID         = securityTicket.TenantID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single();
                    personInfo.IsDeleted = true;
                    personInfo.Save(Connection, Transaction);

                    var addressQuery = new ORM_CMN_Address.Query();
                    addressQuery.CMN_AddressID = personInfo.Address_RefID;
                    addressQuery.IsDeleted     = false;
                    addressQuery.Tenant_RefID  = securityTicket.TenantID;

                    var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single();
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);

                    var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query();
                    socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    socialSecurityNumberQuery.IsDeleted        = false;
                    socialSecurityNumberQuery.Tenant_RefID     = securityTicket.TenantID;

                    var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).Single();
                    socialSecurityNumber.IsDeleted = true;
                    socialSecurityNumber.Save(Connection, Transaction);

                    var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                    communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    communicationContactQuery.IsDeleted        = false;
                    communicationContactQuery.Tenant_RefID     = securityTicket.TenantID;

                    var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList();

                    ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.SoftDelete(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                        CMN_BPT_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                    });

                    //// delete on Elastic
                    //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString());
                }
                #endregion
                #region Edit
                else
                {
                    var patientQuery = new ORM_HEC_Patient.Query();
                    patientQuery.HEC_PatientID = Parameter.ID;
                    patientQuery.IsDeleted     = false;
                    patientQuery.Tenant_RefID  = securityTicket.TenantID;

                    patient = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single();

                    var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID;
                    businessParticipantQuery.IsDeleted    = false;
                    businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;

                    var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

                    var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                    personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    personInfoQuery.IsDeleted            = false;
                    personInfoQuery.Tenant_RefID         = securityTicket.TenantID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single();
                    personInfo.FirstName    = Parameter.FirstName;
                    personInfo.LastName     = Parameter.LastName;
                    personInfo.PrimaryEmail = Parameter.PrimaryEmail;
                    personInfo.Title        = Parameter.Title;
                    personInfo.Gender       = Int32.Parse(Parameter.Gender);
                    personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID;
                    personInfo.BirthDate                  = Parameter.BirthDate;
                    personInfo.Salutation_General         = Parameter.AcademicTitle;
                    personInfo.Modification_Timestamp     = DateTime.Now;
                    personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year;
                    personInfo.Save(Connection, Transaction);

                    if (personInfo.Address_RefID != Guid.Empty)
                    {
                        var addressQuery = new ORM_CMN_Address.Query();
                        addressQuery.CMN_AddressID = personInfo.Address_RefID;
                        addressQuery.IsDeleted     = false;
                        addressQuery.Tenant_RefID  = securityTicket.TenantID;

                        var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single();
                        address.Street_Name     = Parameter.Street_Name;
                        address.Street_Number   = Parameter.Street_Number;
                        address.City_Name       = Parameter.City_Name;
                        address.City_PostalCode = Parameter.City_PostalCode;
                        address.Country_ISOCode = Parameter.Country_ISOCode;
                        address.Save(Connection, Transaction);
                    }
                    else
                    {
                        var address = new ORM_CMN_Address();
                        address.CMN_AddressID      = Guid.NewGuid();
                        address.Street_Name        = Parameter.Street_Name;
                        address.Street_Number      = Parameter.Street_Number;
                        address.City_Name          = Parameter.City_Name;
                        address.City_PostalCode    = Parameter.City_PostalCode;
                        address.Country_ISOCode    = Parameter.Country_ISOCode;
                        address.Tenant_RefID       = securityTicket.TenantID;
                        address.Creation_Timestamp = DateTime.Now;
                        address.Save(Connection, Transaction);


                        personInfo.Address_RefID = address.CMN_AddressID;
                        personInfo.Save(Connection, Transaction);
                    }


                    var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query();
                    socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    socialSecurityNumberQuery.IsDeleted        = false;
                    socialSecurityNumberQuery.Tenant_RefID     = securityTicket.TenantID;

                    var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).SingleOrDefault();

                    if (socialSecurityNumber == null)
                    {
                        socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber();
                        socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid();
                        socialSecurityNumber.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                        socialSecurityNumber.Tenant_RefID     = securityTicket.TenantID;
                    }

                    socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber;
                    socialSecurityNumber.Save(Connection, Transaction);

                    var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                    communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    communicationContactQuery.IsDeleted        = false;
                    communicationContactQuery.Tenant_RefID     = securityTicket.TenantID;

                    var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList();

                    List <string> unusedTypes = new List <string>()
                    {
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email)
                    };

                    foreach (var communicationContact in communicationContactList)
                    {
                        var communicationContact_TypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                        communicationContact_TypeQuery.CMN_PER_CommunicationContact_TypeID = communicationContact.Contact_Type;
                        communicationContact_TypeQuery.IsDeleted    = false;
                        communicationContact_TypeQuery.Tenant_RefID = securityTicket.TenantID;
                        var communicationContact_Type = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, communicationContact_TypeQuery).Single();

                        var newType = Parameter.ContactTypes.Where(i => i.Type == communicationContact_Type.Type).Single();
                        communicationContact.Content = newType.Content;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.Save(Connection, Transaction);

                        if (unusedTypes.Contains(communicationContact_Type.Type))
                        {
                            unusedTypes.Remove(communicationContact_Type.Type);
                        }
                    }

                    var contactTypes = cls_Get_AllComunicationContactTypes.Invoke(Connection, Transaction, securityTicket).Result.ToList();

                    foreach (var type in unusedTypes)
                    {
                        ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact();

                        communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid();
                        communicationContactsPhone.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                        P_L2CN_GCTIDfGPMID_1359 contantTypeParam = new P_L2CN_GCTIDfGPMID_1359();
                        contantTypeParam.Type = type;
                        var contantTypeID = cls_Get_ContantTypeID_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, contantTypeParam, securityTicket).Result.ContactTypeID;
                        communicationContactsPhone.Contact_Type           = contantTypeID;
                        communicationContactsPhone.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content;
                        communicationContactsPhone.Creation_Timestamp     = DateTime.Now;
                        communicationContactsPhone.Modification_Timestamp = DateTime.Now;
                        communicationContactsPhone.Tenant_RefID           = securityTicket.TenantID;
                        communicationContactsPhone.Save(Connection, Transaction);
                    }

                    //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString());
                    //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh();

                    //List<Patient> patientList = new List<Patient>();
                    //Patient patient_elastic = new Patient();
                    //patient_elastic.id = patient.HEC_PatientID.ToString();
                    //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString();
                    //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString();
                    //patient_elastic.last_name = Parameter.LastName;
                    //patient_elastic.name = Parameter.FirstName;
                    //patientList.Add(patient_elastic);

                    //string bulkJson = new BulkBuilder(serializer)
                    //    .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id)
                    //    );
                    //connection.Post(bulkCommand, bulkJson);


                    #region languages

                    if (Parameter.Languages == null || Parameter.Languages.Count() == 0)
                    {
                        P_L5PA_GPBD_1613_Languages Languages = new P_L5PA_GPBD_1613_Languages();
                        Languages.CMN_Language_RefID = Guid.Empty;
                    }
                    else if (Parameter.Languages != null || Parameter.Languages.Count() != 0)
                    {
                        foreach (var language in Parameter.Languages)
                        {
                            var languageToPatient = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                                CMN_Language_RefID = language.CMN_Language_RefID, CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                            }).FirstOrDefault();
                            if (languageToPatient == null)
                            {
                                ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage();
                                bpLanguage.CMN_BPT_BusinessParticipant_RefID            = patient.CMN_BPT_BusinessParticipant_RefID;
                                bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid();
                                bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID;
                                bpLanguage.IsDeleted          = false;
                                bpLanguage.Tenant_RefID       = securityTicket.TenantID;
                                bpLanguage.Save(Connection, Transaction);
                            }
                        }

                        // deleting languages to patient that were deleted during edit

                        List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                            CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                        });
                        foreach (var languageToDoctor in languageToDoctorList)
                        {
                            if (Parameter.Languages.FirstOrDefault(x => x.CMN_Language_RefID == languageToDoctor.CMN_Language_RefID) == null)
                            {
                                languageToDoctor.IsDeleted = true;
                                languageToDoctor.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                            CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                        });
                        if (languageToDoctorList != null || languageToDoctorList.Count() != 0)
                        {
                            foreach (var language in languageToDoctorList)
                            {
                                language.IsDeleted = true;
                                language.Save(Connection, Transaction);
                            }
                        }
                    }

                    #endregion
                }
                #endregion
            }
            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 10
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OF_SO_1428 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();



            var item = new ORM_CMN_STR_Office();
            if (Parameter.CMN_STR_OfficeID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.CMN_STR_OfficeID);
                if (result.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(error);
                }
            }



            var 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.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            address.City_PostalCode             = Parameter.City_PostalCode;
            address.City_Region   = Parameter.City_Region;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Tenant_RefID  = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            item.Default_BillingAddress_RefID  = address.CMN_AddressID;
            item.Default_ShippingAddress_RefID = address.CMN_AddressID;
            item.Tenant_RefID                   = securityTicket.TenantID;
            item.Default_FaxNumber              = Parameter.Default_FaxNumber;
            item.Default_PhoneNumber            = Parameter.Default_PhoneNumber;
            item.Office_Name                    = Parameter.OfficeName;
            item.Office_Description             = Parameter.OfficeDescription;
            item.Office_ShortName               = Parameter.OfficeShortName;
            item.CMN_CAL_CalendarInstance_RefID = Parameter.CMN_CAL_CalendarInstance_RefID;
            item.Region_RefID                   = Parameter.Region_RefID;
            item.Country_RefID                  = Parameter.Country_RefID;

            ORM_CMN_CAL_CalendarInstance calendar = new ORM_CMN_CAL_CalendarInstance();
            if (Parameter.CMN_CAL_CalendarInstance_RefID != Guid.Empty)
            {
                var result = calendar.Load(Connection, Transaction, Parameter.CMN_CAL_CalendarInstance_RefID);
                if (result.Status != FR_Status.Success || calendar.CMN_CAL_CalendarInstanceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            calendar.WeekStartsOnDay = 1;
            calendar.Save(Connection, Transaction);
            item.CMN_CAL_CalendarInstance_RefID = calendar.CMN_CAL_CalendarInstanceID;
            item.Save(Connection, Transaction);



            ORM_CMN_STR_Office_2_CostCenter whereCC2OInstance = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_STR_Office_2_CostCenter>();
            whereCC2OInstance.Office_RefID = Parameter.CMN_STR_OfficeID;
            CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereCC2OInstance);
            if (Parameter.Costcenter_RefID != Guid.Empty)
            {
                var cc2o = new ORM_CMN_STR_Office_2_CostCenter();
                cc2o.CostCenter_RefID = Parameter.Costcenter_RefID;
                cc2o.IsDefault        = true;
                cc2o.IsDeleted        = false;
                cc2o.Tenant_RefID     = securityTicket.TenantID;
                cc2o.Office_RefID     = item.CMN_STR_OfficeID;
                cc2o.Save(Connection, Transaction);
            }
            var query1 = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
            query1.Tenant_RefID = securityTicket.TenantID;
            query1.Office_RefID = item.CMN_STR_OfficeID;
            var res = ORM_CMN_STR_Office_ResponsiblePerson.Query.SoftDelete(Connection, Transaction, query1);
            if (Parameter.ResponsiblePerson != null && Parameter.ResponsiblePerson.Length > 0)
            {
                foreach (P_L5OF_SO_1428_ResponsiblePerson obj in Parameter.ResponsiblePerson)
                {
                    ORM_CMN_STR_Office_ResponsiblePerson person = new ORM_CMN_STR_Office_ResponsiblePerson();
                    if (obj.AssignmentID != Guid.Empty)
                    {
                        var result = calendar.Load(Connection, Transaction, obj.AssignmentID);
                        if (result.Status != FR_Status.Success || person.CMN_STR_Office_ResponsiblePersonID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (obj.AssignmentID != Guid.Empty)
                    {
                        person.IsDeleted = true;
                    }
                    else
                    {
                        person.CMN_BPT_EMP_Employee_RefID = obj.ResponsibleEmployeeID;
                        person.Office_RefID = item.CMN_STR_OfficeID;
                        person.Tenant_RefID = securityTicket.TenantID;
                    }

                    person.Save(Connection, Transaction);
                }
            }

            return(new FR_Guid(item.CMN_STR_OfficeID));

            #endregion UserCode
        }
Exemplo n.º 11
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
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SMSAFP_1547 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            P_L6PA_GMSPfID_1538 getPatientParam = new P_L6PA_GMSPfID_1538();
            getPatientParam.HEC_PatientID = Parameter.HEC_PatientID;
            L6PA_GMSPfID_1538 patient = cls_Get_MS_Patients_For_ID.Invoke(Connection, Transaction, getPatientParam, securityTicket).Result;

            if (patient == null)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            ORM_CMN_PER_PersonInfo_2_Address.Query query = new ORM_CMN_PER_PersonInfo_2_Address.Query();
            query.CMN_PER_PersonInfo_RefID = patient.CMN_PER_PersonInfoID;
            query.Tenant_RefID             = securityTicket.TenantID;
            query.IsDeleted = false;
            var queryRes = ORM_CMN_PER_PersonInfo_2_Address.Query.Search(Connection, Transaction, query);

            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.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.City_Name       = Parameter.City_Name;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            ORM_CMN_PER_PersonInfo_2_Address assignment = queryRes.FirstOrDefault(a => a.CMN_Address_RefID == Parameter.CMN_AddressID);
            if (assignment == null)
            {
                assignment = new ORM_CMN_PER_PersonInfo_2_Address();

                assignment.CMN_Address_RefID        = address.CMN_AddressID;
                assignment.CMN_PER_PersonInfo_RefID = patient.CMN_PER_PersonInfoID;
                assignment.Tenant_RefID             = securityTicket.TenantID;
                if (queryRes.Count == 0)
                {
                    assignment.IsPrimary = true;
                }
                assignment.SequenceNumber = queryRes.Count + 1;
            }

            assignment.Save(Connection, Transaction);

            returnValue.Result = address.CMN_AddressID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 13
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6RP_SNRPFMA_1321 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            P_L5RE_SREPBI_0846 realestateParam = new P_L5RE_SREPBI_0846();
            realestateParam.InformationSubmittedBy_Account_RefID        = securityTicket.AccountID;
            realestateParam.LandRegistrationEntry_GroundAreaSize_in_sqm = 0;
            realestateParam.RealestateProperty_ConstructionDate         = new DateTime(0);
            realestateParam.RealestateProperty_InformationDate          = DateTime.Now;
            realestateParam.RealestateProperty_InternalID               = Guid.NewGuid().ToString();
            realestateParam.RealestateProperty_LivingSpace_in_sqm       = 0;
            realestateParam.RealestateProperty_NumberOfResidentialUnits = 0;
            realestateParam.RealestateProperty_RefurbishmentDate        = new DateTime(0);
            realestateParam.RealestateProperty_Title = Parameter.Title;
            realestateParam.RES_RealestateProperty_ConstructionTypeID    = Guid.Empty;
            realestateParam.RES_RealestateProperty_SourceOfInformationID = Guid.Empty;
            realestateParam.RES_RealestateProperty_TypeID = Guid.Empty;
            realestateParam.Longitude = Parameter.Longitude;
            realestateParam.Lattitude = Parameter.Lattitude;

            returnValue.Result = cls_Save_RealestateProperty_BasicInfo.Invoke(Connection, Transaction, realestateParam, securityTicket).Result;



            P_L5LI_SLI_1538 locationInfoParam = new P_L5LI_SLI_1538();
            locationInfoParam.City_Name       = Parameter.City;
            locationInfoParam.City_PostalCode = Parameter.ZipCode;
            locationInfoParam.City_Region     = Parameter.Region;
            L3CTR_GAC_1420[] countries = cls_Get_All_Countries.Invoke(Connection, Transaction, securityTicket).Result;

            if (countries.Any(c => c.Country_ISOCode_Alpha2 == Parameter.Country))
            {
                locationInfoParam.Country_RefID = countries.Where(c => c.Country_ISOCode_Alpha2 == Parameter.Country).Select(c => c.CMN_CountryID).FirstOrDefault();

                ORM_CMN_Address address = new ORM_CMN_Address();
                address.Tenant_RefID    = securityTicket.TenantID;
                address.Country_ISOCode = Parameter.Country;
                address.Save(Connection, Transaction);

                locationInfoParam.AddressID = address.CMN_AddressID;
            }

            locationInfoParam.Province_Name        = Parameter.Province;
            locationInfoParam.Street_Name          = Parameter.StreetName;
            locationInfoParam.Street_Number        = Parameter.StreetNumber;
            locationInfoParam.RealestatePropertyID = returnValue.Result;

            cls_Save_LocationInformation.Invoke(Connection, Transaction, locationInfoParam, securityTicket);

            foreach (var building in Parameter.Buildings)
            {
                P_L5BD_SB_1359 buildingParam = new P_L5BD_SB_1359();
                buildingParam.AppartmentCount        = building.numberOfApartments;
                buildingParam.atticsCount            = building.numberOfAttics;
                buildingParam.basementsCount         = building.numberOfBasements;
                buildingParam.Building_Name          = building.name;
                buildingParam.facadesCount           = building.numberOfFacades;
                buildingParam.hvarcsCount            = building.numberOfHvacrs;
                buildingParam.outdoorfacilitiesCount = building.numberOfOutdoorFacilities;
                buildingParam.RealestatePropertyID   = returnValue.Result;
                buildingParam.roofCount       = building.numberOfRoofs;
                buildingParam.staircasesCount = building.numberOfStaircases;
                buildingParam.Building_Name   = building.name;
                cls_Save_Building.Invoke(Connection, Transaction, buildingParam, securityTicket);
            }
            //Put your code here
            return(returnValue);

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

            var statusUploaded = ORM_MRS_RUN_MeasurementRun_Status.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(MeasurementRunStatus.Uploaded),
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            }).Single();

            var run = new ORM_MRS_RUN_MeasurementRun()
            {
                Tenant_RefID             = securityTicket.TenantID,
                MRS_RUN_MeasurementRunID = Guid.NewGuid(),
                DateFrom            = DateTime.Now,
                DateThrough         = DateTime.MaxValue,
                CurrentStatus_RefID = statusUploaded.MRS_RUN_MeasurementRun_StatusID
            };

            returnValue.Result = run.MRS_RUN_MeasurementRunID;

            var account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
            {
                Tenant_RefID  = securityTicket.TenantID,
                USR_AccountID = securityTicket.AccountID
            }).Single();


            var runHistory = new ORM_MRS_RUN_MeasurementRun_StatusHistory()
            {
                Tenant_RefID = securityTicket.TenantID,
                MRS_RUN_MeasurementRun_StatusHistoryID = Guid.NewGuid(),
                MeasurementRun_Status_RefID            = statusUploaded.MRS_RUN_MeasurementRun_StatusID,
                TriggeredBy_BusinessParticipant_RefID  = account.BusinessParticipant_RefID,
                MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID,
                Comment = string.Empty
            };

            run.Save(Connection, Transaction);
            runHistory.Save(Connection, Transaction);

            foreach (var row in Parameter.Positions)
            {
                #region reader
                var readerPersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    PrimaryEmail = row.ReaderEmail
                }).SingleOrDefault();

                if (readerPersonInfo == null)
                {
                    readerPersonInfo = new ORM_CMN_PER_PersonInfo()
                    {
                        Tenant_RefID         = securityTicket.TenantID,
                        PrimaryEmail         = row.ReaderEmail,
                        CMN_PER_PersonInfoID = Guid.NewGuid()
                    };
                }

                readerPersonInfo.FirstName = row.ReaderFirstName;
                readerPersonInfo.LastName  = row.ReaderLastName;

                readerPersonInfo.Save(Connection, Transaction);

                var readerBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    Tenant_RefID    = securityTicket.TenantID,
                    IsDeleted       = false,
                    IsNaturalPerson = true,
                    IfNaturalPerson_CMN_PER_PersonInfo_RefID = readerPersonInfo.CMN_PER_PersonInfoID
                }).SingleOrDefault();

                if (readerBP == null)
                {
                    readerBP = new ORM_CMN_BPT_BusinessParticipant()
                    {
                        CMN_BPT_BusinessParticipantID = Guid.NewGuid(),
                        Tenant_RefID    = securityTicket.TenantID,
                        IsNaturalPerson = true,
                        IfNaturalPerson_CMN_PER_PersonInfo_RefID = readerPersonInfo.CMN_PER_PersonInfoID,
                    };

                    readerBP.Save(Connection, Transaction);
                }

                var bpCode = ORM_CMN_BPT_BusinessParticipant_AccessCode.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_AccessCode.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    BusinessParticipant_RefID = readerBP.CMN_BPT_BusinessParticipantID,
                    IsValid            = true,
                    IsDeviceAccessCode = true
                }).SingleOrDefault();

                if (bpCode == null)
                {
                    bpCode = new ORM_CMN_BPT_BusinessParticipant_AccessCode()
                    {
                        CMN_BPT_BusinessParticipant_AccessCodeID = Guid.NewGuid(),
                        Tenant_RefID = securityTicket.TenantID,
                        BusinessParticipant_RefID = readerBP.CMN_BPT_BusinessParticipantID,
                        IsValid            = true,
                        IsDeviceAccessCode = true,
                        ValidFrom          = DateTime.Now,
                        ValidThrough       = DateTime.MaxValue,
                        Code = StringUtils.CodeGen(8).ToLower()
                    };
                    bpCode.Save(Connection, Transaction);
                }

                #endregion

                #region meter
                var meter = ORM_MRS_MPT_Meter.Query.Search(Connection, Transaction, new ORM_MRS_MPT_Meter.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    SerialNumber = row.MeterSerialNumber
                }).SingleOrDefault();

                if (meter == null)
                {
                    meter = new ORM_MRS_MPT_Meter()
                    {
                        MRS_MPT_MeterID = Guid.NewGuid(),
                        SerialNumber    = row.MeterSerialNumber,
                        Tenant_RefID    = securityTicket.TenantID,
                    };
                    meter.Save(Connection, Transaction);
                }

                var meterBinding = ORM_MRS_MPT_MeasuringPoint_MeterBinding.Query.Search(Connection, Transaction, new ORM_MRS_MPT_MeasuringPoint_MeterBinding.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    Meter_RefID  = meter.MRS_MPT_MeterID
                }).SingleOrDefault();

                if (meterBinding == null)
                {
                    meterBinding = new ORM_MRS_MPT_MeasuringPoint_MeterBinding()
                    {
                        Tenant_RefID = securityTicket.TenantID,
                        ActiveFrom   = DateTime.Now,
                        Meter_RefID  = meter.MRS_MPT_MeterID,
                        MRS_MPT_MeasuringPoint_MeterBindingID = Guid.NewGuid()
                    };
                    meterBinding.Save(Connection, Transaction);
                }

                var measurentPoint = ORM_MRS_MPT_MeasuringPoint.Query.Search(Connection, Transaction, new ORM_MRS_MPT_MeasuringPoint.Query()
                {
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted                = false,
                    MRS_MPT_MeasuringPointID = meterBinding.MeasuringPoint_RefID
                }).SingleOrDefault();

                if (measurentPoint == null)
                {
                    measurentPoint = new ORM_MRS_MPT_MeasuringPoint()
                    {
                        Tenant_RefID             = securityTicket.TenantID,
                        MRS_MPT_MeasuringPointID = Guid.NewGuid()
                    };

                    meterBinding.MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID;
                    meterBinding.Save(Connection, Transaction);

                    measurentPoint.Save(Connection, Transaction);
                }

                #endregion

                #region customer
                var customerOwnership = ORM_MRS_MPT_CustomerOwnership.Query.Search(Connection, Transaction, new ORM_MRS_MPT_CustomerOwnership.Query()
                {
                    Tenant_RefID   = securityTicket.TenantID,
                    IsDeleted      = false,
                    ContractNumber = row.ContractNumber
                }).SingleOrDefault();

                if (customerOwnership == null)
                {
                    var customerPersonInfo = new ORM_CMN_PER_PersonInfo()
                    {
                        Tenant_RefID         = securityTicket.TenantID,
                        FirstName            = row.ContractOwnerFirstName,
                        LastName             = row.ContractOwnerLastName,
                        CMN_PER_PersonInfoID = Guid.NewGuid()
                    };
                    customerPersonInfo.Save(Connection, Transaction);

                    var customerBP = new ORM_CMN_BPT_BusinessParticipant()
                    {
                        CMN_BPT_BusinessParticipantID = Guid.NewGuid(),
                        Tenant_RefID    = securityTicket.TenantID,
                        IsNaturalPerson = true,
                        IfNaturalPerson_CMN_PER_PersonInfo_RefID = customerPersonInfo.CMN_PER_PersonInfoID,
                    };
                    customerBP.Save(Connection, Transaction);

                    var customer = new ORM_CMN_BPT_CTM_Customer()
                    {
                        Tenant_RefID                  = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID        = Guid.NewGuid(),
                        Ext_BusinessParticipant_RefID = customerBP.CMN_BPT_BusinessParticipantID
                    };
                    customer.Save(Connection, Transaction);

                    customerOwnership = new ORM_MRS_MPT_CustomerOwnership()
                    {
                        Tenant_RefID = securityTicket.TenantID,
                        MRS_MPT_CustomerOwnershipID = Guid.NewGuid(),
                        ContractNumber       = row.ContractNumber,
                        ValidFrom            = DateTime.Now,
                        Customer_RefID       = customer.CMN_BPT_CTM_CustomerID,
                        MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID
                    };
                    customerOwnership.Save(Connection, Transaction);
                }
                else
                {
                    var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        Tenant_RefID           = securityTicket.TenantID,
                        IsDeleted              = false,
                        CMN_BPT_CTM_CustomerID = customerOwnership.Customer_RefID
                    }).Single();

                    var customerBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false,
                        CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID
                    }).Single();

                    var customerPI = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                    {
                        Tenant_RefID         = securityTicket.TenantID,
                        IsDeleted            = false,
                        CMN_PER_PersonInfoID = customerBP.IfNaturalPerson_CMN_PER_PersonInfo_RefID
                    }).Single();

                    customerPI.FirstName = row.ContractOwnerFirstName;
                    customerPI.LastName  = row.ContractOwnerLastName;
                    customerPI.Save(Connection, Transaction);
                }

                customerOwnership.MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID;
                customerOwnership.Save(Connection, Transaction);

                #region address
                var address = ORM_CMN_Address.Query.Search(Connection, Transaction, new ORM_CMN_Address.Query()
                {
                    Tenant_RefID    = securityTicket.TenantID,
                    IsDeleted       = false,
                    City_Name       = row.City,
                    Street_Name     = row.AddressName,
                    Street_Number   = row.AddressNumber,
                    City_PostalCode = row.ZipCode
                }).SingleOrDefault();

                if (address == null)
                {
                    address = new ORM_CMN_Address()
                    {
                        Tenant_RefID    = securityTicket.TenantID,
                        City_Name       = row.City,
                        Street_Name     = row.AddressName,
                        Street_Number   = row.AddressNumber,
                        City_PostalCode = row.ZipCode,
                        CMN_AddressID   = Guid.NewGuid()
                    };
                    address.Save(Connection, Transaction);
                }

                measurentPoint.CurrentAddress_RefID = address.CMN_AddressID;
                measurentPoint.Save(Connection, Transaction);

                #endregion

                #endregion

                #region route

                var route = ORM_MRS_RUT_Route.Query.Search(Connection, Transaction, new ORM_MRS_RUT_Route.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    DisplayName  = row.RouteName
                }).SingleOrDefault();

                if (route == null)
                {
                    route = new ORM_MRS_RUT_Route()
                    {
                        Tenant_RefID    = securityTicket.TenantID,
                        MRS_RUT_RouteID = Guid.NewGuid(),
                        DisplayName     = row.RouteName,
                        //Default_RouteReaderAccount_RefID = readerBP.CMN_BPT_BusinessParticipantID
                    };
                    route.Save(Connection, Transaction);
                }

                var routeMeasuringPoint = ORM_MRS_RUT_Route_MeasuringPoint.Query.Search(Connection, Transaction, new ORM_MRS_RUT_Route_MeasuringPoint.Query()
                {
                    Tenant_RefID         = securityTicket.TenantID,
                    IsDeleted            = false,
                    Route_RefID          = route.MRS_RUT_RouteID,
                    MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID
                }).SingleOrDefault();

                if (routeMeasuringPoint == null)
                {
                    routeMeasuringPoint = new ORM_MRS_RUT_Route_MeasuringPoint()
                    {
                        Tenant_RefID = securityTicket.TenantID,
                        MRS_RUT_Route_MeasuringPointID = Guid.NewGuid(),
                        Route_RefID          = route.MRS_RUT_RouteID,
                        MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID
                    };
                }

                routeMeasuringPoint.OrderSequence = row.SequenceInRoute;
                routeMeasuringPoint.Save(Connection, Transaction);


                #endregion

                #region measurement

                var measurement = new ORM_MRS_RUN_Measurement()
                {
                    Tenant_RefID          = securityTicket.TenantID,
                    MRS_RUN_MeasurementID = Guid.NewGuid(),
                    MeasurementRun_RefID  = run.MRS_RUN_MeasurementRunID,
                    MeasuringPoint_RefID  = routeMeasuringPoint.MRS_RUT_Route_MeasuringPointID
                };
                measurement.Save(Connection, Transaction);


                var run2route = ORM_MRS_RUN_MeasurementRun_Route.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_Route.Query()
                {
                    Tenant_RefID         = securityTicket.TenantID,
                    IsDeleted            = false,
                    Route_RefID          = route.MRS_RUT_RouteID,
                    MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID
                }).SingleOrDefault();

                if (run2route == null)
                {
                    run2route = new ORM_MRS_RUN_MeasurementRun_Route()
                    {
                        MRS_RUN_MeasurementRun_RouteID = Guid.NewGuid(),
                        Tenant_RefID         = securityTicket.TenantID,
                        Route_RefID          = route.MRS_RUT_RouteID,
                        MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID
                    }
                }
                ;

                run2route.BoundTo_Account_RefID = readerBP.CMN_BPT_BusinessParticipantID;
                run2route.Save(Connection, Transaction);


                #endregion
            }
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 15
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.º 16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SUS_1346 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var adress        = new ORM_CMN_Address();
            var person2Adress = new ORM_CMN_PER_PersonInfo_2_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = adress.Load(Connection, Transaction, Parameter.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);
                }
                person2Adress.CMN_Address_RefID = Parameter.CMN_AddressID;
            }

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

            if (Parameter.IsDeleted == true)
            {
                adress.IsDeleted        = true;
                person2Adress.IsDeleted = true;
                person2Adress.Save(Connection, Transaction);
                return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_AddressID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_AddressID == Guid.Empty)
            {
                person2Adress.CMN_Address_RefID = adress.CMN_AddressID;
                person2Adress.Tenant_RefID      = securityTicket.TenantID;
                adress.Tenant_RefID             = securityTicket.TenantID;
            }

            adress.Street_Name     = Parameter.Street_Name;
            adress.Street_Number   = Parameter.Street_Number;
            adress.City_Name       = Parameter.City_Name;
            adress.City_PostalCode = Parameter.City_PostalCode;
            adress.Country_Name    = Parameter.Country_Name;
            adress.Country_ISOCode = Parameter.Country_ISOCode;

            person2Adress.CMN_PER_PersonInfo_RefID = Parameter.CMN_PER_PersonInfo_RefID;
            person2Adress.IsAddress_Billing        = Parameter.IsAddress_Billing;
            person2Adress.IsAddress_Shipping       = Parameter.IsAddress_Shipping;
            person2Adress.AddressLabel             = Parameter.AddressName;
            person2Adress.IsPrimary = Parameter.IsPrimary;

            person2Adress.Save(Connection, Transaction);
            return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_AddressID));

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

            Guid PurchasingPowerAmount_Current;
            Guid PurchasingPowerAmount_Forecast;
            Guid ResidentialRent_MinPrice;
            Guid ResidentialRent_AveragePrice;
            Guid ResidentialRent_MaxPrice;
            Guid NonResidentialRent_MinPrice;
            Guid NonResidentialRent_AveragePrice;
            Guid NonResidentialRent_MaxPrice;

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.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_Region   = Parameter.City_Region;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            address.City_Name       = Parameter.City_Name;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            //for purchasingPowerAmountCurrent
            ORM_CMN_Price price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Current = price.CMN_PriceID;

            ORM_CMN_Price_Value.Query priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            List <ORM_CMN_Price_Value> prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            ORM_CMN_Price_Value priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Current_RefIDValue;
            priceValue.Save(Connection, Transaction);


            //for RegionInformation_PurchasingPowerAmount_Forecast_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Forecast = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for regionInfo and region
            ORM_CMN_LOC_Region region = new ORM_CMN_LOC_Region();
            if (Parameter.RegionID != Guid.Empty)
            {
                var result = region.Load(Connection, Transaction, Parameter.RegionID);
                if (result.Status != FR_Status.Success || region.CMN_LOC_RegionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            ORM_RES_LOC_RegionInformation.Query regionInfo = new ORM_RES_LOC_RegionInformation.Query();
            regionInfo.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
            regionInfo.Tenant_RefID         = securityTicket.TenantID;
            regionInfo.IsDeleted            = false;
            List <ORM_RES_LOC_RegionInformation> infos = ORM_RES_LOC_RegionInformation.Query.Search(Connection, Transaction, regionInfo);

            ORM_RES_LOC_RegionInformation info;
            if (infos.Count > 0)
            {
                info = infos[0];
                info.RegionInformation_RegionArea_in_sqkm            = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation               = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm           = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current    = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast   = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }
            else
            {
                info = new ORM_RES_LOC_RegionInformation();
                info.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
                info.RegionInformation_RegionArea_in_sqkm                    = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation                       = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm                   = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent         = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current            = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast           = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.RegionInformation_PurchasingPowerAmount_Current_RefID   = PurchasingPowerAmount_Current;
                info.RegionInformation_PurchasingPowerAmount_Forecast_RefID  = PurchasingPowerAmount_Forecast;
                info.RegionInformation_ResidentialRent_MinPrice_RefID        = ResidentialRent_MinPrice;
                info.RegionInformation_ResidentialRent_AveragePrice_RefID    = ResidentialRent_AveragePrice;
                info.RegionInformation_ResidentialRent_MaxPrice_RefID        = ResidentialRent_MaxPrice;
                info.RegionInformation_NonResidentialRent_MinPrice_RefID     = NonResidentialRent_MinPrice;
                info.RegionInformation_NonResidentialRent_AveragePrice_RefID = NonResidentialRent_AveragePrice;
                info.RegionInformation_NonResidentialRent_MaxPrice_RefID     = NonResidentialRent_MaxPrice;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }

            //save region
            region.Country_RefID = Parameter.Country_RefID;
            region.Tenant_RefID  = securityTicket.TenantID;
            region.Save(Connection, Transaction);

            //for location
            ORM_CMN_LOC_Location location = new ORM_CMN_LOC_Location();
            if (Parameter.CMN_LOC_LocationID != Guid.Empty)
            {
                var result = location.Load(Connection, Transaction, Parameter.CMN_LOC_LocationID);
                if (result.Status != FR_Status.Success || location.CMN_LOC_LocationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            location.Region_RefID  = region.CMN_LOC_RegionID;
            location.Address_RefID = address.CMN_AddressID;
            location.Tenant_RefID  = securityTicket.TenantID;
            location.Save(Connection, Transaction);

            //add location ref id in realesteProperty
            ORM_RES_RealestateProperty.Query realestatePropertyQuery = new ORM_RES_RealestateProperty.Query();
            realestatePropertyQuery.RES_RealestatePropertyID = Parameter.RealestatePropertyID;
            List <ORM_RES_RealestateProperty> realestates = ORM_RES_RealestateProperty.Query.Search(Connection, Transaction, realestatePropertyQuery);
            ORM_RES_RealestateProperty        realestate  = realestates[0];
            realestate.RealestateProperty_Location_RefID = location.CMN_LOC_LocationID;
            realestate.Save(Connection, Transaction);

            //for locationInformation
            ORM_RES_LOC_LocationInformation locationInformation = new ORM_RES_LOC_LocationInformation();
            if (Parameter.LocationInformationID != Guid.Empty)
            {
                var result = locationInformation.Load(Connection, Transaction, Parameter.LocationInformationID);
                if (result.Status != FR_Status.Success || locationInformation.RES_LOC_LocationInformationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            locationInformation.CMN_LOC_Location_RefID                   = location.CMN_LOC_LocationID;
            locationInformation.LocationInformation_MapImage_DocID       = Parameter.MapImage;
            locationInformation.LocationInformation_SatelliteImage_DocID = Parameter.SateliteImage;
            locationInformation.LocationInformation_AddressImage_DocID   = Parameter.AddressImage;
            locationInformation.Tenant_RefID = securityTicket.TenantID;
            locationInformation.Save(Connection, Transaction);

            //for meansOfTrasnportation, emmissions, infrastructures...
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation     transportation;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure infrastructure;
            ORM_RES_LOC_LocationInformation_2_Emmission           emmission;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality qualitie;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation           parkingSituation;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy         residentialVacancy;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy          commercialVacancy;

            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query transportationQuery = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query();
            transportationQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            transportationQuery.Tenant_RefID = securityTicket.TenantID;
            transportationQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query.SoftDelete(Connection, Transaction, transportationQuery);

            if (Parameter.RES_LOC_MeansOfTransportation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_MeansOfTransportation_RefID)
                {
                    transportation = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation();
                    transportation.RES_LOC_LocationInformation_RefID   = locationInformation.RES_LOC_LocationInformationID;
                    transportation.RES_LOC_MeansOfTransportation_RefID = guid;
                    transportation.Tenant_RefID = securityTicket.TenantID;
                    transportation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query infrastructureQuery = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query();
            infrastructureQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            infrastructureQuery.Tenant_RefID = securityTicket.TenantID;
            infrastructureQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query.SoftDelete(Connection, Transaction, infrastructureQuery);

            if (Parameter.RES_LOC_SurroundingInfrastructure_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_SurroundingInfrastructure_RefID)
                {
                    infrastructure = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure();
                    infrastructure.RES_LOC_LocationInformation_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    infrastructure.RES_LOC_SurroundingInfrastructure_RefID = guid;
                    infrastructure.Tenant_RefID = securityTicket.TenantID;
                    infrastructure.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_Emmission.Query emmissionQuery = new ORM_RES_LOC_LocationInformation_2_Emmission.Query();
            emmissionQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            emmissionQuery.Tenant_RefID = securityTicket.TenantID;
            emmissionQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_Emmission.Query.SoftDelete(Connection, Transaction, emmissionQuery);

            if (Parameter.RES_LOC_Emmission_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_Emmission_RefID)
                {
                    emmission = new ORM_RES_LOC_LocationInformation_2_Emmission();
                    emmission.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    emmission.RES_LOC_Emmission_RefID           = guid;
                    emmission.Tenant_RefID = securityTicket.TenantID;
                    emmission.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query neighborhoodQuery = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query();
            neighborhoodQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            neighborhoodQuery.Tenant_RefID = securityTicket.TenantID;
            neighborhoodQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query.SoftDelete(Connection, Transaction, neighborhoodQuery);

            if (Parameter.RES_LOC_NeighborhoodQuality_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_NeighborhoodQuality_RefID)
                {
                    qualitie = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality();
                    qualitie.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    qualitie.RES_LOC_NeighborhoodQuality_RefID = guid;
                    qualitie.Tenant_RefID = securityTicket.TenantID;
                    qualitie.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query parkingQuery = new ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query();
            parkingQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            parkingQuery.Tenant_RefID = securityTicket.TenantID;
            parkingQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query.SoftDelete(Connection, Transaction, parkingQuery);

            if (Parameter.RES_LOC_ParkingSituation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ParkingSituation_RefID)
                {
                    parkingSituation = new ORM_RES_LOC_LocationInfo_2_ParkingSituation();
                    parkingSituation.RES_LOC_LocationInfo_RefID     = locationInformation.RES_LOC_LocationInformationID;
                    parkingSituation.RES_LOC_ParkingSituation_RefID = guid;
                    parkingSituation.Tenant_RefID = securityTicket.TenantID;
                    parkingSituation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query residentalQuery = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query();
            residentalQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            residentalQuery.Tenant_RefID = securityTicket.TenantID;
            residentalQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query.SoftDelete(Connection, Transaction, residentalQuery);

            if (Parameter.RES_LOC_ResidentialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ResidentialVacancies_RefID)
                {
                    residentialVacancy = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy();
                    residentialVacancy.RES_LOC_LocationInfo_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    residentialVacancy.RES_LOC_ResidentialVacancy_RefID = guid;
                    residentialVacancy.Tenant_RefID = securityTicket.TenantID;
                    residentialVacancy.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query commercialQuery = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query();
            commercialQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            commercialQuery.Tenant_RefID = securityTicket.TenantID;
            commercialQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query.SoftDelete(Connection, Transaction, commercialQuery);

            if (Parameter.RES_LOC_CommercialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_CommercialVacancies_RefID)
                {
                    commercialVacancy = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy();
                    commercialVacancy.RES_LOC_LocationInfo_RefID      = locationInformation.RES_LOC_LocationInformationID;
                    commercialVacancy.RES_LOC_CommercialVacancy_RefID = guid;
                    commercialVacancy.Tenant_RefID = securityTicket.TenantID;
                    commercialVacancy.Save(Connection, Transaction);
                }
            }

            returnValue.Result = location.CMN_LOC_LocationID;

            return(returnValue);

            #endregion UserCode
        }