コード例 #1
0
        /// <summary>
        /// SetContactEmail
        /// </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 SetContactEmail(Int32 personid, string emailValue, string main, string primary, string notes, string location)
        {
            try
            {
                logger.Log(LogLevel.Debug, "Trace:: SIMSBulkImport.Classes.Contacts.SetContactEmail(personid=" + personid + ", emailValue=" + emailValue +
                           ", main=" + main + ", primary=" + primary + ", notes=" + notes + ", location=" + location);
                var contactprocess = new EditContact();

                // Load Contact record
                contactprocess.Populate(new PersonID(personid));
                IContactRelation relation = null;
                relation = new StudentContact();
                contactprocess.Contact.ContactRelation = relation;

                // 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 = (contactprocess.Contact.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 = (contactprocess.Contact.Emails.Value.Count > 0)
                            ? EMailMainCollection.GetValues().Item(1) as CodeDescriptionEntity
                            : EMailMainCollection.GetValues().Item(0) as CodeDescriptionEntity;
                    break;
                }

                switch (primary)
                {
                case "Yes":
                    email.PrimaryAttribute.Value = (contactprocess.Contact.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 = (contactprocess.Contact.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
                contactprocess.Contact.Emails.Add(email);
                return(contactprocess.Save());
            }
            catch (Exception SetContactEmail_Exception)
            {
                logger.Log(LogLevel.Error, SetContactEmail_Exception);
                return(false);
            }
        }
コード例 #2
0
ファイル: Pupil.cs プロジェクト: SteveMac555/SIMSBulkImport
        /// <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);
            }
        }