private VolunteerInfo GenerateOrganizerVolunteerInfo(int codeCampId) { var registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId); if (registration == null) { RegistrationDataAccess.CreateItem(new RegistrationInfo() { CodeCampId = codeCampId, IsRegistered = true, Notes = "Registered automatically by Volunteer view.", RegistrationDate = DateTime.Now, ShirtSize = "XL", UserId = UserInfo.UserID }); registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId); } VolunteerDataAccess.CreateItem(new VolunteerInfo() { CodeCampId = codeCampId, Notes = "Automatically generated by the Volunteer view.", RegistrationId = registration.RegistrationId }); return(VolunteerDataAccess.GetItemByRegistrationId(registration.RegistrationId, codeCampId)); }
public HttpResponseMessage GetVolunteerByRegistrationId(int registrationId, int codeCampId) { try { var volunteer = VolunteerDataAccess.GetItemByRegistrationId(registrationId, codeCampId); if (volunteer != null) { LoadSupplementalProperties(ref volunteer); } var response = new ServiceResponse <VolunteerInfo> { Content = volunteer }; if (volunteer == null && (UserInfo.IsSuperUser || UserInfo.IsInRole(PortalSettings.AdministratorRoleName) || ModulePermissionController.HasModulePermission(ActiveModule.ModulePermissions, "Edit"))) { // automatically make superusers, admins, and editors a volunteer response.Content = GenerateOrganizerVolunteerInfo(codeCampId); } else if (volunteer == null) { ServiceResponseHelper <VolunteerInfo> .AddNoneFoundError("volunteer", ref response); } return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }
public HttpResponseMessage CreateVolunteer(VolunteerInfo volunteer) { try { VolunteerDataAccess.CreateItem(volunteer); var savedVolunteer = VolunteerDataAccess.GetItemByRegistrationId(volunteer.RegistrationId, volunteer.CodeCampId); var response = new ServiceResponse <VolunteerInfo> { Content = savedVolunteer }; return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }