public IHttpActionResult UnregisterPost(int eventId, int memberId)
        {
            var status = EventRepository.RemoveParticipant(eventId, memberId);

            if (status == EventStatus.Unregistered)
            {
                var currentMember       = Members.GetById(memberId);
                var currentMappedMember = ContextService.MembershipHelper.MapMember(currentMember);
                currentMappedMember.MemberField = string.Empty;
                var eventPage = CodeFirstHelper.TypedContent <EventPageModel>(eventId);

                // Remove any scheduled mails for this event and member.
                Mailer.RemoveScheduleNotifyEventStart(currentMappedMember, eventPage);
            }

            return(Json(status));
        }
        public IHttpActionResult BuildStatePost(int eventId, int?memberId = null)
        {
            var eventPage = CodeFirstHelper.TypedContent <EventPageModel>(eventId);
            var payload   = new EventStatePayload();

            if (memberId.HasValue && memberId.Value != -1)
            {
                var participating = eventPage.Participants.FirstOrDefault(x => x.Id == memberId.Value);
                payload.IsParticipating = participating != null;
            }

            DateTime eventDate;

            if (eventPage.StartDate.HasValue)
            {
                eventDate = new DateTime(eventPage.StartDate.Value.Year, eventPage.StartDate.Value.Month, eventPage.StartDate.Value.Day, eventPage.StartDate.Value.Hour, eventPage.StartDate.Value.Minute, eventPage.StartDate.Value.Second);
            }
            else
            {
                // We have no start date mark this as closed.
                payload.Closed        = true;
                payload.CanUnregister = false;

                return(Json(payload));
            }

            // Closing un-registrations ?
            if (eventDate < DateTime.Now)
            {
                // Course closed
                payload.Closed = true;
            }

            var stopRegistrations = eventDate.AddHours(-48);

            if (stopRegistrations < DateTime.Now)
            {
                payload.CanUnregister = false;
            }
            else
            {
                payload.CanUnregister = true;
            }

            return(Json(payload));
        }
        public IHttpActionResult RegisterPost(int eventId, int memberId)
        {
            var status = EventRepository.AddParticipant(eventId, memberId);

            if (status == EventStatus.Registered)
            {
                var currentMember = Members.GetById(memberId);
                var eventPage     = CodeFirstHelper.TypedContent <EventPageModel>(eventId);

                var currentMappedMember = ContextService.MembershipHelper.MapMember(currentMember);
                Mailer.SendNotifyEventApplied(currentMappedMember, eventPage); // Notify the member who applied.

                foreach (var activity in eventPage.EventActivities)
                {
                    // Create a qued email close to this event's start date.
                    Mailer.ScheduleSendNotifyEventStart(currentMappedMember, eventPage, activity);
                }
            }

            return(Json(status));
        }