Exemplo n.º 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CU_SCgaA_1535 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_BPT_BusinessParticipant_Group group = null;
            if (Parameter.GroupID != Guid.Empty)
            {
                group = ORM_CMN_BPT_BusinessParticipant_Group.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_Group.Query
                {
                    CMN_BPT_BusinessParticipant_GroupID = Parameter.GroupID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();
            }

            if (group == null && !Parameter.DeleteGroup)
            {
                group = new ORM_CMN_BPT_BusinessParticipant_Group {
                    CMN_BPT_BusinessParticipant_GroupID  = Guid.NewGuid(),
                    BusinessParticipantGroup_Name        = Parameter.BusinessParticipantGroup_Name,
                    BusinessParticipantGroup_Description = Parameter.BusinessParticipantGroup_Description,
                    Tenant_RefID = securityTicket.TenantID
                };
            }
            else if (group != null && !Parameter.DeleteGroup)
            {
                if (Parameter.BusinessParticipantGroup_Name != null)
                {
                    group.BusinessParticipantGroup_Name = Parameter.BusinessParticipantGroup_Name;
                }
                if (Parameter.BusinessParticipantGroup_Description != null)
                {
                    group.BusinessParticipantGroup_Description = Parameter.BusinessParticipantGroup_Description;
                }
            }
            ;

            if (!Parameter.DeleteGroup)
            {
                group.Save(Connection, Transaction);
            }
            else
            {
                group.Remove(Connection, Transaction);
            }

            var Assignments = ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query
            {
                CMN_BPT_BusinessParticipant_Group_RefID = Parameter.GroupID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            });


            if (Parameter.DeleteGroup)
            {
                foreach (var item in Assignments)
                {
                    item.Remove(Connection, Transaction);
                }
            }
            else
            {
                foreach (var BPID in Parameter.BusinessParticipantID)
                {
                    if (BPID != Guid.Empty)
                    {
                        if (!Assignments.Select(x => x.CMN_BPT_BusinessParticipant_RefID).Contains(BPID))
                        {
                            var assignment = new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup();
                            assignment.AssignmentID = Guid.NewGuid();
                            assignment.CMN_BPT_BusinessParticipant_Group_RefID = group.CMN_BPT_BusinessParticipant_GroupID;
                            assignment.CMN_BPT_BusinessParticipant_RefID       = BPID;
                            assignment.Tenant_RefID = securityTicket.TenantID;
                            assignment.Save(Connection, Transaction);
                        }
                    }
                }


                var assignmentsForDelete = Assignments.Where(a => !Parameter.BusinessParticipantID.Any(b => b == a.CMN_BPT_BusinessParticipant_RefID));


                foreach (var forDelete in assignmentsForDelete)
                {
                    forDelete.Remove(Connection, Transaction);
                }
            }


            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_PH_SP_1124 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
            #region Pharmacy
            var pharmacy = ORM_HEC_Pharmacy.Query.Search(Connection, Transaction, new ORM_HEC_Pharmacy.Query
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                HEC_PharmacyID = Parameter.Pharmacy.PharmacyID
            }).SingleOrDefault();

            if (pharmacy == null)
            {
                pharmacy = new ORM_HEC_Pharmacy();
                pharmacy.Tenant_RefID = securityTicket.TenantID;
            }
            #endregion

            #region CompanyInfo

            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query
            {
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false,
                CMN_COM_CompanyInfoID = pharmacy.Ext_CompanyInfo_RefID
            }).SingleOrDefault();
            if (companyInfo == null)
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Tenant_RefID = securityTicket.TenantID;


                pharmacy.Ext_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            }

            var contractUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID
            }).SingleOrDefault();
            if (contractUCD == null)
            {
                contractUCD = new ORM_CMN_UniversalContactDetail();
                contractUCD.Tenant_RefID = securityTicket.TenantID;
                contractUCD.IsCompany    = true;
            }
            contractUCD.CompanyName_Line1 = Parameter.Pharmacy.PharmacyName;
            contractUCD.First_Name        = Parameter.Pharmacy.PharmacyName;
            contractUCD.Contact_Email     = Parameter.Pharmacy.Email;
            contractUCD.Contact_Telephone = Parameter.Pharmacy.PhoneNumber;
            contractUCD.Contact_Fax       = Parameter.Pharmacy.Fax;
            contractUCD.Street_Name       = Parameter.Pharmacy.Street;
            contractUCD.Street_Number     = Parameter.Pharmacy.StreetNumber;
            contractUCD.ZIP  = Parameter.Pharmacy.ZipCode;
            contractUCD.Town = Parameter.Pharmacy.Town;
            contractUCD.Save(Connection, Transaction);

            companyInfo.Contact_UCD_RefID = contractUCD.CMN_UniversalContactDetailID;
            companyInfo.Save(Connection, Transaction);

            var ciBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID
            }).SingleOrDefault();
            if (ciBusinessParticipant == null)
            {
                ciBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                ciBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                ciBusinessParticipant.IsCompany    = true;
                ciBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            }

            ciBusinessParticipant.Save(Connection, Transaction);

            var pharmacyType = EPharmacyType.Internal.Value();
            if (Parameter.Pharmacy.IsExternalPharmacy)
            {
                pharmacyType = EPharmacyType.External.Value();
            }

            var businessParticipantGroup = ORM_CMN_BPT_BusinessParticipant_Group.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_Group.Query
            {
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted                = false,
                GlobalPropertyMatchingID = pharmacyType
            }).SingleOrDefault();
            if (businessParticipantGroup == null)
            {
                businessParticipantGroup = new ORM_CMN_BPT_BusinessParticipant_Group();
                businessParticipantGroup.Tenant_RefID             = securityTicket.TenantID;
                businessParticipantGroup.GlobalPropertyMatchingID = pharmacyType;
                businessParticipantGroup.Save(Connection, Transaction);
            }

            var bpToBpGroup = ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_BPT_BusinessParticipant_RefID       = ciBusinessParticipant.CMN_BPT_BusinessParticipantID,
                CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID
            }).SingleOrDefault();
            if (bpToBpGroup == null)
            {
                bpToBpGroup = new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup();
                bpToBpGroup.Tenant_RefID = securityTicket.TenantID;
                bpToBpGroup.CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID;
                bpToBpGroup.CMN_BPT_BusinessParticipant_RefID       = ciBusinessParticipant.CMN_BPT_BusinessParticipantID;
                bpToBpGroup.Save(Connection, Transaction);
            }
            #endregion

            #region ContactPersonInfo
            var contactInfo = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_BPT_BusinessParticipantID = pharmacy.ContactPerson_BusinessParticipant_RefID
            }).SingleOrDefault();
            if (contactInfo == null)
            {
                contactInfo = new ORM_CMN_BPT_BusinessParticipant();
                contactInfo.Tenant_RefID    = securityTicket.TenantID;
                contactInfo.IsNaturalPerson = true;
            }

            var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDead               = false,
                CMN_PER_PersonInfoID = contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID
            }).SingleOrDefault();
            if (personInfo == null)
            {
                personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Tenant_RefID = securityTicket.TenantID;
            }
            var splitedName = Parameter.Pharmacy.ContactPersonName.Split(' ');
            var firstName   = splitedName.Length > 1 ? string.Join(" ", splitedName.Take(splitedName.Length - 1)) : splitedName[0];
            var lastName    = splitedName.Length > 1 ? splitedName.Last() : "";

            personInfo.FirstName = firstName;
            personInfo.LastName  = lastName;
            personInfo.Save(Connection, Transaction);

            contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
            contactInfo.Save(Connection, Transaction);

            pharmacy.ContactPerson_BusinessParticipant_RefID = contactInfo.CMN_BPT_BusinessParticipantID;

            #endregion

            pharmacy.Save(Connection, Transaction);

            returnValue.Result = pharmacy.HEC_PharmacyID;
            return(returnValue);

            #endregion UserCode
        }