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

            ORM_CMN_STR_Office whereInstance = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_STR_Office>();
            whereInstance.CMN_STR_OfficeID = Parameter.CMN_STR_OfficeID;
            int result = CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstance);

            ORM_CMN_CAL_CalendarInstance CalendarWhereInstance = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_CAL_CalendarInstance>();
            CalendarWhereInstance.CMN_CAL_CalendarInstanceID = Parameter.CMN_CAL_CalendarInstance_RefID;
            CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, CalendarWhereInstance);

            return(returnValue);

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

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

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



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

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



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

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

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

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

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

            #endregion UserCode
        }
Пример #4
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5WS_CSCfP_1431 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            var item        = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart();
            item.ORD_PRC_ShoppingCartID = Guid.NewGuid();

            // Get status
            var statusActive = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query.Search(Connection, Transaction,
                                                                                        new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query()
            {
                GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription
                                               (DLCore_DBCommons.APODemand.EShoppingCartStatus.Active),
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).Single();

            ORM_CMN_STR_Office office;
            var offices = ORM_CMN_STR_Office.Query.Search(Connection, Transaction,
                                                          new ORM_CMN_STR_Office.Query()
            {
                Office_InternalName = Parameter.PracticeBPID,
                Tenant_RefID        = securityTicket.TenantID,
                IsDeleted           = false
            }).ToArray();
            if (offices.Count() == 0)
            {
                office = new ORM_CMN_STR_Office();
                office.CMN_STR_OfficeID    = Guid.NewGuid();
                office.Tenant_RefID        = securityTicket.TenantID;
                office.Office_InternalName = Parameter.PracticeBPID;
                office.Save(Connection, Transaction);
            }
            else
            {
                office = offices[0];
            }



            double internalIdentifier = 0;

            var lastShoppingCartOfficeAssignment = CL1_ORD_PRC.ORM_ORD_PRC_Office_ShoppingCart.Query.Search(Connection, Transaction,
                                                                                                            new CL1_ORD_PRC.ORM_ORD_PRC_Office_ShoppingCart.Query {
                Tenant_RefID = securityTicket.TenantID, CMN_STR_Office_RefID = office.CMN_STR_OfficeID
            }
                                                                                                            ).OrderByDescending(x => x.Creation_Timestamp).FirstOrDefault();
            if (lastShoppingCartOfficeAssignment != null)
            {
                var lastShoppingCart = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart.Query.Search(Connection, Transaction,
                                                                                         new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart.Query {
                    Tenant_RefID = securityTicket.TenantID, ORD_PRC_ShoppingCartID = lastShoppingCartOfficeAssignment.ORD_PRC_ShoppingCart_RefID
                }
                                                                                         ).FirstOrDefault();
                double.TryParse(lastShoppingCart.InternalIdentifier, out internalIdentifier);
            }

            var shoppingCartOffice = new CL1_ORD_PRC.ORM_ORD_PRC_Office_ShoppingCart();
            shoppingCartOffice.ORD_PRC_ShoppingCart_RefID = item.ORD_PRC_ShoppingCartID;
            shoppingCartOffice.CMN_STR_Office_RefID       = office.CMN_STR_OfficeID;
            shoppingCartOffice.Tenant_RefID = securityTicket.TenantID;
            shoppingCartOffice.Save(Connection, Transaction);

            // Create shoppping cart
            item.ShoppingCart_CurrentStatus_RefID = statusActive.ORD_PRC_ShoppingCart_StatusID;
            item.InternalIdentifier        = (++internalIdentifier).ToString();
            item.Tenant_RefID              = securityTicket.TenantID;
            item.CreatedBy_Account_RefID   = securityTicket.AccountID;
            item.IsProcurementOrderCreated = false;

            // Create and save new shopping cart history
            var shoppingHistory = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCartStatus_History();
            shoppingHistory.ORD_PRC_ShoppingCart_RefID        = item.ORD_PRC_ShoppingCartID;
            shoppingHistory.ORD_PRC_ShoppingCart_Status_RefID = statusActive.ORD_PRC_ShoppingCart_StatusID;
            shoppingHistory.PerformedBy_Account_RefID         = securityTicket.AccountID;
            shoppingHistory.Tenant_RefID = securityTicket.TenantID;
            shoppingHistory.Save(Connection, Transaction);

            return(new FR_Guid(item.Save(Connection, Transaction), item.ORD_PRC_ShoppingCartID));

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

            returnValue.Result = new L5OU_SOUT_0934();

            Guid orgUnitTypeId = Guid.Empty;
            if (!Parameter.BaseData.IsDeleted)
            {
                orgUnitTypeId = cls_Save_MedicalPracticeType.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
            }
            else
            {
                List <ORM_HEC_MedicalPractice_2_PracticeType> existingOffice = ORM_HEC_MedicalPractice_2_PracticeType.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_PracticeType.Query
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    HEC_MedicalPractice_Type_RefID = Parameter.BaseData.HEC_MedicalPractice_TypeID
                }).ToList();

                if (existingOffice.Count > 0) //cannot delete
                {
                    List <ORM_HEC_MedicalPractis> medicalPracticesList = new List <ORM_HEC_MedicalPractis>();
                    foreach (var item in existingOffice)
                    {
                        ORM_HEC_MedicalPractis medPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractis.Query
                        {
                            IsDeleted             = false,
                            Tenant_RefID          = securityTicket.TenantID,
                            HEC_MedicalPractiseID = item.HEC_MedicalPractice_RefID
                        }).Single();

                        medicalPracticesList.Add(new ORM_HEC_MedicalPractis {
                            HEC_MedicalPractiseID = item.HEC_MedicalPractice_RefID
                        });
                    }
                    ;

                    if (medicalPracticesList.Count > 0) //cannot delete
                    {
                        List <L5OU_SOUT_0934_UsedInOrgUnit> usedOrgUnitList = new List <L5OU_SOUT_0934_UsedInOrgUnit>();

                        foreach (var item in medicalPracticesList)
                        {
                            ORM_CMN_STR_Office officeName = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office.Query
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                IfMedicalPractise_HEC_MedicalPractice_RefID = item.HEC_MedicalPractiseID
                            }).Single();

                            usedOrgUnitList.Add(new L5OU_SOUT_0934_UsedInOrgUnit {
                                OrgUnitName = officeName.Office_Name
                            });
                        }
                        returnValue.Result.UsedInOrgUnit = usedOrgUnitList.ToArray();
                    }
                }
                if (existingOffice.Count == 0)
                {
                    orgUnitTypeId = cls_Save_MedicalPracticeType.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
                }
            }
            returnValue.Result.ID = orgUnitTypeId;

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

            //Put your code here
            List <L5PP_GSHwDOfPfT_1013> retVal = new List <L5PP_GSHwDOfPfT_1013>();
            returnValue.Result = retVal.ToArray();

            #region Retrieve Headers

            // get all headers
            P_L2SH_GSHfT_1527 shipmentHeadersParam = new P_L2SH_GSHfT_1527();
            shipmentHeadersParam.IsShipped                = false;
            shipmentHeadersParam.ShipmentNumber           = Parameter.ShipmentNumber;
            shipmentHeadersParam.ShipmentCreationDateFrom = Parameter.ShipmentCreationDateFrom;
            shipmentHeadersParam.ShipmentCreationDateTo   = Parameter.ShipmentCreationDateTo;
            var headersResult = cls_Get_ShippmentHeaders_for_TenantID.Invoke(Connection, Transaction, shipmentHeadersParam, securityTicket).Result;

            if (headersResult == null)
            {
                return(returnValue);
            }

            // filter headers
            List <L2SH_GSHfT_1527> headers     = new List <L2SH_GSHfT_1527>();
            List <L2SH_GSHfT_1527> tempHeaders = new List <L2SH_GSHfT_1527>();
            if (Parameter.HasPositionsPartiallyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsReadyForPicking)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.IsInPickingProcess)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i => i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            if (Parameter.NoPositionsFullyToPick)
            {
                // filtered by passed parameter option
                tempHeaders = headersResult.Where(i =>
                                                  !(i.IsPartiallyReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.IsReadyForPicking && !i.IsManuallyCleared_ForPicking) &&
                                                  !(i.HasPickingStarted || i.HasPickingFinished || i.IsManuallyCleared_ForPicking)
                                                  ).ToList();
                // add not inserted shipment headers
                headers.AddRange(tempHeaders.Where(i => !headers.Any(j => j.LOG_SHP_Shipment_HeaderID == i.LOG_SHP_Shipment_HeaderID)).ToList());
            }

            #endregion

            L5PP_GSHwDOfPfT_1013 retValItem;
            foreach (var header in headers)
            {
                #region Getting data

                #region Shipment positions
                // get one shipment position for shipment header
                ORM_LOG_SHP_Shipment_Position.Query shipmentPositionsQuery = new ORM_LOG_SHP_Shipment_Position.Query();
                shipmentPositionsQuery.LOG_SHP_Shipment_Header_RefID = header.LOG_SHP_Shipment_HeaderID;
                shipmentPositionsQuery.Tenant_RefID = securityTicket.TenantID;
                shipmentPositionsQuery.IsDeleted    = false;
                List <ORM_LOG_SHP_Shipment_Position> shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, shipmentPositionsQuery);

                if (shipmentPositions == null || shipmentPositions.Count == 0)
                {
                    continue;
                }
                #endregion

                #region Distribution order position for shipment position
                // get one distribution order position for shipment position
                ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition distributionOrder2ShipmentPosition = null;
                foreach (var shipmentPosition in shipmentPositions)
                {
                    ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query distributionOrder2ShipmentPositionQuery = new ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query();
                    distributionOrder2ShipmentPositionQuery.LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID;
                    distributionOrder2ShipmentPositionQuery.Tenant_RefID = securityTicket.TenantID;
                    distributionOrder2ShipmentPositionQuery.IsDeleted    = false;
                    distributionOrder2ShipmentPosition =
                        ORM_ORD_DIS_DistributionOrderPosition_2_ShipmentOrderPosition.Query
                        .Search(Connection, Transaction, distributionOrder2ShipmentPositionQuery).FirstOrDefault();

                    if (distributionOrder2ShipmentPosition != null)
                    {
                        break;
                    }
                }

                if (distributionOrder2ShipmentPosition == null)
                {
                    continue;
                }
                #endregion

                #region Disrtibution order position
                ORM_ORD_DIS_DistributionOrder_Position orm_DistributionOrderPosition = new ORM_ORD_DIS_DistributionOrder_Position();
                var distributionOrderPosition = orm_DistributionOrderPosition.Load(Connection, Transaction, distributionOrder2ShipmentPosition.ORD_DIS_DistributionOrder_Position_RefID);
                if (distributionOrderPosition.Status != FR_Status.Success || orm_DistributionOrderPosition.ORD_DIS_DistributionOrder_PositionID == Guid.Empty)
                {
                    continue;
                }
                #endregion

                #region Distribution order header
                // get sitribution order header for distribution order position
                ORM_ORD_DIS_DistributionOrder_Header.Query distributionOrderHeaderQuery = new ORM_ORD_DIS_DistributionOrder_Header.Query();
                distributionOrderHeaderQuery.ORD_DIS_DistributionOrder_HeaderID = orm_DistributionOrderPosition.DistributionOrder_Header_RefID;
                distributionOrderHeaderQuery.Tenant_RefID = securityTicket.TenantID;
                distributionOrderHeaderQuery.IsDeleted    = false;

                ORM_ORD_DIS_DistributionOrder_Header distributionOrderHeader = ORM_ORD_DIS_DistributionOrder_Header.Query.Search(Connection, Transaction, distributionOrderHeaderQuery).FirstOrDefault();
                if (distributionOrderHeader == null)
                {
                    continue;
                }

                // apply filter for distribution order header
                if (Parameter.OrderDateFrom != null)
                {
                    if (distributionOrderHeader.DistributionOrderDate < Parameter.OrderDateFrom)
                    {
                        continue;
                    }
                }

                if (Parameter.OrderDateTo != null)
                {
                    if (distributionOrderHeader.DistributionOrderDate > Parameter.OrderDateTo)
                    {
                        continue;
                    }
                }

                if (!String.IsNullOrEmpty(Parameter.DistributionOrderNumber))
                {
                    if (!distributionOrderHeader.DistributionOrderNumber.ToUpper().Contains(Parameter.DistributionOrderNumber.ToUpper()))
                    {
                        continue;
                    }
                }
                #endregion

                #region CostCenter
                // get cost center for distribution order header
                ORM_CMN_STR_CostCenter orm_CostCenter = new ORM_CMN_STR_CostCenter();
                var costCenter = orm_CostCenter.Load(Connection, Transaction, distributionOrderHeader.Charged_CostCenter_RefID);
                if (costCenter.Status != FR_Status.Success || orm_CostCenter.CMN_STR_CostCenterID == Guid.Empty)
                {
                    continue;
                }

                if (!String.IsNullOrEmpty(Parameter.CostCenter))
                {
                    // apply filter for cost center
                    if (!orm_CostCenter.Name.Contents.Any(i => i.Content.ToLower().Contains(Parameter.CostCenter)))
                    {
                        continue;
                    }
                }
                #endregion

                #region Office
                // get office for cost center
                ORM_CMN_STR_Office_2_CostCenter.Query office2CostCenterQuery = new ORM_CMN_STR_Office_2_CostCenter.Query();
                office2CostCenterQuery.CostCenter_RefID = orm_CostCenter.CMN_STR_CostCenterID;
                office2CostCenterQuery.Tenant_RefID     = securityTicket.TenantID;
                office2CostCenterQuery.IsDefault        = false;
                ORM_CMN_STR_Office_2_CostCenter office2CostCenter = ORM_CMN_STR_Office_2_CostCenter.Query.Search(Connection, Transaction, office2CostCenterQuery).FirstOrDefault();

                ORM_CMN_STR_Office orm_Office = null;
                if (office2CostCenter != null)
                {
                    orm_Office = new ORM_CMN_STR_Office();
                    var office = orm_Office.Load(Connection, Transaction, office2CostCenter.Office_RefID);
                    if (office.Status != FR_Status.Success || orm_Office.CMN_STR_OfficeID == Guid.Empty)
                    {
                        // there is no office with such ID
                        orm_Office = null;
                    }
                    else
                    {
                        // office loaded, apply filter
                        if (!String.IsNullOrEmpty(Parameter.OrganizationalUnit))
                        {
                            if (!(orm_Office.Office_InternalName.ToLower().Contains(Parameter.OrganizationalUnit) ||
                                  orm_Office.Office_Name.Contents.Any(i => i.Content.ToLower().Contains(Parameter.OrganizationalUnit))))
                            {
                                continue;
                            }
                        }
                    }
                }
                #endregion

                #endregion

                retValItem = new L5PP_GSHwDOfPfT_1013();
                retValItem.LOG_SHP_Shipment_HeaderID = header.LOG_SHP_Shipment_HeaderID;
                retValItem.ShipmentHeader_Number     = header.ShipmentHeader_Number;
                retValItem.IsShipped                    = header.IsShipped;
                retValItem.IsBilled                     = header.IsBilled;
                retValItem.IsReadyForPicking            = header.IsReadyForPicking;
                retValItem.IsPartiallyReadyForPicking   = header.IsPartiallyReadyForPicking;
                retValItem.HasPickingStarted            = header.HasPickingStarted;
                retValItem.HasPickingFinished           = header.HasPickingFinished;
                retValItem.IsManuallyCleared_ForPicking = header.IsManuallyCleared_ForPicking;
                retValItem.ShipmentCreationDate         = header.Creation_Timestamp;

                retValItem.ORD_DIS_DistributionOrder_HeaderID = distributionOrderHeader.ORD_DIS_DistributionOrder_HeaderID;
                retValItem.DistributionOrderNumber            = distributionOrderHeader.DistributionOrderNumber;
                retValItem.DistributionOrderDate = distributionOrderHeader.DistributionOrderDate;

                retValItem.CMN_STR_CostCenterID = orm_CostCenter.CMN_STR_CostCenterID;
                retValItem.CostCenterName       = orm_CostCenter.Name;

                retValItem.CMN_STR_OfficeID   = orm_Office != null ? orm_Office.CMN_STR_OfficeID : Guid.Empty;
                retValItem.OfficeInternalName = orm_Office != null ? orm_Office.Office_InternalName : String.Empty;

                retVal.Add(retValItem);
            }

            retVal = retVal.Skip(Parameter.From).Take(Parameter.Size).ToList();

            returnValue.Result = retVal.ToArray();

            return(returnValue);

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

            returnValue.Result = new L6TA_STTwDC_1146();

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

                if (Parameter.UpdateSlots)
                {
                    cls_Update_Slots_for_AppointmentTypeChange.Invoke(Connection, Transaction, new P_L5S_CSfATC_1242()
                    {
                        AppointmentTypeID = AppointmentTypeId
                    }, securityTicket);
                }
            }
            else
            {
                List <ORM_PPS_TSK_Task> existingAppointment = ORM_PPS_TSK_Task.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task.Query
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    InstantiatedFrom_TaskTemplate_RefID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                }).ToList();

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

                    foreach (var appointment in existingAppointment)
                    {
                        usedAppointmentList.Add(new L6TA_STTwDC_1146_UsedInAppointment {
                            AppointmentName = appointment.DisplayName
                        });
                    }
                    returnValue.Result.UsedInAppointment = usedAppointmentList.ToArray();
                }

                List <ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability> existingOrgUnit = ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    PPS_TSK_Task_Template_RefID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                }).ToList();

                if (existingOrgUnit.Count > 0) //cannot delete
                {
                    List <L6TA_STTwDC_1146_UsedInOrgUnit> usedOrgUnitList = new List <L6TA_STTwDC_1146_UsedInOrgUnit>();

                    foreach (var orgUnit in existingOrgUnit)
                    {
                        ORM_CMN_STR_Office officeName = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office.Query
                        {
                            IsDeleted        = false,
                            Tenant_RefID     = securityTicket.TenantID,
                            CMN_STR_OfficeID = orgUnit.CMN_STR_Office_RefID
                        }).Single();

                        usedOrgUnitList.Add(new L6TA_STTwDC_1146_UsedInOrgUnit {
                            OrgUnitName = officeName.Office_Name
                        });
                    }

                    returnValue.Result.UsedInOrgUnit = usedOrgUnitList.ToArray();
                }

                if (existingAppointment.Count == 0 && existingOrgUnit.Count == 0)
                {
                    AppointmentTypeId = cls_Save_TaskTemplate.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
                    if (Parameter.UpdateSlots)
                    {
                        cls_Delete_Slots_for_AppointmentTypeID.Invoke(Connection, Transaction, new P_L5BTS_DSfATID_1111()
                        {
                            AppointmentTypeID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                        }, securityTicket);
                    }
                }
            }
            returnValue.Result.ID = AppointmentTypeId;

            return(returnValue);

            #endregion UserCode
        }