public virtual async Task <ActionResult> Event(IndexViewModel model) { if (ModelState.IsValid) { var newEvent = await RaceDayClient.AddEvent( model.EventForm.EventName.Trim(), model.EventForm.EventDate, (model.EventForm.EventUrl != null ? model.EventForm.EventUrl.Trim() : null), (model.EventForm.EventLocation != null ? model.EventForm.EventLocation.Trim() : null), (model.EventForm.EventDescription != null ? model.EventForm.EventDescription.Trim() : null), RaceDayUser.CurrentUser.UserId ); if (newEvent != null) { await RaceDayClient.AddUserToEvent(newEvent.eventinfo.EventId); // redisplay new list positioning on the added event // return(Redirect(VirtualPathUtility.ToAppRelative("~/") + "#e" + newEvent.eventinfo.EventId.ToString())); } else { model.PageMessage = new PageMessageModel(MessageDismissEnum.close, CssMessageClassEnum.error, "Unable to create event"); } } return(View(MVC.Home.Views.Index, model)); }
public virtual async Task <ActionResult> Attending(String EventId, String ClassName) { // Event Id must be an integer and found // Int32 eventId = 0; if (!Int32.TryParse(EventId, out eventId)) { eventId = 0; } if (eventId == 0) { return(new HttpStatusCodeResult(400, "Invalid event Id")); } // ClassName must be recognized // if ((ClassName != "glyphicon-check") && (ClassName != "glyphicon-unchecked")) { return(new HttpStatusCodeResult(400, "Unrecognized class name")); } EventDetail eventDetail; // Switch the attendance // AttendanceResult result = new AttendanceResult(); if (ClassName == "glyphicon-check") { await RaceDayClient.RemoveUserFromEvent(eventId); eventDetail = await RaceDayClient.GetEventDetail(eventId); result.Button = RenderPartialViewToString(MVC.Shared.Views.Partials._NotAttendingButton, EventInfo.CopyFromEventService(false, eventDetail)); } else { await RaceDayClient.AddUserToEvent(eventId); eventDetail = await RaceDayClient.GetEventDetail(eventId); result.Button = RenderPartialViewToString(MVC.Shared.Views.Partials._AttendingButton, EventInfo.CopyFromEventService(true, eventDetail)); } // Rebind the participant list with the change // List <EventParticipant> participants = new List <EventParticipant>(); foreach (var user in eventDetail.attendees) { participants.Add(EventParticipant.FromJson(user)); } result.Attendees = RenderPartialViewToString(MVC.Shared.Views.Partials._ParticipantList, participants); return(Json(result)); }