예제 #1
0
        public DataEntityCollectionDTO RetrieveEntityById(string entityName, Guid entityId, SecurityToken sessionToken)
        {
            SecuritySummary securitySummary = new SecuritySummary();
            CallStatus callStatus = new CallStatus();

            using (ChannelFactory<IDataEntityIO> factory = GetApplicationServerChannelFactory(_applicationServerAddress))
            {
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);

                List<string> fieldNames = GetFields(entityName);

                DataEntityCollectionDTO entities = secureConnection.ReadEntity(
                   entityId,
                   entityName,
                   fieldNames, ref securitySummary, ref callStatus);

                if (callStatus.Result == CallStatusenumCallResult.Success) return entities;

                StringBuilder sb = new StringBuilder();
                foreach (ValidationError error in callStatus.Messages)
                {
                    sb.AppendLine(error.Message);
                }
                throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
            }
        }
예제 #2
0
        public DataEntityCollectionDTO RetrieveEntityByNameQuery(string queryName, Dictionary <string, object> parameters,
                                                                 SecurityToken sessionToken)
        {
            SecuritySummary securitySummary = new SecuritySummary();
            CallStatus      callStatus      = new CallStatus();

            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory(_applicationServerAddress)
                   )
            {
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);

                DataEntityCollectionDTO entities = secureConnection.RunNamedQuery(queryName, parameters,
                                                                                  ref securitySummary, ref callStatus);

                if (callStatus.Result == CallStatusenumCallResult.Success)
                {
                    return(entities);
                }

                StringBuilder sb = new StringBuilder();
                foreach (ValidationError error in callStatus.Messages)
                {
                    sb.AppendLine(error.Message);
                }
                throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
            }

            //TODO: CONTINUE WITH THIS METHOD SIMILAR TO StaffQuery
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Display the data in the passed DataEntityCollectionDTO in the console window. This gives an example of how the content
        /// of a loosly typed entity property bag works.
        /// </summary>
        /// <param name="entities"></param>
        internal void DisplayDataInConsoleWindow(DataEntityCollectionDTO entities)
        {
            // The data structure returned may have many entities, (in our case a mixture of Address, LearnerAddress and Learner). The TopLevelDtoIDs collection
            // gives the list of unique IDs that represent the Learner entitities we requested.
            foreach (int referenceId in entities.TopLevelDtoIDs)
            {
                // In our case there is only one expected TopLevel entity - the Learner 8BCF76BF-C067-98AB-5DFC-88D62DE77450
                DataEntityDTO entity = entities.DataEntityDtos[referenceId];
                Console.WriteLine("Entity " + entity.EntityName + " " + entity.ID.ToString());

                // Extract the fields from the DataEntityDTO.Values dictionary
                // Dangerous assumption that these Values can be cast to a String - if they are Null they will be of type SimplePropertyDTONull, not SimplePropertyDTOString
                // programmers should construct a conversion function to prevent having to check this every time, returning a Nullable<Type> when passed an instance of a
                // SimplePropertyDTO
                Console.WriteLine("      Surname " + ((DataEntityDTO.SimplePropertyDTOString)entity.Values["LegalSurname"]).Value);
                Console.WriteLine("     Forename " + ((DataEntityDTO.SimplePropertyDTOString)entity.Values["LegalForename"]).Value);
                Console.WriteLine("     PreferredForename " + ((DataEntityDTO.SimplePropertyDTOString)entity.Values["PreferredForename"]).Value);
                // In theory any value might be returned as Null rather than the expected Type. Third party developers should assume that, due to security redaction or
                // naturally occuring blanks in the data, that any Value property of an DataEntityDTO could be of Type SimplePropertyDTONull.
                if (entity.Values.ContainsKey("UPN"))
                {
                    if (entity.Values["UPN"] is DataEntityDTO.SimplePropertyDTONull)
                    {
                        Console.WriteLine("          UPN NULL");
                    }
                    else
                    {
                        Console.WriteLine("          UPN " + ((DataEntityDTO.SimplePropertyDTOString)entity.Values["UPN"]).Value);
                    }
                }

                if (entity.Values.ContainsKey("LearnerAddresses"))
                {
                    // Spin round each of the possible addresses attached to this learner.
                    foreach (DataEntityDTO.ReferencePropertyDTO learerReference in ((DataEntityDTO.ReferencePropertyDTOArray)entity.Values["LearnerAddresses"]).ReferenceProperties)
                    {
                        if (learerReference.InternalReferenceID.HasValue)
                        {
                            // Get the learnerAddress entity
                            DataEntityDTO learnerAddressEntity = entities.DataEntityDtos[learerReference.InternalReferenceID.Value];
                            Date          dateValue            = ((DataEntityDTO.SimplePropertyDTODate)learnerAddressEntity.Values["StartDate"]).Value;
                            Console.WriteLine("      Address Start Date " + dateValue.internalDateTime.Date);

                            // Get the address unique ID
                            DataEntityDTO.ReferencePropertyDTO addressReference = ((DataEntityDTO.ReferencePropertyDTO)learnerAddressEntity.Values["Address"]);
                            // Get the address entity.
                            // ReSharper disable once AssignNullToNotNullAttribute
                            // ReSharper disable once PossibleInvalidOperationException
                            DataEntityDTO addressEntity = entities.DataEntityDtos[addressReference.InternalReferenceID.Value];
                            Console.WriteLine("      Address PostCode    " + ((DataEntityDTO.SimplePropertyDTOString)addressEntity.Values["PostCode"]).Value);
                        }
                    }
                }
            }
        }
예제 #4
0
        public DataEntityCollectionDTO UpdateEntity(DataEntityCollectionDTO entitys, string fieldName, string referencevalue)
        {
            foreach (int referenceId in entitys.TopLevelDtoIDs)
            {
                DataEntityDTO entity = entitys.DataEntityDtos[referenceId];
                ((DataEntityDTO.SimplePropertyDTOString)entity.Values[fieldName]).Value = referencevalue;
                _changedFields.Add(fieldName);
            }

            return(entitys);
        }
예제 #5
0
        public void Save(DataEntityCollectionDTO entitys, SecurityToken sessionToken, string applicationServerURL, List <string> saveScope)
        {
            CallStatus callStatus = new CallStatus();

            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory(applicationServerURL))
            {
                DataEntityDTOChangeBatchCollection changes = new DataEntityDTOChangeBatchCollection
                {
                    Batches = new List <DataEntityDTOChangeBatch>()
                };
                DataEntityDTO.DataModelTypeDTO dataModelType = new DataEntityDTO.DataModelTypeDTO {
                    SchemaName = "dbo", DataModelPurpose = "BusinessDataModel"
                };
                changes.DataModelType = dataModelType;
                DataEntityDTOChangeBatch batch = new DataEntityDTOChangeBatch {
                    EntitiesToSave = entitys
                };
                DataEntitySaveContext batchSaveContext = new DataEntitySaveContext();
                List <string>         alternateKeys    = new List <string>();
                List <string>         batchSaveScope   = new List <string>();
                if (_changedFields.Any())
                {
                    batchSaveScope = _changedFields;
                }
                else if (saveScope.Any())
                {
                    batchSaveScope = saveScope;
                }
                batchSaveContext.SaveScope             = batchSaveScope;
                batchSaveContext.AlternateKeyFields    = alternateKeys;
                batchSaveContext.CustomWorkflows       = new List <WorkflowPackage>();
                batchSaveContext.CustomDeleteWorkflows = new List <WorkflowPackage>();
                batch.SaveContext = batchSaveContext;
                changes.Batches.Add(batch);

                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);
                secureConnection.SaveEntityCollection(changes, ref callStatus);

                if (callStatus.Result == CallStatusenumCallResult.Success)
                {
                    return;
                }

                StringBuilder sb = new StringBuilder();
                foreach (ValidationError error in callStatus.Messages)
                {
                    sb.AppendLine(error.Message);
                }

                throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
            }
        }
예제 #6
0
        internal void Save(DataEntityCollectionDTO entitys, SecurityToken sessionToken)
        {
            // Almost all iSIMS calls fill a callStatus response message in with status and error messages.
            CallStatus callStatus = new CallStatus();

            // Create a communication channel factory to communicate with the iSIMS application server
            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory())
            {
                // Because our communication now will be secured using our Identity Token we need to use some WIF extension methods to make sure the identity token
                // is sent as a Cookie on the SOAP call that WCF will be generating.
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);

                DataEntityDTOChangeBatchCollection changes = new DataEntityDTOChangeBatchCollection
                {
                    Batches = new List <DataEntityDTOChangeBatch>()
                };
                DataEntityDTO.DataModelTypeDTO dataModelType = new DataEntityDTO.DataModelTypeDTO {
                    SchemaName = "dbo", DataModelPurpose = "BusinessDataModel"
                };
                changes.DataModelType = dataModelType;
                DataEntityDTOChangeBatch batch = new DataEntityDTOChangeBatch {
                    EntitiesToSave = entitys
                };
                DataEntitySaveContext batchSaveContext = new DataEntitySaveContext();
                List <string>         alternateKeys    = new List <string>();
                // Simplest thing to do is declare which field we believe we have changed
                List <string> batchSaveScope = new List <string> {
                    "Learner.PreferredForename"
                };
                List <WorkflowPackage> customWorkflows = new List <WorkflowPackage>();
                batchSaveContext.SaveScope             = batchSaveScope;
                batchSaveContext.AlternateKeyFields    = alternateKeys;
                batchSaveContext.CustomWorkflows       = customWorkflows;
                batchSaveContext.CustomDeleteWorkflows = new List <WorkflowPackage>();
                batch.SaveContext = batchSaveContext;
                changes.Batches.Add(batch);
                secureConnection.SaveEntityCollection(changes, ref callStatus);



                // Handle an unsuccessful call.
                if (callStatus.Result != CallStatusenumCallResult.Success)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ValidationError error in callStatus.Messages)
                    {
                        sb.AppendLine(error.Message);
                    }
                    throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
                }
            }
        }
예제 #7
0
        public void GetDataFromTheWebService()
        {
            var sq = new StudentQuery(ApplicationServerAddress, SecurityServerAddress);
            //Login and get session token
            SecurityToken sessionToken = sq.Login(UserName, Password, SchoolId, TenantId);
            //Retrieve student entity based on id
            DataEntityCollectionDTO students = sq.RetrieveSingleLearnerById(Learnerid, sessionToken);

            //Display Student
            sq.DisplayDataInConsoleWindow(students);
            //Logoff
            sq.Logoff(UserName, Password, sessionToken);
        }
예제 #8
0
        /// <summary>
        /// Make some modifications to the Learner entity fetched by RetrieveSingleLearnerByID
        /// </summary>
        internal DataEntityCollectionDTO MakeModificatons(DataEntityCollectionDTO entitys, string editedvalue)
        {
            // The data structure returned may have many entities, (in our case a mixture of Address, LearnerAddress and Learner). The TopLevelDtoIDs collection
            // gives the list of unique IDs that represent the Learner entitities we requested.
            foreach (int referenceId in entitys.TopLevelDtoIDs)
            {
                // In our case there is only one expected TopLevel entity
                DataEntityDTO entity = entitys.DataEntityDtos[referenceId];
                // SimplePropertyDTO
                ((DataEntityDTO.SimplePropertyDTOString)entity.Values["PreferredForename"]).Value = editedvalue;
            }

            return(entitys);
        }
예제 #9
0
        /// <summary>
        /// Example of retrieving some data from the application server. In this case we will use the ReadEnity call to retrieve data for a single Learner entity.
        ///
        /// This illustrates the method of constructing a single entity query, and handling the results that are returned. It also illustrates the use of the CallStatus
        /// structure to retrieve information about the call, and any failures that occured.
        /// </summary>
        /// <param name="learnerid"></param>
        /// <param name="sessionToken"></param>
        internal DataEntityCollectionDTO RetrieveSingleLearnerById(string learnerid, SecurityToken sessionToken)
        {
            // The security summary will be filled with any notifications of data fields which were removed by the security protocols prior to being sent to the recipient. This
            // enables you to see whether your data has been redacted before you got to see it.
            SecuritySummary securitySummary = new SecuritySummary();

            // Almost all iSIMS calls fill a callStatus response message in with status and error messages.
            CallStatus callStatus = new CallStatus();

            // Create a communication channel factory to communicate with the iSIMS application server
            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory())
            {
                // Because our communication now will be secured using our Identity Token we need to use some WIF extension methods to make sure the identity token
                // is sent as a Cookie on the SOAP call that WCF will be generating.
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);
                Guid          studentId        = new Guid(learnerid);

                // Construct a query to read a specific entity from SIMS8
                DataEntityCollectionDTO entities = secureConnection.ReadEntity( // Tell it which specific unique entity we want to fetch
                    studentId,                                                  // Tell it what type of entity this is
                    "Learner",                                                  // Tell it what scope of data we want to get back from the call.
                    new List <string>(new[]
                {
                    // The surname and forename
                    "Learner.LegalSurname",
                    "Learner.LegalForename",
                    "Learner.PreferredForename",
                    // The Unique Pupil Number
                    "Learner.UPN",
                    // The Learners Addresses, start date. Note that there are many Addresses attached to a single Learner
                    "Learner.LearnerAddresses.StartDate",
                    // The Learners Addresses, Post Code
                    "Learner.LearnerAddresses.Address.PostCode"
                }), ref securitySummary, ref callStatus);

                // Handle an unsuccessful call.
                if (callStatus.Result != CallStatusenumCallResult.Success)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ValidationError error in callStatus.Messages)
                    {
                        sb.AppendLine(error.Message);
                    }
                    throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
                }
                return(entities);
            }
        }
예제 #10
0
        public static List <Guid> AddRoom(string roomShortName, string roomLongName)
        {
            var query        = new RoomQuery();
            var sessionToken = query.Login(TestDefaults.Default.TestUser,
                                           TestDefaults.Default.TestUserPassword,
                                           TestDefaults.Default.SchoolID,
                                           TestDefaults.Default.TenantId.ToString(CultureInfo.InvariantCulture),
                                           Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath,
                                           Configuration.GetSutUrl() + TestDefaults.Default.SecurityServerPath);

            //Retrieved collection of Staff Records
            DataEntityCollectionDTO staffCollection = query.RetrieveEntityByNameQuery("SIMS8SchoolRoomSearchQuery", new Dictionary <string, object>(), sessionToken);

            return(null);
        }
예제 #11
0
        /// <summary>
        /// Get year group details
        /// </summary>
        /// <param name="shortName"></param>
        /// <param name="sessionToken"></param>
        /// <returns></returns>
        private static DataEntityDTO getyearGroupDetails(string shortName, SecurityToken sessionToken)
        {
            //New Instance of DataExchangeQuery
            DataExchangeQuery dataExchangeQuery = new DataExchangeQuery();

            DataQuery yearGroupQuery = CreateStandardQuery("YearGroup", "dbo");

            yearGroupQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "YearGroup.ShortName", new QuerySelectionField {
                      SymbolName = "YearGroup.ShortName"
                  } }
            };
            yearGroupQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "YearGroup.ShortName",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue()
                        {
                            SymbolName     = "ShortName",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            var parameters = new Dictionary <string, object>()
            {
                {
                    "ShortName", shortName
                }
            };

            DataEntityCollectionDTO yearGroupCollection = dataExchangeQuery.RetrieveEntityByQuery(yearGroupQuery, parameters, sessionToken);

            return(yearGroupCollection.DataEntityDtos.FirstOrDefault().Value);
        }
예제 #12
0
        public void SaveDataUsingTheWeservice()
        {
            var sq = new StudentQuery(ApplicationServerAddress, SecurityServerAddress);
            //Logon
            SecurityToken sessionToken = sq.Login(UserName, Password, SchoolId, TenantId);
            //Retrieve student entity based on id
            DataEntityCollectionDTO students = sq.RetrieveSingleLearnerById(Learnerid, sessionToken);
            //we only bring back 1 student so
            DataEntityCollectionDTO changedStudents = sq.MakeModificatons(students, "Dude");

            //Save the student
            sq.Save(changedStudents, sessionToken);
            //Retrive student with new details
            students = sq.RetrieveSingleLearnerById(Learnerid, sessionToken);
            //Display Student
            sq.DisplayDataInConsoleWindow(students);
            //Logoff
            sq.Logoff(UserName, Password, sessionToken);
        }
예제 #13
0
        /// <summary>
        /// Get Learner Enrolment Status details
        /// </summary>
        /// <param name="enrolmentStatusCode"></param>
        /// <param name="sessionToken"></param>
        /// <returns></returns>
        private static DataEntityDTO getEnrolmentStatus(string enrolmentStatusCode, SecurityToken sessionToken)
        {
            //New Instance of DataExchangeQuery
            DataExchangeQuery dataExchangeQuery = new DataExchangeQuery();
            //Retrieve collection of Genders
            DataQuery enrolmentStatusQuery = CreateStandardQuery("EnrolmentStatus", "dbo");

            enrolmentStatusQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "EnrolmentStatus.Code", new QuerySelectionField {
                      SymbolName = "EnrolmentStatus.Code"
                  } }
            };
            enrolmentStatusQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "EnrolmentStatus.Code",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue
                        {
                            SymbolName     = "enrolmentStatusCode",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            var parameters = new Dictionary <string, object>()
            {
                { "enrolmentStatusCode", enrolmentStatusCode }
            };

            DataEntityCollectionDTO enrolmentStatusCollection = dataExchangeQuery.RetrieveEntityByQuery(enrolmentStatusQuery, parameters, sessionToken);

            return(enrolmentStatusCollection.DataEntityDtos.FirstOrDefault().Value);
        }
예제 #14
0
        private static DataEntityDTO GetNoteCategory(PupilQuery pupilQuery, SecurityToken sessionToken, string categoryCode)
        {
            //Retrieve collection of Pupil Log Note Categories
            DataQuery categoryQuery = CreateStandardQuery("PupilLogNoteCategory", "dbo");

            categoryQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "PupilLogNoteCategory.Code", new QuerySelectionField {
                      SymbolName = "PupilLogNoteCategory.Code"
                  } }
            };
            categoryQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "PupilLogNoteCategory.Code",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue
                        {
                            SymbolName     = "CategoryCode",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            var parameters = new Dictionary <string, object>()
            {
                { "CategoryCode", categoryCode }
            };
            DataEntityCollectionDTO categoryCollection = pupilQuery.RetrieveEntityByQuery(categoryQuery, parameters, sessionToken);

            return(categoryCollection.DataEntityDtos.FirstOrDefault().Value);
        }
예제 #15
0
        private static DataEntityDTO GetUser(PupilQuery pupilQuery, SecurityToken sessionToken, string userName)
        {
            //Retrieve collection of Authorised Users
            DataQuery userQuery = CreateStandardQuery("AuthorisedUser", "app");

            userQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "AuthorisedUser.UserName", new QuerySelectionField {
                      SymbolName = "AuthorisedUser.UserName"
                  } }
            };
            userQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "AuthorisedUser.UserName",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue
                        {
                            SymbolName     = "UserName",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            var parameters = new Dictionary <string, object>()
            {
                { "UserName", userName }
            };
            DataEntityCollectionDTO userCollection = pupilQuery.RetrieveEntityByQuery(userQuery, parameters, sessionToken);

            return(userCollection.DataEntityDtos.FirstOrDefault().Value);
        }
예제 #16
0
        /// <summary>
        /// Get School NC year Details for pupil
        /// </summary>
        /// <param name="shortName"></param>
        /// <param name="sessionToken"></param>
        /// <returns></returns>
        private static DataEntityDTO getSchoolNCyearDetails(string shortName, SecurityToken sessionToken)
        {
            //New Instance of DataExchangeQuery
            DataExchangeQuery dataExchangeQuery = new DataExchangeQuery();

            DataQuery schoolNcYearQuery = CreateStandardQuery("SchoolNCYear", "dbo");

            schoolNcYearQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "SchoolNCYear.NCYear", new QuerySelectionField {
                      SymbolName = "SchoolNCYear.NCYear"
                  } }
            };
            schoolNcYearQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "SchoolNCYear.NCYear.ShortName",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue()
                        {
                            SymbolName     = "shortname",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            //schoolNcYearQuery.Filter = new AndExpression
            //{
            //    Expressions = new List<object> {
            //        new EqualsExpression
            //        {
            //            CurrentValue = new ParameterValue
            //            {
            //                SymbolName = "SchoolNCYear.School",
            //                SymbolTypeName = "iSIMS.Common.DataTypes.Guischoolring"
            //            },
            //           TestValue = new InputParameterValue
            //            {
            //                SymbolName = "schoolId",
            //                SymbolTypeName = typeof(string).FullName
            //            }
            //        }
            //    }
            //};

            var parameters = new Dictionary <string, object>()
            {
                {
                    "Shortname", shortName
                }
            };

            DataEntityCollectionDTO schoolNCyearCollection = dataExchangeQuery.RetrieveEntityByQuery(schoolNcYearQuery, parameters, sessionToken);

            return(schoolNCyearCollection.DataEntityDtos.FirstOrDefault().Value);
        }
예제 #17
0
        /// <summary>
        /// Add pupil data with SEN details
        /// </summary>
        /// <param name="legalForename"></param>
        /// <param name="legalSurname"></param>
        /// <param name="dateOfBirth"></param>
        /// <param name="genderCode"></param>
        /// <param name="UPN"></param>
        /// <param name="admissionno"></param>
        /// <param name="startDate"></param>
        /// <param name="senStatusCode"></param>
        /// <param name="senNeedTypeCode"></param>
        /// <param name="rank"></param>
        /// <param name="leavingDate"></param>
        /// <returns></returns>
        public static Guid AddPupilWithSEN(string legalForename, string legalSurname, string dateOfBirth, string genderCode, string shortNameYearGroup, string UPN, string admissionno, string startDate, string senStatusCode, string senNeedTypeCode, int rank, string shortNameNCYear, string enrolmentStatusCode, string leavingDate = null)
        {
            //New Instance of DataExchangeQuery
            DataExchangeQuery dataExchangeQuery = new DataExchangeQuery();

            string sql      = "SELECT id FROM school WHERE Name ='" + TestDefaults.Default.SchoolName.Replace("'", "''") + "'";
            Guid   schoolid = DataAccessHelpers.GetValue <Guid>(sql);


            //Security Token
            SecurityToken sessionToken = dataExchangeQuery.Login(TestDefaults.Default.TestUser,
                                                                 TestDefaults.Default.TestUserPassword,
                                                                 schoolid.ToString(),
                                                                 TestDefaults.Default.TenantId.ToString(CultureInfo.InvariantCulture),
                                                                 Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath,
                                                                 Configuration.GetSutUrl() + TestDefaults.Default.SecurityServerPath);

            //create collection of Pupil Records
            DataEntityCollectionDTO pupilCollection = new DataEntityCollectionDTO();

            pupilCollection.DataEntityDtos = new Dictionary <int, DataEntityDTO>();
            pupilCollection.TopLevelDtoIDs = new List <int>();

            int pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            Guid pupilID                  = Guid.NewGuid();
            Guid learnerSENStatusID       = Guid.NewGuid();
            Guid learnerSENneedTypeID     = Guid.NewGuid();
            Guid learnerEnrolmentID       = Guid.NewGuid();
            Guid learnerNCyearID          = Guid.NewGuid();
            Guid learneryearID            = Guid.NewGuid();
            Guid learnerenrolmentStatusID = Guid.NewGuid();

            //get basic details to save pupil
            DataEntityDTO gender       = getGenderDetails(genderCode, sessionToken);
            DataEntityDTO schoolncyear = getSchoolNCyearDetails(shortNameNCYear, sessionToken);

            DataEntityDTO yeargroup = getyearGroupDetails(shortNameYearGroup, sessionToken);
            Guid          yeargroupguid;

            if (yeargroup == null)
            {
                string yeargroupQuery = "SELECT TOP 1 ID FROM dbo.yeargroup WHERE school = '" + schoolid + "'";
                yeargroupguid = DataAccessHelpers.GetValue <Guid>(yeargroupQuery);
            }
            else
            {
                yeargroupguid = yeargroup.ID;
            }
            DataEntityDTO SENStatus = getSENStatusDetails(senStatusCode, sessionToken);
            DataEntityDTO needType  = getNeedTypeDetails(senNeedTypeCode, sessionToken);
            DataEntityDTO learnerEnrolmentStatus = getEnrolmentStatus(enrolmentStatusCode, sessionToken);

            //Create the Pupil Record
            DataEntityDTO pupil = dataExchangeQuery.CreatePupil(pupilID,
                                                                legalForename,
                                                                legalSurname,
                                                                dateOfBirth,
                                                                gender.ID,
                                                                yeargroupguid,
                                                                UPN,
                                                                admissionno,
                                                                schoolid,
                                                                pupilCollectionCount,
                                                                pupilCollection.ExtensionData);

            //Add the Pupil Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, pupil);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            DataEntityDTO enrolment = dataExchangeQuery.CreateLearnerEnrolment(learnerEnrolmentID,
                                                                               pupilID,
                                                                               startDate,
                                                                               leavingDate,
                                                                               schoolid,
                                                                               pupil.ReferenceID,
                                                                               pupilCollectionCount,
                                                                               pupilCollection.ExtensionData);

            //Add the enrolment Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, enrolment);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            //Add sen status and needtype as a reference property
            DataEntityDTO.ReferencePropertyDTO learnerEnrolmentProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learnerEnrolmentID,
                InternalReferenceID = (short?)pupilCollectionCount
            };


            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;


            DataEntityDTO learnerEnrolmentStatusEntity = dataExchangeQuery.CreateLearnerEnrolmentStatus(learnerenrolmentStatusID,
                                                                                                        learnerEnrolmentID,
                                                                                                        learnerEnrolmentStatus.ID,
                                                                                                        startDate,
                                                                                                        leavingDate,
                                                                                                        pupil.ReferenceID,
                                                                                                        pupilCollectionCount,
                                                                                                        pupilCollection.ExtensionData);

            //Add the enrolment Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, learnerEnrolmentStatusEntity);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            //Add sen status and needtype as a reference property
            DataEntityDTO.ReferencePropertyDTO learnerEnrolmentStatusProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learnerenrolmentStatusID,
                InternalReferenceID = (short?)pupilCollectionCount
            };


            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;


            //Create the learner year Record
            DataEntityDTO learnerYeargroup = dataExchangeQuery.CreateLearnerYearGroup(learneryearID,
                                                                                      pupilID,
                                                                                      startDate,
                                                                                      yeargroupguid,
                                                                                      pupil.ReferenceID,
                                                                                      pupilCollectionCount,
                                                                                      pupilCollection.ExtensionData);

            //Add the yeargroup Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, learnerYeargroup);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);


            DataEntityDTO.ReferencePropertyDTO learnerYearGroupProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learneryearID,
                InternalReferenceID = (short?)pupilCollectionCount
            };

            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            //Create the pupil ncyear Record
            DataEntityDTO learnerncyear = dataExchangeQuery.CreateLearnerNCYear(learnerNCyearID,
                                                                                pupilID,
                                                                                startDate,
                                                                                schoolncyear.ID,
                                                                                pupil.ReferenceID,
                                                                                pupilCollectionCount,
                                                                                pupilCollection.ExtensionData);

            //Add the nc year Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, learnerncyear);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            //Add sen status and needtype as a reference property
            DataEntityDTO.ReferencePropertyDTO learnerNCYearProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learnerNCyearID,
                InternalReferenceID = (short?)pupilCollectionCount
            };


            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            //Create the SENnStatus Record
            DataEntityDTO learnerSenStatus = dataExchangeQuery.CreateSENStatus(learnerSENStatusID,
                                                                               SENStatus.ID,
                                                                               startDate,
                                                                               pupilID,
                                                                               pupil.ReferenceID,
                                                                               pupilCollectionCount,
                                                                               pupilCollection.ExtensionData);

            //Add sen status and needtype as a reference property
            DataEntityDTO.ReferencePropertyDTO learnerSENStatusProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learnerSENStatusID,
                InternalReferenceID = (short?)pupilCollectionCount
            };

            //Add the SEN details to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, learnerSenStatus);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            //Create the SEN need type
            DataEntityDTO learnerSenNeedType = dataExchangeQuery.CreateSENSNeed(learnerSENneedTypeID,
                                                                                needType.ID,
                                                                                rank,
                                                                                startDate,
                                                                                pupilID,
                                                                                pupil.ReferenceID,
                                                                                pupilCollectionCount,
                                                                                pupilCollection.ExtensionData);

            //Add the Service Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, learnerSenNeedType);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            DataEntityDTO.ReferencePropertyDTO learnerSENSNeedProperty = new DataEntityDTO.ReferencePropertyDTO
            {
                EntityPrimaryKey    = learnerSENneedTypeID,
                InternalReferenceID = (short?)pupilCollectionCount
            };

            DataEntityDTO.ReferencePropertyDTOArray learnerSENStatus = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerSENStatusProperty
                }
            };


            DataEntityDTO.ReferencePropertyDTOArray learnerNeedType = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerSENSNeedProperty
                }
            };

            DataEntityDTO.ReferencePropertyDTOArray enrolmentReference = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerEnrolmentProperty
                }
            };

            DataEntityDTO.ReferencePropertyDTOArray enrolmentStatusReference = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerEnrolmentStatusProperty
                }
            };


            DataEntityDTO.ReferencePropertyDTOArray ncyearReference = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerNCYearProperty
                }
            };

            DataEntityDTO.ReferencePropertyDTOArray yearReference = new DataEntityDTO.ReferencePropertyDTOArray
            {
                ReferenceProperties = new List <DataEntityDTO.ReferencePropertyDTO> {
                    learnerYearGroupProperty
                }
            };

            enrolment.Values.Add("MulitpleLearnerEnrolmentStatus", enrolmentStatusReference);

            //Add references in pupil entity
            pupil.Values.Add("LearnerEnrolments", enrolmentReference);
            //pupil.Values.Add("LearnerEnrolments.MulitpleLearnerEnrolmentStatus", enrolmentStatusReference);
            pupil.Values.Add("LearnerYearGroupMemberships", yearReference);
            pupil.Values.Add("LearnerNCYearMemberships", ncyearReference);
            pupil.Values.Add("LearnerSENStatuses", learnerSENStatus);
            pupil.Values.Add("LearnerSENNeedTypes", learnerNeedType);


            //Save Scope for Pupil
            List <string> pupilSaveScope = new List <string>
            {
                "Learner.ID",
                "Learner.LegalForename",
                "Learner.LegalSurname",
                "Learner.DateOfBirth",
                "Learner.Gender",
                "Learner.School",
                "Learner.AdmissionNumber",
                "Learner.UPN",
                "Learner.YearGroup",
                "Learner.LearnerEnrolments.DOA",
                "Learner.LearnerEnrolments.DOL",
                "Learner.LearnerEnrolments.School",
                "Learner.LearnerEnrolments.Learner",
                "Learner.LearnerEnrolments.MulitpleLearnerEnrolmentStatus.EnrolmentStatus",
                "Learner.LearnerEnrolments.MulitpleLearnerEnrolmentStatus.LearnerEnrolment",
                "Learner.LearnerEnrolments.MulitpleLearnerEnrolmentStatus.StartDate",
                "Learner.LearnerEnrolments.MulitpleLearnerEnrolmentStatus.EndDate",
                "Learner.LearnerYearGroupMemberships.StartDate",
                "Learner.LearnerYearGroupMemberships.Learner",
                "Learner.LearnerYearGroupMemberships.YearGroup",
                "Learner.LearnerNCYearMemberships.StartDate",
                "Learner.LearnerNCYearMemberships.Learner",
                "Learner.LearnerNCYearMemberships.SchoolNCYear",
                "Learner.LearnerSENStatuses.StartDate",
                "Learner.LearnerSENStatuses.Learner",
                "Learner.LearnerSENStatuses.SENStatus",
                "Learner.LearnerSENNeedTypes.NeedType",
                "Learner.LearnerSENNeedTypes.StartDate",
                "Learner.LearnerSENNeedTypes.Rank",
                "Learner.LearnerSENNeedTypes.Learner"
            };

            //Save the modified collection
            dataExchangeQuery.Save(pupilCollection, sessionToken, Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath, pupilSaveScope);

            return(pupilID);
        }
예제 #18
0
        public static Guid AddStandardPupilLogNote(Guid learnerID, string title, string noteText, string categoryCode, bool pinned, string userName = "******")
        {
            //New Instance of PupilQuery
            PupilQuery pupilQuery = new PupilQuery();

            //Security Token
            SecurityToken sessionToken = pupilQuery.Login(TestDefaults.Default.SchoolAdministrator,
                                                          TestDefaults.Default.SchoolAdministratorPassword,
                                                          TestDefaults.Default.SchoolID,
                                                          TestDefaults.Default.TenantId.ToString(CultureInfo.InvariantCulture),
                                                          Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath,
                                                          Configuration.GetSutUrl() + TestDefaults.Default.SecurityServerPath);

            //Retrieve collection of Pupil Log Notes
            DataQuery noteQuery = CreateStandardQuery("PupilLogNoteStandard", "dbo");

            noteQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "PupilLogNoteStandard.Title", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.Title"
                  } },
                { "PupilLogNoteStandard.NoteText", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.NoteText"
                  } },
                { "PupilLogNoteStandard.Pinned", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.Pinned"
                  } },
                { "PupilLogNoteStandard.CreatedOn", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.CreatedOn"
                  } },
                { "PupilLogNoteStandard.CreatedByUserId", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.CreatedByUserId"
                  } },
                { "PupilLogNoteStandard.Learner", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.Learner"
                  } },
                { "PupilLogNoteStandard.PupilLogNoteCategory", new QuerySelectionField {
                      SymbolName = "PupilLogNoteStandard.PupilLogNoteCategory"
                  } }
            };
            noteQuery.Filter = new AndExpression {
                Expressions = new List <object>()
            };
            var parameters = new Dictionary <string, object>();
            DataEntityCollectionDTO noteCollection = pupilQuery.RetrieveEntityByQuery(noteQuery, parameters, sessionToken);

            var category      = GetNoteCategory(pupilQuery, sessionToken, categoryCode);
            var createdByUser = GetUser(pupilQuery, sessionToken, userName);
            int pupilLogNoteCollectionCount = noteCollection.DataEntityDtos.Count;

            Guid pupilLogNoteID = Guid.NewGuid();

            //Create the PupilLog Note
            DataEntityDTO pupilLogNote = pupilQuery.CreateStandardPupilLogNote(pupilLogNoteID,
                                                                               title,
                                                                               noteText,
                                                                               learnerID,
                                                                               category.ID,
                                                                               createdByUser.ID,
                                                                               pinned,
                                                                               category.ReferenceID,
                                                                               pupilLogNoteCollectionCount,
                                                                               noteCollection.ExtensionData);

            noteCollection.DataEntityDtos.Add(pupilLogNoteCollectionCount, pupilLogNote);
            noteCollection.TopLevelDtoIDs.Add(pupilLogNoteCollectionCount);

            //Save Scope for Pupil Log Note
            List <string> pupilLogNoteSaveScope = new List <string>
            {
                "PupilLogNoteStandard.ID",
                "PupilLogNoteStandard.Title",
                "PupilLogNoteStandard.NoteText",
                "PupilLogNoteStandard.Pinned",
                "PupilLogNoteStandard.CreatedOn",
                "PupilLogNoteStandard.CreatedByUserId",
                "PupilLogNoteStandard.Learner",
                "PupilLogNoteStandard.PupilLogNoteCategory"
            };

            //Save the modified collection
            pupilQuery.Save(noteCollection, sessionToken, Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath, pupilLogNoteSaveScope);

            return(pupilLogNoteID);
        }
예제 #19
0
        public static List <Guid> AddPupil(string legalForename, string legalSurname, Date dateOfBirth, string genderCode)
        {
            //New Instance of PupilQuery
            PupilQuery pupilQuery = new PupilQuery();

            //Security Token
            SecurityToken sessionToken = pupilQuery.Login(TestDefaults.Default.SchoolAdministrator,
                                                          TestDefaults.Default.SchoolAdministratorPassword,
                                                          TestDefaults.Default.SchoolID,
                                                          TestDefaults.Default.TenantId.ToString(CultureInfo.InvariantCulture),
                                                          Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath,
                                                          Configuration.GetSutUrl() + TestDefaults.Default.SecurityServerPath);

            //Retrieved collection of Pupil Records
            DataEntityCollectionDTO pupilCollection = pupilQuery.RetrieveEntityByNameQuery("SIMS8PupilSearchQuery", new Dictionary <string, object>(), sessionToken);

            int pupilCollectionCount = pupilCollection.DataEntityDtos.Count;

            Guid pupilID = Guid.NewGuid();

            //Retrieve collection of Genders
            DataQuery genderQuery = CreateStandardQuery("Gender", "dbo");

            genderQuery.SelectedElements = new Dictionary <string, QuerySelectionElementBase>
            {
                { "Gender.Code", new QuerySelectionField {
                      SymbolName = "Gender.Code"
                  } }
            };
            genderQuery.Filter = new AndExpression
            {
                Expressions = new List <object> {
                    new EqualsExpression
                    {
                        CurrentValue = new ParameterValue
                        {
                            SymbolName     = "Gender.Code",
                            SymbolTypeName = "iSIMS.Common.DataTypes.String"
                        },
                        TestValue = new InputParameterValue
                        {
                            SymbolName     = "GenderCode",
                            SymbolTypeName = typeof(string).FullName
                        }
                    }
                }
            };

            var parameters = new Dictionary <string, object>()
            {
                { "GenderCode", genderCode }
            };

            DataEntityCollectionDTO genderCollection = pupilQuery.RetrieveEntityByQuery(genderQuery, parameters, sessionToken);
            DataEntityDTO           gender           = genderCollection.DataEntityDtos.FirstOrDefault().Value;

            //Create the Pupil Record
            DataEntityDTO pupil = pupilQuery.CreatePupil(pupilID,
                                                         legalForename,
                                                         legalSurname,
                                                         dateOfBirth,
                                                         gender.ID,
                                                         Guid.Parse(TestDefaults.Default.SchoolID),
                                                         pupilCollectionCount,
                                                         pupilCollection.ExtensionData);

            //Add the Pupil Record to the collection
            pupilCollection.DataEntityDtos.Add(pupilCollectionCount, pupil);
            pupilCollection.TopLevelDtoIDs.Add(pupilCollectionCount);

            //Save Scope for Pupil
            List <string> pupilSaveScope = new List <string>
            {
                "Learner.ID",
                "Learner.LegalForename",
                "Learner.LegalSurname",
                "Learner.DateOfBirth",
                "Learner.Gender",
                "Learner.School"
            };

            //Save the modified collection
            pupilQuery.Save(pupilCollection, sessionToken, Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath, pupilSaveScope);

            return(new List <Guid> {
                pupilID
            });
        }