Example #1
0
        /// <summary>
        /// Converts Messages to BoardMessage.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="timezone">The timezone.</param>
        /// <returns>BoardMessage.</returns>
        private BoardMessage ConvertToBoardMessage(Message message, Timezone timezone)
        {
            string number = string.Format("{0:(###) ###-####}", Convert.ToInt64(message.From.Replace("+1", string.Empty)));
            string @from = _aliasLookup.ContainsKey(message.From) ? string.Format("{0} {1}", _aliasLookup[message.From].Name, number) : number;

            return new BoardMessage
                       {
                           From = @from,
                           Message = message.Body,
                           Time = message.Received.AddHours(timezone.OffsetHour).AddMinutes(timezone.OffsetMinutes).ToShortTimeString()
                       };
        }
Example #2
0
        /// <summary>
        /// Saves the alias.
        /// </summary>
        /// <param name="evt">The evt.</param>
        /// <param name="name">The name.</param>
        /// <param name="message">The message.</param>
        private void SaveAlias(Event evt, string name, Message message)
        {
            bool hasTagInDictionary = _aliasLookup.ContainsKey(message.From);
            var alias = new Alias { Event = evt, Name = name, Number = message.From };

            //get Instance of existing hashtag
            if (hasTagInDictionary)
            {
                alias = _aliasLookup[message.From];
                alias.Name = name;
            }

            //save hashtage
            using (var trans = _session.BeginTransaction())
            {
                _session.SaveOrUpdate(alias);
                trans.Commit();
            }

            //update hashtag collection
            if (!hasTagInDictionary)
            {
                _aliasLookup.Add(message.From, alias);
            }
        }