public bool AddNewPhoneAndMessage(PhoneModel phone) { Phone newPhone = new Phone(); newPhone.Name = phone.Name; newPhone.PhoneNumber = phone.PhoneNumber; newPhone.Surname = phone.Surname; context.Add(newPhone); Message msg = new Message(); msg.PhoneId = newPhone.Id; msg.Text = phone.Message; msg.Date = DateTime.Now; context.Add(msg); context.SaveChanges(); return(true); }
public async Task <IActionResult> Create([Bind("Id,Libelle")] UserRole userRole) { if (ModelState.IsValid) { _context.Add(userRole); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userRole)); }
public async Task <IActionResult> Create([Bind("Id,CreationDate,Content,IsCoupDeCoeur")] Publication publication) { if (ModelState.IsValid) { _context.Add(publication); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(publication)); }
public async Task <IActionResult> Create([Bind("Id,Name,Point,WinDate")] Team team) { if (ModelState.IsValid) { _context.Add(team); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(team)); }
public async Task <IActionResult> Create([Bind("Id,Name,XAxis,YAxis,IsActive,IsObsolete")] Checkpoint checkpoint) { if (ModelState.IsValid) { _context.Add(checkpoint); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(checkpoint)); }
public async Task <IActionResult> Create([Bind("Id,Path,PublicationId")] Photo photo) { if (ModelState.IsValid) { _context.Add(photo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PublicationId"] = new SelectList(_context.Publication, "Id", "Content", photo.PublicationId); return(View(photo)); }
public void IfChangesImmediatelyAccessible() { var context = new EfContext(); var newSuperBlog = new Article() { }; context.Add(newSuperBlog); //before saveChanges data is not accessible for query context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("Id,NickName,IsActive,CanPublish,Resign,UserRoleId")] SuperUser superUser) { if (ModelState.IsValid) { _context.Add(superUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserRoleId"] = new SelectList(_context.UserRole, "Id", "Libelle", superUser.UserRoleId); return(View(superUser)); }
public static void ReadCSVFile(string filePath) { string[] resultSet = File.ReadAllLines(filePath); using (var context = new EfContext()) { foreach (var data in resultSet) { WeatherData tmpInfo = new WeatherData(); string[] tmpString = data.Split(","); tmpInfo.DateAndTime = DateTime.Parse(tmpString[0]); tmpInfo.Location = tmpString[1]; tmpInfo.Temp = decimal.Parse(tmpString[2], CultureInfo.InvariantCulture); tmpInfo.Humidity = int.Parse(tmpString[3], CultureInfo.InvariantCulture); context.Add(tmpInfo); } context.SaveChanges(); } }
public static void ReadCSVFile(string filePath) { //Samlar alla rader i filen till en sträng-array. string[] resultSet = File.ReadAllLines(filePath); using (var context = new EfContext()) { //loopar alla poster i tabellen, tolkar datatyperna och sätter värdet på alla fällt för alla poster. foreach (var data in resultSet) { WeatherData wdInfo = new WeatherData(); string[] wdString = data.Split(","); wdInfo.DateAndTime = DateTime.Parse(wdString[0]); wdInfo.Location = wdString[1]; wdInfo.Temp = decimal.Parse(wdString[2], CultureInfo.InvariantCulture); wdInfo.Humidity = int.Parse(wdString[3], CultureInfo.InvariantCulture); //lägg till posterna till tabelln i databasen. context.Add(wdInfo); } //sparar ändringar i databasen. context.SaveChanges(); } }
internal TestData() { using (EfContext con = new EfContext(_conf)) { if (con.Database.Exists()) { con.Database.Delete(); } con.Database.Create(); Product p1 = new Product() { Name = "Testanlage" }; Product p2 = new Product() { Name = "A2017-0000" }; Product p3 = new Product() { Name = "A2017-0001" }; Product p4 = new Product() { Name = "A2017-0002" }; Product p5 = new Product() { Name = "A2090-0000" }; con.Add(p1); con.Add(p2); con.Add(p3); con.Add(p4); con.Add(p5); con.Complete(); Customer c1 = new Customer() { Name = "GmbH 1", Products = new List <Product>() { p2, p3 } }; Customer c2 = new Customer(); c2.Name = "GmbH 2"; Customer c3 = new Customer() { Name = "GmbH 3", Products = new List <Product>() { p4 } }; Customer c4 = new Customer() { Name = "GmbH 4" }; Customer c5 = new Customer() { Name = "Intern", Products = new List <Product>() { p1 } }; p2.Owner = c1; p3.Owner = c1; p4.Owner = c3; p1.Owner = c5; con.Add(c1); con.Add(c2); con.Add(c3); con.Add(c4); con.Add(c5); con.Complete(); } }
public void EfContextTests_CRUD_Customer() { using (TestData td = new TestData()) { Customer c1 = new Customer() { Name = "GmbH Test" }; string newName = "Tested"; using (EfContext con = new EfContext(new TestConfig())) { con.Set <Customer>().Add(c1); con.SaveChanges(); } using (EfContext con = new EfContext(new TestConfig())) { Customer loaded = con.Set <Customer>().Find(c1.Id); Assert.IsNotNull(loaded); Assert.AreEqual(c1.Name, loaded.Name); loaded.Name = newName; con.SaveChanges(); } using (EfContext con = new EfContext(new TestConfig())) { Customer loaded = con.Set <Customer>().Find(c1.Id); Assert.AreEqual(loaded.Name, newName); con.Set <Customer>().Remove(loaded); con.SaveChanges(); } using (EfContext con = new EfContext(new TestConfig())) { Customer loaded = con.Set <Customer>().Find(c1.Id); Assert.IsNull(loaded); } } using (EfContext con = new EfContext(new TestConfig())) { if (con.Database.Exists()) { con.Database.Delete(); } con.Database.Create(); Product p1 = new Product() { Name = "Testanlage" }; Product p2 = new Product() { Name = "A2017-0000" }; Product p3 = new Product() { Name = "A2017-0001" }; Product p4 = new Product() { Name = "A2017-0002" }; Product p5 = new Product() { Name = "A2090-0000" }; con.Add(p1); con.Add(p2); con.Add(p3); con.Add(p4); con.Add(p5); con.Complete(); Customer c1 = new Customer(); c1.Name = "GmbH 1"; c1.Products = new List <Product>() { p2, p3 }; Customer c2 = new Customer(); c2.Name = "GmbH 2"; Customer c3 = new Customer(); c3.Name = "GmbH 3"; c3.Products = new List <Product>() { p4 }; Customer c4 = new Customer(); c4.Name = "GmbH 4"; Customer c5 = new Customer(); c5.Name = "Intern"; c5.Products = new List <Product>() { p1 }; p2.Owner = c1; p3.Owner = c1; p4.Owner = c3; p1.Owner = c5; con.Add(c1); con.Add(c2); con.Add(c3); con.Add(c4); con.Add(c5); con.Complete(); } }
public void Add(T entity) { _context.Add(entity); }