private void button2_Click(object sender, EventArgs e) { authors = new List <Author>(); authors = Variables.AuthorDataSource; int CountResponse = 0; AuthorDataLayer objDataLayer = new AuthorDataLayer(); if (authors.Count > 0) { foreach (var author in authors) { if (author != null) { int Result = objDataLayer.SaveAuthors(author); if (Result == 1) { CountResponse++; } } } } if (CountResponse == authors.Count) { MessageBox.Show("Data saved to database"); } else { MessageBox.Show("Some error occured,This may occured due to the duplicate entires,Data saved partially.Please check your database for ensure data saved as expected"); } }
public void Upsert(Book item) { BookDataLayer.ShallowUpsert(item); foreach (var dbAuthor in item.Authors) { AuthorDataLayer.ShallowUpsert(dbAuthor); } }
public void Add(Book item) { item.Id = default; BookDataLayer.Add(item); foreach (var dbAuthor in item.Authors) { AuthorDataLayer.ShallowUpsert(dbAuthor); } }
public List <Author> LoopWebSiteWithXpath(IWebDriver driver, DataGridView dataUrls, DataTable dt) { List <Author> outPutAuthors = new List <Author>(); foreach (DataGridViewRow row in dataUrls.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (cell.Value.ToString() != " ") { driver.Navigate().GoToUrl(string.Format(Variables.BaseUrl, cell.Value.ToString())); // driver.Navigate().GoToUrl(cell.Value.ToString()); string AuthorTextXPath = "//*[@id='authDetailsNameSection']/div/div[1]/div[1]/h2"; string UniversityTextXPath = "//*[@id='authDetailsNameSection']/div/div[1]/div[1]/div[1]"; string hindexTextXpath = "//*[@id='authorDetailsHindex']/div/div[2]/span"; string DocumentTextXpath = "//*[@id='authorDetailsDocumentsByAuthor']/div/div[2]/span"; /** Find the element **/ IWebElement h3Element = driver.FindElement(By.XPath(AuthorTextXPath)); IWebElement UniversityElement = driver.FindElement(By.XPath(UniversityTextXPath)); IWebElement hindexElement = driver.FindElement(By.XPath(hindexTextXpath)); IWebElement DocumentElement = driver.FindElement(By.XPath(DocumentTextXpath)); /** Grab the text **/ string AuthorName = h3Element.Text; string Univerisity = UniversityElement.Text; string Hindex = "h-index: " + hindexElement.Text; string DocumentName = "Documents: " + DocumentElement.Text; //driver.Close(); //driver.Dispose(); // PopulateRows(AuthorName, Univerisity, Hindex, DocumentName); dt.Rows.Add(AuthorName, Univerisity, Hindex, DocumentName, "NIl"); Author author = new Author { AuthorName = AuthorName, DocumentName = DocumentName, Hindex = Hindex, University = Univerisity }; AuthorDataLayer onbjAuthorDataLayer = new AuthorDataLayer(); onbjAuthorDataLayer.SaveAuthors(author); outPutAuthors.Add(author); } } } return(outPutAuthors); }
public void Update(Book item) { if (item.Id == default) { throw new ArgumentException("It's impossible to update item without id"); } BookDataLayer.ShallowUpdate(item); foreach (var dbAuthor in item.Authors) { AuthorDataLayer.ShallowUpsert(dbAuthor); } }