public Task DiscardChanges() { foreach (DbEntityEntry entry in _context.ChangeTracker.Entries()) { entry.State = EntityState.Unchanged; } _context.SaveChanges(); return(Task.CompletedTask); }
public ActionResult Create(Contact contact, HttpPostedFileBase file) { if (ModelState.IsValid) { //_db.Contacts.Add(contact); var contact2 = new Contact { FirstName = contact.FirstName, LastName = contact.LastName, EmailAddress = contact.EmailAddress, PhoneNumber = contact.PhoneNumber, BirthDate = contact.BirthDate, Comments = contact.Comments, Id = contact.Id }; // Save picture to a file on the server. if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Content/images"), pic); // Upload file to server. file.SaveAs(path); contact2.PicturePath = path; } _db.Contacts.Add(contact2); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public Contact AddContact(Contact contact) { _context.Contacts.Add(contact); _context.SaveChanges(); return(contact); }