示例#1
0
        public Customer CreateCustomer(Customer customer)
        {
            var customer2add = _pac.Customers.Add(customer).Entity;

            _pac.SaveChanges();
            return(customer2add);
        }
示例#2
0
        public Owner CreateOwner(Owner owner)
        {
            var changeTracker = _pac.ChangeTracker.Entries <Pet>();

            if (owner.Pet != null)
            {
                _pac.Attach(owner.Pet);
            }
            var owner2add = _pac.Owners.Add(owner).Entity;

            _pac.SaveChanges();
            return(owner2add);
        }
示例#3
0
        public Pet CreatePet(Pet pet)
        {
            var changeTracker = _pac.ChangeTracker.Entries <Owner>();

            if (pet.Owner != null &&
                _pac.ChangeTracker.Entries <Owner>().FirstOrDefault(pe => pe.Entity.ID == pet.Owner.ID) == null)
            {
                _pac.Attach(pet.Owner);
            }
            var pet2Add = _pac.Pets.Add(pet).Entity;

            _pac.SaveChanges();

            return(pet2Add);
        }
示例#4
0
        public static void SeedDB(PetAppContext ctx)
        {
            //ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();


            List <TodoItem> items = new List <TodoItem>
            {
                new TodoItem {
                    IsComplete = true, Name = "Make homework"
                },
                new TodoItem {
                    IsComplete = false, Name = "Sleep"
                }
            };
            // Create two users with hashed and salted passwords
            string password = "******";

            byte[] passwordHashSusi, passwordSaltSusi, passwordHashSam, passwordSaltSam;
            CreatePasswordHash(password, out passwordHashSusi, out passwordSaltSusi);
            CreatePasswordHash(password, out passwordHashSam, out passwordSaltSam);


            var owner1 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Susana",
                LastName    = "Caparros",
                Address     = "MyHeart<3",
                PhoneNumber = 060606060,
                Email       = "*****@*****.**",
            }).Entity;
            var owner2 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Samuel",
                LastName    = "Caparros",
                Address     = "Doom",
                PhoneNumber = 123456789,
                Email       = "*****@*****.**",
            }).Entity;

            var pet1 = ctx.Pets.Add(new Pet()
            {
                Birthday = new DateTime(1997, 3, 18),
                Owner    = owner1,
                SoldDate = new DateTime(2016, 8, 26),
                Color    = "White",
                Race     = "Programmer",
                Type     = "Student",
                Price    = -4450
            }).Entity;

            var customer1 = ctx.Customers.Add(new Customer()
            {
                // ID = 1,
                FirstName    = "SamuelLDB",
                LastName     = "CaparrosLDB",
                Address      = "1234LDB",
                PasswordHash = passwordHashSam,
                PasswordSalt = passwordSaltSam,
                IsAdmin      = true
            }).Entity;
            var customer2 = ctx.Customers.Add(new Customer()
            {
                // ID = 1,
                FirstName    = "Susana",
                LastName     = "Caparros",
                Address      = "Malaga",
                PasswordHash = passwordHashSusi,
                PasswordSalt = passwordSaltSusi,
                IsAdmin      = true
            }).Entity;

            ctx.Customers.AddRange(customer1);
            ctx.SaveChanges();
        }