/// <summary>
        /// Assistant method that creates the recipient name for a message depending on the message type
        /// </summary>
        /// <param name="message">The source message</param>
        /// <param name="messageType">The type of recipient (class, everyone, specific person...)</param>
        /// <returns>The fitting recipient name</returns>
        private static string GetRecipientName(Message message, MessageRecipientsTypes messageType)
        {
            string recipientName;

            switch (messageType)
            {
            case MessageRecipientsTypes.Class:
                recipientName = "כיתה " + message.Class.className;
                break;

            case MessageRecipientsTypes.Everyone:
                recipientName = "הודעה כללית";
                break;

            case MessageRecipientsTypes.Management:
                recipientName = "הנהלה";
                break;

            case MessageRecipientsTypes.Students:
                recipientName = "תלמידים";
                break;

            case MessageRecipientsTypes.Teachers:
                recipientName = "מורים";
                break;

            case MessageRecipientsTypes.Person:
            default:
                recipientName = message.ReceiverPerson.firstName + " " + message.ReceiverPerson.lastName;
                break;
            }

            return(recipientName);
        }
        /// <summary>
        /// Converts the Model's Message object in a local DisplayedMessage object
        /// </summary>
        /// <param name="message">The message to convert</param>
        /// <param name="messageType">The message to convert</param>
        /// <returns>DisplayedMessage version of the message</returns>
        private DisplayedMessage ModelMessageToDisplayedMessage(Message message, MessageRecipientsTypes messageType)
        {
            // Make sure input is correct
            if (message == null)
            {
                throw new ArgumentNullException("Arguement 'message' cannot be null!");
            }

            DisplayedMessage displayedMessage = new DisplayedMessage();

            // Get the name of the sender (unless it is an automatic message)
            if (message.senderID != null)
            {
                displayedMessage.SenderName = message.SenderPerson.firstName + " " + message.SenderPerson.lastName;
            }
            else
            {
                displayedMessage.SenderName = "הודעה אוטומטית";
            }

            displayedMessage.RecipientName   = GetRecipientName(message, messageType);
            displayedMessage.Title           = message.title;
            displayedMessage.MessageDateTime = message.date;
            displayedMessage.Details         = message.data;

            return(displayedMessage);
        }
        /// <summary>
        /// Update the recipients list following a selection of recipients category
        /// </summary>
        /// <param name="recipientsType">The category of recipients to use</param>
        private void UpdateRecipientsList(MessageRecipientsTypes recipientsType)
        {
            // Create the list of recipients for the current category selection
            CreateRecipientsList(recipientsType);

            // Select first available recipient in the list (if it has any)
            SelectedRecipient = (Recipients.Count() > 0) ? Recipients.First().Key : NOT_ASSIGNED;

            // For some reason, after re-initializing the recipients list, the selection is not updated properly unless called again
            OnPropertyChanged("SelectedRecipient");
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new message and saves it
        /// </summary>
        /// <param name="title">The title of the message</param>
        /// <param name="text">The actual content of the message</param>
        /// <param name="recipientType">The type of recipients for this message</param>
        /// <param name="senderID">Person ID of the sender. If null, it is an automatic message</param>
        /// <param name="recipientID">The ID of the recipient</param>
        static public void CreateMessage(string title, string text, MessageRecipientsTypes recipientType, int?senderID = null, int?recipientID = null)
        {
            // If this recipientType requires an specific person/class ID, make sure it is defined and not null
            if (recipientType == MessageRecipientsTypes.Person ||
                recipientType == MessageRecipientsTypes.Class ||
                recipientType == MessageRecipientsTypes.Parent)
            {
                if (!recipientID.HasValue)
                {
                    throw new ArgumentNullException("recipientID", "recipientID must be defined for direct messages");
                }
            }

            // Check message recipient type and create a message accordingly
            switch (recipientType)
            {
            case MessageRecipientsTypes.Class:
                CreateMessageToClass(title, text, recipientID.Value, senderID);
                break;

            case MessageRecipientsTypes.Person:
            case MessageRecipientsTypes.Parent:
                CreateMessageToPerson(title, text, recipientID.Value, senderID);
                break;

            case MessageRecipientsTypes.Everyone:
                CreateMessageToEveryone(title, text, senderID);
                break;

            case MessageRecipientsTypes.Management:
                CreateMessageToAllManagement(title, text, senderID);
                break;

            case MessageRecipientsTypes.Students:
                CreateMessageToAllStudents(title, text, senderID);
                break;

            case MessageRecipientsTypes.Teachers:
                CreateMessageToTeachers(title, text, senderID);
                break;
            }
        }
        /// <summary>
        /// Uses the current category selection and creates the list of recipients accordingly
        /// </summary>
        /// <param name="recipientsType">The category of recipients to use</param>
        private void CreateRecipientsList(MessageRecipientsTypes recipientsType)
        {
            // Reset the recipients list
            Recipients.Clear();

            // Create the list of students
            switch (recipientsType)
            {
            case MessageRecipientsTypes.Students:
                // Adding a 'send to every student' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל התלמידים");
                }

                // Add every active student in the school
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isStudent).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Parent:
                // Add every parent in the school
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isParent).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Teachers:
                // Add a 'send to management' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל המורים");
                }

                // Add the teachers
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isTeacher).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Management:
                // Add a 'send to management' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל ההנהלה");
                }

                // Add the secretaries and principal
                _schoolData.Persons.Where(person => !person.User.isDisabled && (person.isPrincipal || person.isSecretary)).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Class:
                // Add every class in the school
                _schoolData.Classes.ToList().ForEach(schoolClass => Recipients.Add(schoolClass.classID, schoolClass.className));
                break;

            case MessageRecipientsTypes.Everyone:
                Recipients.Add(EVERYONE_OPTION, "כל בית הספר");
                break;

            default:
                throw new ArgumentException("Invalid recipient type!");
            }
        }