public async Task <ActionResult <ScheduleDto> > createSchedule(UserSchoolDto userSchoolDto) { try { var user = await _volunteerRepo.GetUserWithID(userSchoolDto.userid); if (user == null) { return(BadRequest($"user with id {userSchoolDto.userid} not found")); } var schoolx = await _schoolRepo.GetSchoolWithID(userSchoolDto.schoolid); if (schoolx == null) { return(BadRequest($"School with id {userSchoolDto.schoolid} not found")); } var dayOfWeekx = await _scheduleRepo.GetDayOfWeek(userSchoolDto.dayoftheweek); if (dayOfWeekx == null) { Dayofweek dw = new Dayofweek() { Id = userSchoolDto.dayoftheweek }; _scheduleRepo.Add(dw); await _scheduleRepo.SaveAll(); } var dayw = userSchoolDto.dayoftheweek; Outreachschedule schedulex = new Outreachschedule() { School = schoolx, ApplicationUser = user, DayofweekId = dayw, starttime = userSchoolDto.startime, endtime = userSchoolDto.endtime, comments = userSchoolDto.comments, classize = userSchoolDto.classize }; _scheduleRepo.Add(schedulex); var result = await _scheduleRepo.SaveAll(); var schedulexToReturn = _mapper.Map <ScheduleDto>(schedulex); return(Ok(schedulexToReturn)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message)); } }
public async Task <ActionResult <TeamDto> > addVolunteerToTeam(UsertoteamDto usertoteamDto) { try { var teamx = await _teamRepo.GetTeam(usertoteamDto.teamid); var userx = await _volunteerRepo.GetUserWithID(usertoteamDto.userid); teamx.Volunteer.Add(userx); var result = await _teamRepo.SaveAll(); var teamxToReturn = _mapper.Map <TeamDto>(teamx); return(Ok(teamxToReturn)); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "db no good")); } }
public async Task <ActionResult <SchoolDto> > addPersonnelToSchool(PersonnelToSchoolDto personnelToSchoolDto) { try { var schoolx = await _schoolRepo.GetSchoolWithID(personnelToSchoolDto.schoolid); var userx = await _volunteerRepo.GetUserWithID(personnelToSchoolDto.personnelid); schoolx.SchoolPersonnel.Add(userx); var result = await _schoolRepo.SaveAll(); var schoolxToReturn = _mapper.Map <SchoolDto>(schoolx); return(Ok(schoolxToReturn)); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "db no good")); } }