static void Main(string[] args) { try { Infrastructure.MongoMappings.Initialize(); var repo = Injection.Resolve<SiteRepository>(); var site = new Domain.Site(); site.Name = "This is a test site"; site.AddDomain(new DomainName("www.helloworld.com")); repo.AddSite(site); var site2 = new Domain.Site(); site2.Name = "This is a test site"; site2.AddDomain(new DomainName("www.helloworld.com")); repo.AddSite(site2); //var existing = repo.FindById(site.Id); var existing = repo.GetSiteByDomain(new DomainName("www.helloworld.com")); repo.RemoveSite(site); repo.RemoveSite(site2); } catch (SpecificationException ex) { Console.WriteLine("Broken specification: " + ex.Message); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void SaveSite(Site site) { //generic save site rules var uniqueRule = new DomainNameIsUniqueToSiteRule(); if (uniqueRule.IsSatisfiedBy(this, site)) repo.Save(site); else throw new SiteDomainIsAlreadyTakenFailure(uniqueRule.CausedByDomain, site); }
public SiteDomainIsAlreadyTakenFailure(DomainName domain, Site site) : base(string.Format("Failed to create site [{1}] because the domain name [{0}] is already taken by another site.", site, domain)) { }
public void UpdateSite(Site site) { //can perform any modify only business rules SaveSite(site); }
public void RemoveSite(Site site) { repo.Delete(site.Id); }
public void AddSite(Site site) { //can perform any new site business rules SaveSite(site); }