/// <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; }
/// <summary> /// Releases the old number. /// </summary> /// <param name="editModel">The edit model.</param> private void ReleaseOldNumber(EditEventModel editModel) { var e = GetEvent(editModel.Id); _service.ReleaseNumber(e.NumberSid); }
public ActionResult Edit(EditEventModel editModel) { var oldEvent = GetEvent(editModel.Id); var editEvent = new EditEventView(); var evt = MapEditEventModel(oldEvent,editModel); if (oldEvent.Number != editModel.Number) { evt.NumberSid = _service.ProcureNumber(evt.Number); ReleaseOldNumber(editModel); } using (var trans =_session.BeginTransaction()) { _session.Update(evt); trans.Commit(); } ViewData["timezone"] = _timezoneHydration.GetAndSetSelectedTimezone(evt.Timezone); editEvent.Message = "The event has been updated."; editEvent.Event = ConvertToEventJsonView(evt); return View(editEvent); }