public EApplication Create(EApplication entity) { var addedApplication = _context.EApplications.Add(entity); _context.SaveChanges(); return(addedApplication.Entity); }
public ActionResult Create([Bind(Include = "Id,Name,Email,PhoneNumber,PhoneType")] Person person) { if (ModelState.IsValid) { db.People.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(person)); }
public PetsRepository(SimpleAppContext context) { _context = context; if (_context.Pets.Count() == 0) { _context.Pets.AddRange( new Pet { Name = "Opie", Breed = "Shih Tzu", PetType = PetType.Dog }, new Pet { Name = "Reggie", Breed = "Beagle", PetType = PetType.Dog }, new Pet { Name = "Diesel", Breed = "Bombay", PetType = PetType.Cat }, new Pet { Name = "Lucy", Breed = "Maine Coon", PetType = PetType.Cat }); _context.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Id,ModelName,Make,Year,PersonId")] Car car) { if (ModelState.IsValid) { db.Cars.Add(car); db.SaveChanges(); var owner = db.People.Find(car.PersonId); MailSender.Send("A new car has been created for you!", String.Format("<h2>{0}, A new car has been created for you!</h2>", owner.Name), new System.Net.Mail.MailAddress(owner.Email)); return(RedirectToAction("Index")); } ViewBag.PersonId = new SelectList(db.People, "Id", "Name", car.PersonId); return(View(car)); }
public void AddNewPerson(string name, string nickName, string tel) { using (var context = new SimpleAppContext()){ var newPerson = new PersonDto() { Name = name, NickName = nickName, TelephoneNumber = tel, }; context.Persons.Add(newPerson); context.SaveChanges(); } }
public ProductsRepository(SimpleAppContext context) { _context = context; if (_context.Products.Count() == 0) { _context.Products.AddRange( new Product { IsDiscontinued = true, Name = "Learning ASP.NET Core", Description = "A best-selling book covering the fundamentals of ASP.NET Core" }, new Product { Name = "Learning EF Core", Description = "A best-selling book covering the fundamentals of Entity Framework Core" }); _context.SaveChanges(); } }