Exemplo n.º 1
0
        public Owner CreateOwner(Owner owner)
        {
            var newOwner = _ctx.Add(owner);

            _ctx.SaveChanges();
            return(newOwner.Entity);
        }
Exemplo n.º 2
0
 public Pet UpdatePet(Pet pet)
 {
     _ctx.Attach(pet).State = EntityState.Modified;
     //_ctx.Entry(pet).Reference(p => p.Owner).IsModified = true;
     _ctx.SaveChanges();
     return(pet);
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
 public Owner UpdateOwner(Owner owner)
 {
     _ctx.Attach(owner).State = EntityState.Modified;
     //_ctx.Entry(owner).Reference(c => c.OwnedPets).IsModified = true;
     _ctx.SaveChanges();
     return(owner);
 }
Exemplo n.º 5
0
        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"));
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 11
0
 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"));
        }
Exemplo n.º 13
0
        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"));
        }
Exemplo n.º 14
0
        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;*/
        }
Exemplo n.º 15
0
        public ActionResult Cadastrar(Animal animal)
        {
            _context.Animais.Add(animal);

            _context.SaveChanges();

            TempData["msg"] = "Cadastrado com sucesso";

            return(RedirectToAction("Cadastrar"));
        }
Exemplo n.º 16
0
        public Customer CreateCustomer(Customer customer)
        {
            if (customer.Orders != null)
            {
                _ctx.Attach(customer.Orders);
            }
            var _customer = _ctx.Customers.Add(customer).Entity;

            _ctx.SaveChanges();
            return(_customer);
        }
Exemplo n.º 17
0
        public Order CreateOrder(Order order)
        {
            if (order.Customer != null)
            {
                _ctx.Attach(order.Customer);
            }

            var newOrder = _ctx.Orders.Add(order).Entity;

            _ctx.SaveChanges();
            return(newOrder);
        }
Exemplo n.º 18
0
        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"));
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        // 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();
        }
Exemplo n.º 27
0
 public void Add(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
 }
 public Owner Create(Owner owner)
 {
     context.Owners.Add(owner);
     context.SaveChanges();
     return(owner);
 }
Exemplo n.º 29
0
 public Pet CreatePet(Pet pet)
 {
     Pet petToReturn = _context.Attach(pet).Entity;
     _context.SaveChanges();
     return petToReturn;
 }
Exemplo n.º 30
0
 public void AddUser(User entity)
 {
     _ctx.Users.Add(entity);
     _ctx.SaveChanges();
 }