public async Task <ActionResult> Event(string CalendarId, string EventId) { var calenRep = new CalendarRepository(); CalendarEventParam calendar = new CalendarEventParam(); calendar.calendar_id = CalendarId; calendar.event_id = EventId; return(View(calenRep.GetEvent(calendar))); }
public async Task <IActionResult> EventEdit(EventModel eventModel) { var user = await userManager.GetUserAsync(User); CalendarRepository repo = new CalendarRepository(configModel.ConnectionString); EventModel dbEvent; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Validate that the required fields (name and date) are filled out. // Note that in C#, DateTimes are never null, so instead of checking for null, we check for DateTime.MinValue, which is the // default value that ASP.NET's model binding will provide if the date is not included in the API call. if (eventModel.Date == DateTime.MinValue || String.IsNullOrEmpty(eventModel.Name)) { return(Utilities.ErrorJson("The event must have both a name and a date")); } if (eventModel.Id == 0) { return(Utilities.ErrorJson("Must specify an event to edit")); } // If the description is null, set it to an empty string instead just to avoid nulls in the database if (String.IsNullOrEmpty(eventModel.Description)) { eventModel.Description = ""; } // Get the existing event in the database dbEvent = repo.GetEvent(eventModel.Id); // Check that the event to be edited actually exists if (dbEvent == null) { return(Utilities.ErrorJson("Specified event does not exist")); } // Update the event in the database try { repo.UpdateEvent(eventModel); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "" })); }
public async Task <IActionResult> CancelEvent(EventViewModel eventViewModel) { int eventId = eventViewModel.eventId; var user = await userManager.GetUserAsync(User); VolunteerRepository volRepo = new VolunteerRepository(configModel.ConnectionString); CalendarRepository repo = new CalendarRepository(configModel.ConnectionString); VolunteerModel volunteer; EventModel eventModel; EventSignupModel signup; // Ensure that ONLY volunteer, volunteer captain, and bus driver accounts have access to this API endpoint if (user == null || !(await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Volunteer.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.VolunteerCaptain.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusDriver.ToString()))) { return(Utilities.ErrorJson("Event signup is available only to volunteers, volunteer captains, and bus drivers")); } volunteer = volRepo.GetVolunteer(user.VolunteerId); if (volunteer == null) { return(Utilities.ErrorJson("Unable to find volunteer profile")); } eventModel = repo.GetEvent(eventId); // Verify that the specified event exists if (eventModel == null) { return(Utilities.ErrorJson("Specified event does not exist.")); } // Check if there is already a record of this user having signed up signup = repo.GetEventSignup(eventId, volunteer.Id); if (signup == null) { // If no record exists of the user signing up, or they have already cancelled, then let them know return(Utilities.ErrorJson("You are not signed up for this event")); } else { // Otherwise, update the record to indicate non-attendance repo.DeleteEventSignup(eventId, volunteer.Id); } return(new JsonResult(new { Error = "" })); }
public CalendarEventParam GetEvent([FromBody] CalendarEventParam calendar) { CalendarRepository calen = new CalendarRepository(); return(calen.GetEvent(calendar)); }