public async Task <WatchedRecordDto> UpdateWatchedRecordAsync(Guid domainId, UpdateWatchedRecordData data) { var domain = await _domainsService.GetDomainAsync(domainId); var record = domain.WatchedRecords .FirstOrDefault(e => e.Id == data.Id) ?? throw new NotFoundException($"WatchedRecord with id {data.Id} not found in WatchedDomain with id {domainId}."); _mapper.Map(data, record); var rowsChanged = await _context.SaveChangesAsync(); if (rowsChanged > 0) { // delete results as they are not valid anymore var results = await _context.RecordServerResults .Where(e => e.WatchedRecordId == record.Id) .ToListAsync(); _context.RecordServerResults .RemoveRange(results); await _context.SaveChangesAsync(); } return(_mapper.Map <WatchedRecordDto>(record)); }
public Task <WatchedRecordDto> UpdateWatchedRecord(Guid domainId, Guid id, UpdateWatchedRecordData data) { if (id != data.Id) { throw new BadDataException(ErrorCode.IdsDontMatch); } return(_recordsService.UpdateWatchedRecordAsync(domainId, data)); }