simplified quality fixed some broken tests

This commit is contained in:
Keivan 2011-02-03 11:47:51 -08:00
commit ca27c75df5
10 changed files with 47 additions and 89 deletions

View file

@ -18,61 +18,31 @@ namespace NzbDrone.Core.Providers
#region IQualityProvider Members
public void AddProfile(QualityProfile profile, List<AllowedQuality> allowedQualities)
public void Add(QualityProfile profile)
{
var profileId = _sonicRepo.Add(profile);
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = (int)profileId;
_sonicRepo.Add<AllowedQuality>(allowed);
}
_sonicRepo.Add(profile);
}
public void UpdateProfile(QualityProfile profile, List<AllowedQuality> allowedQualities)
public void Update(QualityProfile profile)
{
if (!_sonicRepo.Exists<QualityProfile>(q => q.ProfileId == profile.ProfileId))
{
//Log Error
throw new NotImplementedException();
throw new InvalidOperationException("Unable to update none existing profile");
}
_sonicRepo.Update<QualityProfile>(profile);
//Check to see if any items in the DB do not exist in this list
//Check to see if any of the allowedQualities already exist, if so update, else add
foreach (var inDb in _sonicRepo.All<AllowedQuality>().Where(q => q.ProfileId == profile.ProfileId))
{
if (!allowedQualities.Exists(l => l.ProfileId == inDb.ProfileId && l.Quality == inDb.Quality))
_sonicRepo.Delete<AllowedQuality>(inDb.Id);
}
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = profile.ProfileId;
if (!_sonicRepo.Exists<AllowedQuality>(q => q.ProfileId == profile.ProfileId && q.Quality == allowed.Quality))
_sonicRepo.Add(allowed);
else
_sonicRepo.Update(allowed);
}
_sonicRepo.Update(profile);
}
public void RemoveProfile(int profileId)
public void Delete(int profileId)
{
_sonicRepo.DeleteMany<AllowedQuality>(q => q.ProfileId == profileId);
_sonicRepo.Delete<QualityProfile>(profileId);
}
public List<QualityProfile> GetProfiles()
public List<QualityProfile> GetAllProfiles()
{
var profiles = _sonicRepo.All<QualityProfile>().ToList();
foreach (var profile in profiles)
{
profile.AllowedQualities = _sonicRepo.Find<AllowedQuality>(q => q.ProfileId == profile.ProfileId).ToList();
}
return profiles;
}