Esempio n. 1
0
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5BTS_EA_2008 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5BTS_EA_2008 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5BTS_EA_2008 functionReturn = new FR_L5BTS_EA_2008();

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

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

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

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

                throw new Exception("Exception occured in method cls_Edit_Appointment", ex);
            }
            return(functionReturn);
        }
Esempio n. 2
0
        protected static FR_L5BTS_EA_2008 Execute(DbConnection Connection, DbTransaction Transaction, P_L5BTS_EA_2008 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5BTS_EA_2008();
            returnValue.Result = new L5BTS_EA_2008();

            var appointment = cls_Get_AllAppointment_Task_for_AppointmentID.Invoke(Connection, Transaction, new P_L5A_GAATfAID_1530()
            {
                AppointmentID = Parameter.AppointmentID
            }, securityTicket).Result;

            var oldCombinationORM = ORM_PPS_TSK_BOK_AvailableResourceCombination.Query.Search(Connection, Transaction, new ORM_PPS_TSK_BOK_AvailableResourceCombination.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                PPS_TSK_BOK_AvailableResourceCombinationID = Parameter.OldCombinationID
            }).Single();
            oldCombinationORM.IsAvailable = true;
            oldCombinationORM.Save(Connection, Transaction);

            var newCombinationORM = ORM_PPS_TSK_BOK_AvailableResourceCombination.Query.Search(Connection, Transaction, new ORM_PPS_TSK_BOK_AvailableResourceCombination.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                PPS_TSK_BOK_AvailableResourceCombinationID = Parameter.NewCombinationID
            }).Single();

            var newSlot = ORM_PPS_TSK_BOK_BookableTimeSlot.Query.Search(Connection, Transaction, new ORM_PPS_TSK_BOK_BookableTimeSlot.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                PPS_TSK_BOK_BookableTimeSlotID = newCombinationORM.BookableTimeSlot_RefID
            }).Single();


            var allCombs = cls_Get_Slot_Combiantions_for_SlotID.Invoke(Connection, Transaction, new P_L5BTS_GSCfSID_1319()
            {
                SlotID = newSlot.PPS_TSK_BOK_BookableTimeSlotID
            }, securityTicket).Result;
            var selectedCombination = allCombs.Single(s => s.PPS_TSK_BOK_AvailableResourceCombinationID == Parameter.NewCombinationID);

            bool _isSameAppointmentType = newSlot.TaskTemplate_RefID == appointment.InstantiatedFrom_TaskTemplate_RefID;

            var paramDevice = new List <P_L5BTS_STI_1331_Device>();
            foreach (var instance in selectedCombination.Devices)
            {
                var _assignemtID = Guid.Empty;
                if (_isSameAppointmentType)
                {
                    var persistedInstance = appointment.Devices.SingleOrDefault(s => s.PPS_DEV_Device_Instance_RefID == instance.PPS_DEV_Device_Instance_RefID);
                    if (persistedInstance != null)
                    {
                        _assignemtID = persistedInstance.PPS_TSK_Task_DeviceBookingID;
                    }
                }
                paramDevice.Add(new P_L5BTS_STI_1331_Device()
                {
                    PPS_DEV_Device_Instance_RefID = instance.PPS_DEV_Device_Instance_RefID,
                    PPS_TSK_Task_DeviceBookingID  = _assignemtID
                });
            }

            var paramStaff = new List <P_L5BTS_STI_1331_Employee>();
            foreach (var staffCombo in selectedCombination.Staff)
            {
                var _assignemtID = Guid.Empty;
                if (_isSameAppointmentType)
                {
                    var persistedStaff = appointment.Staff.SingleOrDefault(s => s.CreatedFrom_TaskTemplate_RequiredStaff_RefID == staffCombo.CreatedFor_TaskTemplateRequiredStaff_RefID);
                    if (persistedStaff != null)
                    {
                        _assignemtID = persistedStaff.PPS_TSK_Task_StaffBookingsID;
                    }
                }

                paramStaff.Add(new P_L5BTS_STI_1331_Employee()
                {
                    CMN_BPT_EMP_Employee_RefID = staffCombo.CMN_BPT_EMP_Employee_RefID,
                    CreatedFrom_TaskTemplate_RequiredStaff_RefID = staffCombo.CreatedFor_TaskTemplateRequiredStaff_RefID,
                    PPS_TSK_Task_StaffBookingsID = _assignemtID
                });
            }

            P_L5BTS_STI_1331_Patient patientInfo = new P_L5BTS_STI_1331_Patient();
            patientInfo.Patient_RefID = Parameter.PatientID;
            P_L5BTS_STI_1331 param = new P_L5BTS_STI_1331()
            {
                Patient        = patientInfo,
                PPS_TSK_TaskID = Parameter.AppointmentID,
                Office         = new P_L5BTS_STI_1331_Office()
                {
                    CMN_STR_Office_RefID         = newSlot.Office_RefID,
                    PPS_TSK_Task_OfficeBookingID = appointment.Offices.PPS_TSK_Task_OfficeBookingID
                },
                PlannedStartDate       = newSlot.FreeInterval_Start,
                PlannedDuration_in_sec = (int)(newSlot.FreeInterval_End - newSlot.FreeInterval_Start).TotalSeconds,
                TaskTemplate_RefID     = newSlot.TaskTemplate_RefID,
                Devices  = paramDevice.ToArray(),
                Employee = paramStaff.ToArray()
            };

            var result = cls_Save_Task.Invoke(Connection, Transaction, param, securityTicket).Result;
            returnValue.Result.ID = result.ID;

            if (result.ReplacedPatient != null)
            {
                returnValue.Result.ReplacedPatient = new L5S_CAfSCID_1705_ReplacedPatient()
                {
                    ID = result.ReplacedPatient.ID
                }
            }
            ;

            newCombinationORM.IsAvailable = false;
            newCombinationORM.Save(Connection, Transaction);


            return(returnValue);

            #endregion UserCode
        }