public IPackage Create(string name) { var cleaned = _stringHelper.Clean(name); if (string.IsNullOrWhiteSpace(cleaned)) { throw new ArgumentNullException(nameof(name)); } if (Exists(name)) { throw new ArgumentException("Package already exists"); } var retval = new Package(); var entity = new PackageEntity { Name = cleaned }; _databaseContext.Packages.Add(entity); _databaseContext.SaveChanges(); retval.Id = entity.Id; retval.Name = entity.Name; return(retval); }
public IPackageNotificationTarget Create(PackageNotificationType type, string value) { var cleaned = _stringHelper.Clean(value); if (string.IsNullOrWhiteSpace(cleaned)) { throw new ArgumentNullException(nameof(value)); } if (Exists(type, value)) { throw new ArgumentException("Package Notification Target already exists"); } var entity = new PackageNotificationTargetEntity { Type = type, Value = cleaned }; _databaseContext.PackageNotificationTargets.Add(entity); _databaseContext.SaveChanges(); return(new PackageNotificationTarget { Id = entity.Id, Type = entity.Type, Value = entity.Value }); }
public bool Exists(string package, PackageNotificationType type, string value) { var cleaned = _stringHelper.Clean(value); var cleanedPackage = _stringHelper.Clean(package); if (string.IsNullOrWhiteSpace(cleaned) || string.IsNullOrWhiteSpace(cleanedPackage)) { return(false); } return(_databaseContext.PackageNotifications.Any(pn => pn.Package.Name.Equals(cleanedPackage) && pn.Target.Type == type && pn.Target.Value.Equals(cleaned))); }