public Customer CreateCustomer(Customer customer) { var customer2add = _pac.Customers.Add(customer).Entity; _pac.SaveChanges(); return(customer2add); }
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); }
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); }
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(); }