public async Task <IActionResult> CancelGroup(GroupCancelViewModel vm) { var user = await userManager.GetUserAsync(User); CalendarRepository repo = new CalendarRepository(configModel.ConnectionString); // 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")); } // Check that all inputs were provided if (vm.Date == DateTime.MinValue) { return(Utilities.ErrorJson("Must provide a date")); } if (vm.GroupId == 0) { return(Utilities.ErrorJson("Must provide a group ID")); } // Check if the group is actually signed up on this date if (!repo.CheckGroupSignup(vm.Date, vm.GroupId)) { return(Utilities.ErrorJson("This group is not signed up on this date.")); } // Delete the record of having signed up from the database try { repo.DeleteGroupSignup(vm.Date, vm.GroupId); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "" })); }