public void Event_CreateNewEvent_EventIsSuccessfullySaved()
        {
            ISession session = ObjectFactory.GetInstance<ISession>();

            User user = new User();
            user.DisplayName = Path.GetRandomFileName();
            user.Email = Path.GetRandomFileName();
            user.Password = Path.GetRandomFileName();
            user.Username = Path.GetRandomFileName();

            using (var trans = session.BeginTransaction())
            {
                session.Save(user);
                trans.Commit();
            }

            using (var trans = session.BeginTransaction())
            {
                Event evnt = new Event();
                evnt.Name = Path.GetRandomFileName();
                evnt.UserId = user.Id;
                evnt.StartTime = DateTime.Now;
                evnt.EndTime = DateTime.Now.AddDays(1);

                session.Save(evnt);
                trans.Commit();

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the messages.
        /// </summary>
        /// <param name="evt">The evt.</param>
        /// <returns>List{BoardMessage}.</returns>
        public List<BoardMessage> GetMessages(Event evt)
        {
            var messages = _database.List<Message, object>("[dbo].[Message_GetMessageByEventId]", new { eventId = evt.Id }).ToList();

            using (var trans = _session.BeginTransaction())
            {
                _aliasLookup = _session.QueryOver<Alias>()
                                .Where(a => a.Event.Id == evt.Id)
                                .List()
                                .ToDictionary(a => a.Number);

                trans.Commit();
            }

            messages = SetHashTag(evt, messages);

            var items = messages.Select(m => ConvertToBoardMessage(m, evt.Timezone));
            return items.ToList();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Maps the specified new event.
        /// </summary>
        /// <param name="edit">The edit.</param>
        /// <returns>Event.</returns>
        private Event MapEditEventModel(Event e, EditEventModel edit)
        {
            Func<string, string, int, DateTime> toUtc = (d, t, i) => ConvertToUtc(DateTime.Parse(d + " " + t), i);

            e.FormattedNumber = edit.Formatted;
            e.BackgroundColor = edit.BackgroundColor;
            e.TextColor = edit.TextColor;
            e.Name = edit.Name;
            e.StartTime = toUtc(edit.DateStart, edit.TimeStart, edit.Timezone);
            e.Number = edit.Number;
            e.EndTime = toUtc(edit.DateEnd, edit.TimeEnd, edit.Timezone);
            e.Timezone = new Timezone {Id = edit.Timezone};

            return e;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Maps the specified new event.
        /// </summary>
        /// <param name="newEvent">The new event.</param>
        /// <returns>Event.</returns>
        private Event MapCreateEventModel(NewEventModel newEvent)
        {
            Func<string, string, int, DateTime> toUtc = (d, t, i) => ConvertToUtc(DateTime.Parse(d + " " + t), i);

            var evt = new Event
                            {
                                Name = newEvent.Name,
                                BackgroundColor = newEvent.BackgroundColor,
                                TextColor = newEvent.TextColor,
                                FormattedNumber = newEvent.Formatted,
                                EndTime = toUtc(newEvent.DateEnd, newEvent.TimeEnd, newEvent.Timezone),
                                Number = newEvent.Number,
                                StartTime = toUtc(newEvent.DateStart, newEvent.TimeStart, newEvent.Timezone),
                                Timezone = new Timezone {Id = newEvent.Timezone}
                            };
            return evt;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Converts to event json view.
        /// </summary>
        /// <param name="a">A.</param>
        /// <returns>EventJsonView.</returns>
        private EventJsonView ConvertToEventJsonView(Event a)
        {
            var start = ConvertToLocal(a.StartTime, a.Timezone.Id);
            var end = ConvertToLocal(a.EndTime, a.Timezone.Id);

            return new EventJsonView
                       {
                           Id = a.Id,
                           EndTime = end.ToShortTimeString(),
                           EndDate = end.ToShortDateString(),
                           FormattedNumber = a.FormattedNumber,
                           Name = a.Name,
                           Number = a.Number,
                           Price = a.Price,
                           StartTime = start.ToShortTimeString(),
                           StartDate = start.ToShortDateString(),
                           TimezoneName = a.Timezone.Name,
                           UserId = a.UserId,
                           TextColor = a.TextColor,
                           BackgroundColor = a.BackgroundColor
                       };
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the hash tag.
        /// </summary>
        /// <param name="evt">The evt.</param>
        /// <param name="messages">The messages.</param>
        /// <returns>List{Message}.</returns>
        private List<Message> SetHashTag(Event evt, List<Message> messages)
        {
            foreach (var message in messages)
            {
                if (message.Body.Contains("#"))
                {
                    //Find HashTag
                    var collection = Regex.Matches(message.Body, @"(?:\s|\A|^)[##]+([A-Za-z0-9-_]+)");
                    string name = collection[0].Value;

                    message.Body = message.Body.Replace(name, string.Empty);

                    //Remove Hashtag
                    name = name.Replace("#", string.Empty);
                    SaveAlias(evt, name, message);
                }
            }

            return messages;
        }