public bool Update(IConnectionHandler connectionHandler, WebSite webSite, List <WebSiteAlias> webSiteAliases) { if (!this.Update(connectionHandler, webSite)) { throw new Exception("خطا در ثبت اطلاعات"); } var homaAliasBo = new WebSiteAliasBO(); var list = homaAliasBo.Where(connectionHandler, x => x.WebSiteId == webSite.Id); foreach (var homaAliase in webSiteAliases) { var homaAlias = homaAliasBo.Get(connectionHandler, homaAliase.Id); if (homaAlias == null) { homaAliase.WebSiteId = webSite.Id; homaAliase.WebSite = webSite; if (!homaAliasBo.Insert(connectionHandler, homaAliase)) { throw new Exception("خطا در ثبت اطلاعات"); } } else { homaAliase.WebSite = webSite; if (!homaAliasBo.Update(connectionHandler, homaAliase)) { throw new Exception("خطا در ثبت اطلاعات"); } } } foreach (var homaAliase in list) { if (webSiteAliases.Any(x => x.Id == homaAliase.Id)) { continue; } if (!homaAliasBo.Delete(connectionHandler, homaAliase.Id)) { throw new Exception("خطا در ثبت اطلاعات"); } } return(true); }
public bool Insert(IConnectionHandler connectionHandler, WebSite webSite, List <WebSiteAlias> webSiteAliases) { if (!this.Insert(connectionHandler, webSite)) { throw new Exception("خطا در ثبت اطلاعات"); } var homaAliasBo = new WebSiteAliasBO(); foreach (var homaAliase in webSiteAliases) { homaAliase.WebSiteId = webSite.Id; homaAliase.WebSite = webSite; if (!homaAliasBo.Insert(connectionHandler, homaAliase)) { throw new Exception("خطا در ثبت اطلاعات"); } } return(true); }