Exemplo n.º 1
0
        public ActionResult Add(NewEventModel newEvent)
        {
            var addEvent = new AddEventView();

            var user = _authenticatedUser.GetUserInfo();
            var evt = MapCreateEventModel(newEvent);
            evt.UserId = user.Id;

            evt.NumberSid = _service.ProcureNumber(evt.Number);

            using (var tran = _session.BeginTransaction())
            {
                _session.Save(evt);
                tran.Commit();
            }

            ViewData["timezone"] = _timezoneHydration.GetAndSetSelectedTimezone();
            addEvent.Message = string.Format("New event created. Phone number: {0}", evt.FormattedNumber);

            return View(addEvent);
        }
Exemplo n.º 2
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;
        }