// GET: /Event/Create
        public ActionResult Create(DateTime startDate)
        {
            var eventFormModel = new EventFormModel();
            eventFormModel.StartDate = eventFormModel.EndDate = startDate;
            PopulateEventDropDowns(eventFormModel);

            return PartialView("Create", eventFormModel);
        }
        public ActionResult Create(EventFormModel eventFormModel)
        {
            PopulateEventDropDowns(eventFormModel);

            if (ModelState.IsValid)
            {
                var rosterMembershipUser = (RosterMembershipUser) Membership.GetUser();
                var domainUser =
                    AutoMapper.Mapper.Map<RosterMembershipUser, User>(rosterMembershipUser);
                var venue = RavenSession.Load<Venue>(eventFormModel.VenueId);
                var newEvent = new CalendarBooking(eventFormModel.StartDate, eventFormModel.EndDate, domainUser.Id,venue);

                foreach (var staffmember in eventFormModel.SelectedStaff)
                {
                    var user = RavenSession.Load<User>(staffmember);
                    newEvent.AddStaff(user);
                }

                RavenSession.Store(newEvent);
                RavenSession.SaveChanges();
                var regevents = CurrentEditSession.RegisteredEvents;
            }
            ModelState.Clear();
            var day = new DateTime(eventFormModel.StartDate.Year, eventFormModel.StartDate.Month,
                                   eventFormModel.StartDate.Day);

            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid)
                    return Json(new {
                        FormattedDate = eventFormModel.StartDate.YmdFormat(),
                        StartDate = day.ToString(CultureInfo.InvariantCulture),
                        EndDate = day.AddDays(1).ToString(CultureInfo.InvariantCulture)
                    });
                return PartialView("Create", eventFormModel);
            }
            return RedirectToAction("Index", "Home");
        }
 private void PopulateEventDropDowns(EventFormModel eventFormModel)
 {
     eventFormModel.SetStaffList(
         AutoMapper.Mapper.Map<IEnumerable<User>, IEnumerable<RosterMembershipUser>>(
             RavenSession.Query<User>().ToList()));
     eventFormModel.SetVenuesList(
         AutoMapper.Mapper.Map<IEnumerable<Venue>, IEnumerable<VenueModel>>(
             RavenSession.Query<Venue>().ToList()));
 }