public async Task <IActionResult> SetSystemSettings([FromBody] AgentAccommodationBookingSettings settings, [FromRoute] int agentId, [FromRoute] int agencyId) { var(_, isFailure, error) = await _systemSettingsManagementService.SetAvailabilitySearchSettings(agentId, agencyId, settings); if (isFailure) { return(BadRequest(ProblemDetailsBuilder.Build(error))); } return(Ok()); }
public static AgentAccommodationBookingSettingsInfo ToAgentAccommodationBookingSettingsInfo(this AgentAccommodationBookingSettings settings) => new ()
public async Task <Result> SetAvailabilitySearchSettings(int agentId, int agencyId, AgentAccommodationBookingSettings settings) { var doesRelationExist = await _context.AgentAgencyRelations .AnyAsync(r => r.AgentId == agentId || r.AgencyId == agencyId); if (!doesRelationExist) { return(Result.Failure("Could not find specified agent in given agency")); } var existingSettings = await _context.AgentSystemSettings.SingleOrDefaultAsync(s => s.AgentId == agentId && s.AgencyId == agencyId); if (existingSettings is null) { var newSettings = new AgentSystemSettings { AgencyId = agencyId, AgentId = agentId, AccommodationBookingSettings = settings }; _context.Add(newSettings); } else { existingSettings.AccommodationBookingSettings = settings; _context.Update(existingSettings); } await _context.SaveChangesAsync(); return(Result.Success()); }