コード例 #1
0
        public EApplication Create(EApplication entity)
        {
            var addedApplication = _context.EApplications.Add(entity);

            _context.SaveChanges();
            return(addedApplication.Entity);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
        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();
            }
        }