public Owner CreateOwner(Owner owner) { var newOwner = _ctx.Add(owner); _ctx.SaveChanges(); return(newOwner.Entity); }
public Pet UpdatePet(Pet pet) { _ctx.Attach(pet).State = EntityState.Modified; //_ctx.Entry(pet).Reference(p => p.Owner).IsModified = true; _ctx.SaveChanges(); return(pet); }
public Person Add(PersonInput person) { Person item; try { byte[] passwordHash, passwordSalt; CreatePasswordHash(person.Password, out passwordHash, out passwordSalt); Person newPerson = new Person { Username = person.Username, PasswordHash = passwordHash, PasswordSalt = passwordSalt, IsAdmin = person.IsAdmin, FirstName = person.FirstName, LastName = person.LastName, Address = _arep.GetById(person.Address.Id), Phone = person.Phone, Email = person.Email }; item = db.Persons.Add(newPerson).Entity; db.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding person: " + e.Message, e); } return item; }
public Owner UpdateOwner(Owner owner) { _ctx.Attach(owner).State = EntityState.Modified; //_ctx.Entry(owner).Reference(c => c.OwnedPets).IsModified = true; _ctx.SaveChanges(); return(owner); }
public Order Add(Order entity) { Order item; try { Order order = new Order { Customer = _psrep.GetById(entity.Customer.Id), Pets = entity.Pets, OrderDate = entity.OrderDate, Price = entity.Price }; item = db.Orders.Add(order).Entity; db.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding order: " + e.Message, e); } return(item); }
public ActionResult Editar(Produto p) { _context.Entry(p).State = EntityState.Modified; _context.SaveChanges(); TempData["msg"] = "Produto atualizado!"; return(RedirectToAction("Listar")); }
public Address Add(Address entity) { Address item; try { Address address = new Address { Street = entity.Street, Number = entity.Number, Letter = entity.Letter, Floor = entity.Floor, Side = entity.Side, ZipCode = entity.ZipCode, City = entity.City }; item = db.Addresses.Add(address).Entity; db.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding address: " + e.Message, e); } return(item); }
public Owner Create(Owner owner) { var ownerFromDB = _ctx.Owners.Add(owner).Entity; _ctx.SaveChanges(); return(ownerFromDB); }
public Owner CreateOwner(Owner owner) { Owner ownerToReturn = _context.Attach(owner).Entity; _context.SaveChanges(); return(ownerToReturn); }
public void CreatePet(Pet pet) { //_context.pets.Add(pet); //_context.SaveChanges(); _context.Attach(pet).State = EntityState.Added; _context.SaveChanges(); }
public ActionResult Cadastrar(Animal animal) { _context.Animais.Add(animal); //adiciona no "Banco" _context.SaveChanges(); TempData["msg"] = "Animal cadastrado!"; //mensagem enviada para a tela //faz redirect para não cadastrar vários no mesmo formulário após o F5 return(RedirectToAction("Cadastrar")); }
public ActionResult Deletar(int id) { Produto produto = _context.Produtos.Find(id); _context.Produtos.Remove(produto); _context.SaveChanges(); TempData["msg"] = "Removido!"; return(RedirectToAction("Listar")); }
public ActionResult Excluir(int id) { var animal = _context.Animais.Find(id); _context.Animais.Remove(animal); _context.SaveChanges(); TempData["msg"] = "Animal excluído"; return(RedirectToAction("Listar")); }
public Pet CreatePet(Pet pet) { _ctx.Attach(pet).State = EntityState.Added; _ctx.SaveChanges(); return(pet); /*var newPet = _ctx.Add(pet); * _ctx.SaveChanges(); * return newPet.Entity;*/ }
public ActionResult Cadastrar(Animal animal) { _context.Animais.Add(animal); _context.SaveChanges(); TempData["msg"] = "Cadastrado com sucesso"; return(RedirectToAction("Cadastrar")); }
public Customer CreateCustomer(Customer customer) { if (customer.Orders != null) { _ctx.Attach(customer.Orders); } var _customer = _ctx.Customers.Add(customer).Entity; _ctx.SaveChanges(); return(_customer); }
public Order CreateOrder(Order order) { if (order.Customer != null) { _ctx.Attach(order.Customer); } var newOrder = _ctx.Orders.Add(order).Entity; _ctx.SaveChanges(); return(newOrder); }
public ActionResult Excluir(int id) { //Busca o animal pelo código var animal = _context.Animais.Find(id); //Remove o animal do banco _context.Animais.Remove(animal); //Commit _context.SaveChanges(); //Mensagem de sucesso TempData["msg"] = "Animal excluido"; //Retorna para a lista return(RedirectToAction("Listar")); }
public Pet Create(Pet pet) { var pe = _ctx.Pets.Add(pet).Entity; _ctx.SaveChanges(); return(pe); }
public User Create(User t) { var user = _ctx.Users.Add(t).Entity; _ctx.SaveChanges(); return(user); }
public PetType CreatePetType(PetType petType) { var newType = _ctx.Add(petType); _ctx.SaveChanges(); return(newType.Entity); }
public void DeleteOwner(int id) { Owner delteOwner = _context.Remove(new Owner() { Id = id }).Entity; _context.SaveChanges(); }
public Pet Add(Pet pet) { Pet item; try { var entityEntry = _ctx.Attach(pet); entityEntry.State = EntityState.Added; item = entityEntry.Entity; _ctx.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding pet: " + e.Message, e); } return(item); }
public Colour Add(Colour entity) { Colour item; try { Colour colour = new Colour { Description = entity.Description }; item = db.Colours.Add(colour).Entity; db.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding colour: " + e.Message, e); } return(item); }
public PetType Add(PetType entity) { PetType item; try { PetType petType = new PetType { Type = entity.Type }; item = db.PetTypes.Add(petType).Entity; db.SaveChanges(); } catch (Exception e) { throw new RepositoryException("Error adding petType: " + e.Message, e); } return(item); }
// This method will create and seed the database. public static void Initialize(PetshopContext context) { // Delete the database, if it already exists. I do this because an // existing database may not be compatible with the entity model, // if the entity model was changed since the database was created. context.Database.EnsureDeleted(); // Create the database, if it does not already exists. This operation // is necessary, if you don't use an in-memory database. context.Database.EnsureCreated(); if (context.Addresses.Any()) { return; // DB has been seeded } List <Address> addresses = new List <Address> { new Address { Street = "Jensvej", Number = 5, Letter = null, Floor = null, Side = null, ZipCode = 6700, City = "Jensbjerg" }, new Address { Street = "Global Avenue", Number = 66, Letter = "b", Floor = null, Side = null, ZipCode = 3322, City = "Gaby" }, new Address { Street = "Vegtable Street", Number = 49, Letter = "V", Floor = 42, Side = "MF", ZipCode = 2743, City = "Salatary" } }; context.Addresses.AddRange(addresses); List <Colour> colours = new List <Colour> { new Colour { Description = "Black" }, new Colour { Description = "Orange" }, new Colour { Description = "Grey" }, new Colour { Description = "White" } }; context.Colours.AddRange(colours); List <PetType> petTypes = new List <PetType> { new PetType { Type = "Dog" }, new PetType { Type = "Cat" }, new PetType { Type = "Goat" }, new PetType { Type = "Dreadnought" } }; context.PetTypes.AddRange(petTypes); byte[] passwordHash, passwordSalt; CreatePasswordHash("1234", out passwordHash, out passwordSalt); List <Person> persons = new List <Person> { new Person { Username = "******", PasswordHash = passwordHash, PasswordSalt = passwordSalt, IsAdmin = false, FirstName = "Jens", LastName = "Jensen", Address = addresses[0], Phone = 536736, Email = "*****@*****.**" }, new Person { Username = "******", PasswordHash = passwordHash, PasswordSalt = passwordSalt, IsAdmin = false, FirstName = "John", LastName = "Smith", Address = addresses[1], Phone = 66666666, Email = "*****@*****.**" }, new Person { Username = "******", PasswordHash = passwordHash, PasswordSalt = passwordSalt, IsAdmin = true, FirstName = "Wonda Bonda", LastName = "Sonda", Address = addresses[2], Phone = 432589, Email = "*****@*****.**" }, }; context.Persons.AddRange(persons); List <Pet> pets = new List <Pet> { new Pet { Name = "Mortis", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[0].Id } }, Type = petTypes[3], PreviousOwner = persons[1], Price = 12000000.0 }, new Pet { Name = "Jaga", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[1].Id }, new PetColourRelation() { ColourId = colours[2].Id } }, Type = petTypes[2], PreviousOwner = persons[1], Price = 10.0 }, new Pet { Name = "Macauley", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[2].Id } }, Type = petTypes[2], PreviousOwner = persons[0], Price = 1300.0 }, new Pet { Name = "Leray", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[3].Id } }, Type = petTypes[1], PreviousOwner = persons[1], Price = 533 }, new Pet { Name = "Guy", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[2].Id }, new PetColourRelation() { ColourId = colours[1].Id } }, Type = petTypes[0], PreviousOwner = persons[2], Price = 153.53 }, new Pet { Name = "Fabia", BirthDate = new DateTime(), SoldDate = DateTime.Now, Colours = new List <PetColourRelation> { new PetColourRelation() { ColourId = colours[1].Id } }, Type = petTypes[0], PreviousOwner = persons[0], Price = 99333 }, }; context.Pets.AddRange(pets); Order order = new Order { Customer = persons[2], OrderDate = DateTime.Now, Price = 2000, Pets = new List <OrderPetRelation> { new OrderPetRelation { Pet = pets[0] } } }; context.Orders.AddRange(order); context.SaveChanges(); }
public void Add(User entity) { db.Users.Add(entity); db.SaveChanges(); }
public Owner Create(Owner owner) { context.Owners.Add(owner); context.SaveChanges(); return(owner); }
public Pet CreatePet(Pet pet) { Pet petToReturn = _context.Attach(pet).Entity; _context.SaveChanges(); return petToReturn; }
public void AddUser(User entity) { _ctx.Users.Add(entity); _ctx.SaveChanges(); }