public void Add(User entity) { db.Users.Add(entity); db.SaveChanges(); }
public User UpdateUser(User user) { _ctx.Entry(user).State = EntityState.Modified; _ctx.SaveChanges(); return(user); }
public bool Insert(PetCategory dto) { _context.PetCategory.Add(dto); return(_context.SaveChanges() != 0); }
public void SeedDb(PetShopContext ctx) { SeedOwners(ctx); ctx.SaveChanges(); }
public Owner Create(Owner owner) { _context.Owners.Attach(owner).State = EntityState.Added; _context.SaveChanges(); return(owner); }
public Pet AddPet(Pet pet) { _context.Attach(pet).State = EntityState.Added; _context.SaveChanges(); return(pet); }
public bool Delete(Favorite dto) { _context.Favorite.Remove(dto); return(_context.SaveChanges() != 0); }
public bool Insert(AccessoryTransactionRel dto) { _context.AccessoryTransactionRel.Add(dto); return(_context.SaveChanges() != 0); }
public static void SeedDB(PetShopContext ctx) { ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); var owner1 = ctx.Owners.Add(new Owner() { FirstName = "Lotte", LastName = "Tubæk", Address = "Rosenparken 53", Email = "*****@*****.**", PhoneNumber = "23313226" } ).Entity; var owner2 = ctx.Owners.Add(new Owner() { FirstName = "Mikael", LastName = "Fabrisous", Address = "Gammelmandvej 53", Email = "*****@*****.**", PhoneNumber = "2334334226" } ).Entity; var pet1 = ctx.Pets.Add(new Pet() { name = "Daniel", type = "Goat", color = "Ugly", price = 2400, previousOwner = owner1 }); var pet2 = ctx.Pets.Add(new Pet() { name = "Misser", type = "Hund", color = "Brun", price = 7699, previousOwner = owner2 }); string password = "******"; byte[] passwordHashJoe, passwordSaltJoe, passwordHashAnn, passwordSaltAnn; CreatePasswordHash(password, out passwordHashJoe, out passwordSaltJoe); CreatePasswordHash(password, out passwordHashAnn, out passwordSaltAnn); List <User> users = new List <User> { new User { Username = "******", PasswordHash = passwordHashJoe, PasswordSalt = passwordSaltJoe, IsAdmin = false }, new User { Username = "******", PasswordHash = passwordHashAnn, PasswordSalt = passwordSaltAnn, IsAdmin = true } }; ctx.Users.AddRange(users); ctx.SaveChanges(); }
public Pet Create(Pet pet) { _ctx.Attach(pet).State = EntityState.Added; _ctx.SaveChanges(); return(pet); }
/// <summary> /// Adds the owner to the DB. /// </summary> /// <param name="owner"></param> /// <returns>Owner with id given by DB.</returns> public Owner CreateOwner(Owner owner) { _ctx.Attach(owner).State = EntityState.Added; _ctx.SaveChanges(); return(owner); }
public static void Seed(PetShopContext ctx) { Pet pet1 = new Pet { name = "Rex", type = PetTypes.Dog, birthDate = new DateTime(2017, 4, 20), soldDate = new DateTime(2017, 6, 25), color = "Brownish", price = 275, ownersHistory = new List <PetOwner>() }; Pet pet2 = new Pet { name = "Spoofy", type = PetTypes.Cat, birthDate = new DateTime(2018, 3, 10), soldDate = new DateTime(2018, 3, 30), color = "White and black", price = 550, ownersHistory = new List <PetOwner>() }; Owner owner1 = new Owner { firstName = "Simon", lastName = "Kjær", address = "Stengårdsvej 12", petHistory = new List <PetOwner>() }; Owner owner2 = new Owner { firstName = "Levis", lastName = "Kjongaard", address = "Hjertingvej 5", petHistory = new List <PetOwner>() }; owner1 = ctx.Owners.Add(owner1).Entity; owner2 = ctx.Owners.Add(owner2).Entity; PetOwner PetOwner1 = new PetOwner { Owner = owner1 }; PetOwner PetOwner2 = new PetOwner { Owner = owner2 }; PetOwner PetOwner3 = new PetOwner { Owner = owner1 }; pet1.ownersHistory.Add(PetOwner1); pet1.ownersHistory.Add(PetOwner2); pet2.ownersHistory.Add(PetOwner3); ctx.Pets.Add(pet1); ctx.Pets.Add(pet2); ctx.SaveChanges(); }
public void Add(User entity) { _ctx.Users.Add(entity); _ctx.SaveChanges(); }
public void UpdateUser(User user) { _ctx.Attach(user).State = EntityState.Modified; _ctx.SaveChanges(); }
public void CreatePet(Pet pet) { _ctx.Add(pet); _ctx.SaveChanges(); }
public ActionResult Create([Bind(Include = "Name,Price,Description,Volume")] Item item, string Animal, string Brand, string Subcategory, string Category) { if (String.IsNullOrEmpty(Animal) || String.IsNullOrEmpty(Brand) || String.IsNullOrEmpty(Subcategory) || String.IsNullOrEmpty(Animal) || String.IsNullOrEmpty(item.Name) || String.IsNullOrEmpty(item.Description) || (item.Price == null) || String.IsNullOrEmpty(item.Volume)) { ModelState.AddModelError(String.Empty, "Values can't be null"); } if (ModelState.IsValid) { var animal = db.Animals.Where(a => a.Name == Animal).FirstOrDefault(); if (animal == null) { animal = db.Animals.Add(new Models.Animal() { Name = Animal, CreatedOn = DateTime.UtcNow }); db.SaveChanges(); } var brand = db.Brands.Where(a => a.Name == Brand).FirstOrDefault(); if (brand == null) { brand = db.Brands.Add(new Models.Brand() { Name = Brand, CreatedOn = DateTime.UtcNow }); db.SaveChanges(); } var category = db.ItemCategories.Where(a => a.Name == Category).FirstOrDefault(); if (category == null) { category = db.ItemCategories.Add(new Models.ItemCategory() { Name = Category, CreatedOn = DateTime.UtcNow }); db.SaveChanges(); } var subcategory = db.ItemSubcategories.Where(a => a.Name == Subcategory).FirstOrDefault(); if (subcategory == null) { subcategory = db.ItemSubcategories.Add(new Models.ItemSubcategory() { Name = Category, CreatedOn = DateTime.UtcNow, ItemCategory = category }); db.SaveChanges(); } item.Animal = animal; item.Brand = brand; item.ItemSubcategory = subcategory; item.CreatedOn = DateTime.UtcNow; db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Animals = db.Animals.Select(a => a.Name).ToList(); ViewBag.Brands = db.Brands.Select(a => a.Name).ToList(); ViewBag.ItemSubcategories = db.ItemSubcategories.Select(a => a.Name).ToList(); ViewBag.Itemcategories = db.ItemCategories.Select(a => a.Name).ToList(); return(View(item)); }
public void CreateOwner(Owner owner) { _ctx.Add(owner); _ctx.SaveChanges(); }
public void Create(User user) { _ctx.Users.Attach(user).State = EntityState.Added; _ctx.SaveChanges(); }
public Color Create(Color color) { _ctx.Colors.Attach(color).State = EntityState.Added; _ctx.SaveChanges(); return(color); }
public void AddUser(User entity) { _context.Users.Add(entity); _context.SaveChanges(); }
public Pet CreateNewPetRepo(Pet newPet) { _ctx.Attach(newPet).State = EntityState.Added; _ctx.SaveChanges(); return(newPet); }
public Owner CreateOwner(Owner owner) { _ctx.Add(owner); _ctx.SaveChanges(); return(owner); }
static void Main() { PetShopContext context = new PetShopContext(); context.SaveChanges(); }
public User Add(User entity) { db.Users.Add(entity); db.SaveChanges(); return(entity); }
public void Edit(User entity) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); }
public bool Insert(AccessoryCategory dto) { _context.AccessoryCategory.Add(dto); return(_context.SaveChanges() != 0); }
public Pet CreatePet(Pet pet) { _ctx.Add(pet); _ctx.SaveChanges(); return(pet); }