Example #1
0
        /// <summary>
        /// Writes the Pupil UDF to SIMS .net (string)
        /// </summary>
        /// <param name="personid"></param>
        /// <param name="udfvalue"></param>
        /// <returns></returns>
        public bool SetPupilUDF(int personid, string udfvalue)
        {
            logger.Log(LogLevel.Debug, "SIMSAPI-SetPupilUDF - personid: " + personid + " - udfvalue: " + udfvalue);
            bool result = false;

            try
            {
                //logger.Log(NLog.LogLevel.Info, "PersonId: " + personid + " - UDF: " + udfvalue);
                using (EditStudentInformation studentsedt = new EditStudentInformation())
                {
                    StudentEditResult status = studentsedt.Load(new Person(personid), DateTime.Now);
                    foreach (UDFValue udfVal in studentsedt.Student.UDFValues)
                    {
                        //logger.Log(NLog.LogLevel.Debug, "Checkpoint1");
                        if (simsudf == udfVal.TypedValueAttribute.Description)
                        {
                            if (Core.SetUdf(udfVal, udfvalue))
                            {
                                studentsedt.Save();
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
                logger.Error("UDF {0} not found.", simsudf);
                return(false);
            }
            catch (Exception SetPupilUDF_Exception)
            {
                logger.Log(LogLevel.Error, SetPupilUDF_Exception);
                result = false;
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Writes a new Pupil email address into the SIMS database
        /// </summary>
        /// <param name="personid"></param>
        /// <param name="emailValue"></param>
        /// <param name="main"></param>
        /// <param name="primary"></param>
        /// <param name="notes"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public bool SetPupilEmail(Int32 personid, string emailValue, string main, string primary, string notes, string location)
        {
            try
            {
                logger.Log(LogLevel.Debug, "Trace:: SIMSBulkImport.Classes.Pupils.SetPupilEmail(personid=" + personid + ", emailValue=" + emailValue +
                           ", main=" + main + ", primary=" + primary + ", notes=" + notes + ", location=" + location);
                var studentsedt = new EditStudentInformation();

                // Load Pupil\Student record
                StudentEditResult status = studentsedt.Load(new Person(personid), DateTime.Now);

                // Create a new email record
                var email = new EMail();

                // Set the email address
                email.AddressAttribute.Value = emailValue;

                // Set Main
                switch (main)
                {
                case "Yes":
                    email.MainAttribute.Value = (studentsedt.Student.Communication.Emails.Value.Count > 0)
                            ? EMailMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : EMailMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;

                case "Yes (Overwrite)":
                    email.MainAttribute.Value = EMailMainCollection.GetValues().Item(1);
                    break;

                case "No":
                    email.MainAttribute.Value = EMailMainCollection.GetValues().Item(0);
                    break;

                default:
                    email.MainAttribute.Value = (studentsedt.Student.Communication.Emails.Value.Count > 0)
                            ? EMailMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : EMailMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;
                }

                // Set Primary
                switch (primary)
                {
                case "Yes":
                    email.PrimaryAttribute.Value = (studentsedt.Student.Communication.Emails.Value.Count > 0)
                            ? EMailPrimaryCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : EMailPrimaryCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;

                case "Yes (Overwrite)":
                    email.PrimaryAttribute.Value = EMailPrimaryCollection.GetValues().Item(1);
                    break;

                case "No":
                    email.PrimaryAttribute.Value = EMailPrimaryCollection.GetValues().Item(0);
                    break;

                default:
                    email.PrimaryAttribute.Value = (studentsedt.Student.Communication.Emails.Value.Count > 0)
                            ? EMailPrimaryCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : EMailPrimaryCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;
                }

                // Set the notes
                if (!string.IsNullOrWhiteSpace(notes))
                {
                    email.NotesAttribute.Value = notes;
                }

                // Set the location
                email.LocationAttribute.Value = PersonCache.EmailLocations.ItemByDescription(location);

                // Run Validation against the new record
                email.Validate();
                logger.Log(LogLevel.Debug, "Email Valid: " + email.Valid());

                // Save the new record to the database
                studentsedt.Student.Communication.Emails.Add(email);
                StudentEditResult result = studentsedt.Save();
                switch (result)
                {
                case StudentEditResult.Success:
                    return(true);

                case StudentEditResult.DuplicateFound:
                    logger.Log(LogLevel.Error, "DuplicateFound");
                    return(false);

                case StudentEditResult.Failure:
                    logger.Log(LogLevel.Error, "Failure");
                    return(false);

                case StudentEditResult.Unknown:
                    logger.Log(LogLevel.Error, "Unknown");
                    return(false);

                default:
                    logger.Log(LogLevel.Error, "default");
                    return(false);
                }
            }
            catch (Exception SetStudentEmailException)
            {
                logger.Log(LogLevel.Error, SetStudentEmailException);
                return(false);
            }
        }
Example #3
0
        public bool SetPupilTelephone(Int32 personid, string telephone, string main, string primary, string notes, string location, string device)
        {
            try
            {
                logger.Log(LogLevel.Debug, "Trace:: SIMSBulkImport.Classes.Pupils.SetPupilTelephone(personid=" + personid + ", telephone=" + telephone +
                           ", main=" + main + ", primary=" + primary + ", notes=" + notes + ", location=" + location + ", device=" + device);
                var studentsedt = new EditStudentInformation();

                // Load Pupil\Student record
                StudentEditResult status = studentsedt.Load(new Person(personid), DateTime.Now);

                // Create a new telephone number
                var phone = new Telephone();

                // Set the telephone number
                phone.NumberAttribute.Value = telephone;

                // Set Main
                switch (main)
                {
                case "Yes":
                    phone.MainAttribute.Value = (studentsedt.Student.Communication.Phones.Value.Count > 0)
                            ? TelephoneMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : TelephoneMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;

                case "Yes (Overwrite)":
                    phone.MainAttribute.Value = TelephoneMainCollection.GetValues().Item(1);
                    break;

                case "No":
                    phone.MainAttribute.Value = TelephoneMainCollection.GetValues().Item(0);
                    break;

                default:
                    phone.MainAttribute.Value = (studentsedt.Student.Communication.Phones.Value.Count > 0)
                            ? TelephoneMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : TelephoneMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;
                }

                // Set primary
                switch (primary)
                {
                case "Yes":
                    phone.PrimaryAttribute.Value = (studentsedt.Student.Communication.Phones.Value.Count > 0)
                            ? TelephoneMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : TelephoneMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;

                case "Yes (Overwrite)":
                    phone.PrimaryAttribute.Value = TelephoneMainCollection.GetValues().Item(1);
                    break;

                case "No":
                    phone.PrimaryAttribute.Value = TelephoneMainCollection.GetValues().Item(0);
                    break;

                default:
                    phone.PrimaryAttribute.Value = (studentsedt.Student.Communication.Phones.Value.Count > 0)
                            ? TelephoneMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : TelephoneMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;
                }

                // Set the notes
                if (!string.IsNullOrWhiteSpace(notes))
                {
                    phone.NotesAttribute.Value = notes;
                }

                // Set the location
                phone.LocationAttribute.Value = PersonCache.TelephoneLocations.ItemByDescription(location);

                // Set the device (telephone\fax)
                phone.DeviceAttribute.Value = PersonCache.TelephoneDevices.ItemByDescription(device);

                // Run Validation against the new record
                phone.Validate();
                logger.Log(LogLevel.Debug, "Telephone Valid: " + phone.Valid());

                // Writes the new record to the database
                studentsedt.Student.Communication.Phones.Add(phone);
                StudentEditResult result = studentsedt.Save();
                switch (result)
                {
                case StudentEditResult.Success:
                    return(true);

                case StudentEditResult.DuplicateFound:
                    logger.Log(LogLevel.Error, "DuplicateFound");
                    return(false);

                case StudentEditResult.Failure:
                    logger.Log(LogLevel.Error, "Failure");
                    return(false);

                case StudentEditResult.Unknown:
                    logger.Log(LogLevel.Error, "Unknown");
                    return(false);

                default:
                    logger.Log(LogLevel.Error, "default");
                    return(false);
                }
            }
            catch (Exception SetPupilTelephone_Exception)
            {
                logger.Log(LogLevel.Error, "SetPupilTelephone " + SetPupilTelephone_Exception);
                return(false);
            }
        }