public async Task <Result> SetDisplayedPaymentOptions(int agencyId, DisplayedPaymentOptionsSettings settings) { return(await CheckAgencyExists(agencyId) .Bind(SetSettings)); async Task <Result> SetSettings() { var existingSettings = await _context.AgencySystemSettings.SingleOrDefaultAsync(s => s.AgencyId == agencyId); if (existingSettings == default) { var newSettings = new AgencySystemSettings { AgencyId = agencyId, DisplayedPaymentOptions = settings }; _context.AgencySystemSettings.Add(newSettings); } else { existingSettings.DisplayedPaymentOptions = settings; _context.Update(existingSettings); } await _context.SaveChangesAsync(); return(Result.Success()); } }
public async Task <IActionResult> SetDisplayedPaymentOptions([FromBody] DisplayedPaymentOptionsSettings settings, [FromRoute] int agencyId) => NoContentOrBadRequest(await _systemSettingsManagementService.SetDisplayedPaymentOptions(agencyId, settings));