public async Task <IActionResult> UpdateVolunteerType(int id, string volunteerType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var volunteer = await _context.Volunteers.FindAsync(id); if (volunteer == null) { return(BadRequest("Specified Volunteer does not exist.")); } VolunteerType parsedVolunteerType; var validVolunteerType = Enum.TryParse(volunteerType, false, out parsedVolunteerType); if (!validVolunteerType || !Enum.IsDefined(typeof(VolunteerType), parsedVolunteerType)) { return(BadRequest("Invalid VolunteerType specified.")); } volunteer.VolunteerType = parsedVolunteerType; _context.Update(volunteer); await _context.SaveChangesAsync(); return(Json(volunteer)); }
public async Task <IActionResult> UpdateContactPerson(int id, [FromBody] int volunteerId) { Volunteer contactPerson = await _context.Volunteers.Where(v => v.Id == volunteerId).FirstOrDefaultAsync(); if (contactPerson == null) { return(BadRequest("No Volunteer exist with the specified id.")); } var team = await _context.Teams.FindAsync(id); if (team == null) { return(BadRequest("No Team exist with the specified id.")); } team.ContactPerson = contactPerson; _context.Update(team); await _context.SaveChangesAsync(); return(Json(team)); }
public void RefreshIdentifications() { lock (lockObject) { foreach (Volunteer v in _context.Volunteers) { var identification = _context.Identifications.Where(i => i.Id == v.IdentificationId).Single(); if (v.VolunteerType.Equals(VolunteerType.PASSIVE)) { identification.Active = false; } else { identification.Active = true; } v.Identification.LastUpdatedTs = DateTime.Now; _context.Update(identification); } _context.SaveChanges(); } }