public void ApproveMember(int id, ServiceModel.MemberApprovalViewModel viewModel) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToJson().ToString())); } //get team var team = GetTeam(id); var authorizer = team.Members.FirstOrDefault(tm => tm.UserId == viewModel.StatusChangedByUserId); if (authorizer == null || (authorizer.Role != DomainModel.TeamUserRole.Administrator && team.OwnerId != authorizer.UserId)) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Forbidden, "Only team owners, and admins can approve members.")); } var teamMember = team.Members.FirstOrDefault(t => t.UserId == viewModel.UserId); if (teamMember == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "Invalid Team Member")); } teamMember.Status = DomainModel.TeamUserStatus.Approved; context.SaveChanges(); emailService.ApprovedForTeam(teamMember.User, team).Send(); }