public void UpdateCategory(Category category) { using (var context = new FBContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
//</inheritdoc> public override void Edit(T entityModel) { try { using (var context = new FBContext()) { context.Entry(entityModel).State = EntityState.Modified; context.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
//</inheritdoc> public override void Delete(T model) { try { using (var context = new FBContext()) { var _dbset = context.Set <T>(); _dbset.Attach(model); context.Entry(model).State = EntityState.Deleted; context.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void RunAutomation() { driver = new ChromeDriver(Directory.GetCurrentDirectory(), option); driver.Url = ConfigurationManager.AppSettings["GroupPage"]; driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20); IList <IWebElement> allElements = driver.FindElements(By.XPath(".//span")); string value = driver.FindElement(By.XPath(".//span[contains(text(), 'Członkowie: ')]")).Text; value = value.Substring(value.Length - 4, 4); IList <IWebElement> record; listOfUsers = driver.FindElement(By.TagName("div")); record = listOfUsers.FindElements(By.CssSelector("div[data-visualcompletion='ignore-dynamic']")); int numberOfRecords = Convert.ToInt32(value); do { try { IJavaScriptExecutor js = (IJavaScriptExecutor)driver; js.ExecuteScript("window.scrollBy(0,document.body.scrollHeight)"); record = listOfUsers.FindElements(By.TagName("div[data-visualcompletion='ignore-dynamic']")); } catch { //Console.WriteLine("Brak rozszerzonej listy"); } Actions hover = new Actions(driver); IWebElement person = record[index]; hover.MoveToElement(person); hover.Perform(); try { string nameValue = person.FindElement(By.CssSelector("a")).GetAttribute("aria-label"); string idValue = person.FindElement(By.CssSelector("a")).GetAttribute("href"); if (!string.IsNullOrEmpty(nameValue)) { FirstName = nameValue.Substring(0, nameValue.IndexOf(" ")); LastName = nameValue.Substring(nameValue.IndexOf(" ") + 1, (nameValue.Length - FirstName.Length - 1)); Console.WriteLine(index + " " + FirstName + " " + LastName); } if (!string.IsNullOrEmpty(idValue)) { var start = idValue.IndexOf("user") + 5; id = idValue.Substring(start, idValue.Length - start - 1); } if (!string.IsNullOrEmpty(nameValue) && !string.IsNullOrEmpty(idValue)) { using (var context = new FBContext()) { User user = new User(); user.FirstName = FirstName; user.LastName = LastName; user.FbID = id; user.ContactInitiated = false; user.PageLiked = false; user.IsFriend = false; user.SharedInfo = false; if (context.Users.Any(e => e.FbID == id)) { context.Entry(user).State = EntityState.Modified; } else { context.Entry(user).State = EntityState.Added; } context.SaveChanges(); } } } catch (Exception ex) { // Console.WriteLine(ex.ToString()); } index++; } while (index < numberOfRecords); driver.Quit(); }