public List <House> GetAllHouses() { using (var db = new PersonPetHouseContext()) { var listOfHouses = db.Houses.ToList(); return(listOfHouses); } }
public House GetHouseById(int houseId) { using (var db = new PersonPetHouseContext()) { var house = db.Houses.FirstOrDefault(x => x.Id == houseId); return(house); } }
public void CreatePerson(Person person) { using (var db = new PersonPetHouseContext()) { db.Persons.Add(person); db.SaveChanges(); } }
public Pet GetPetById(int petId) { using (var db = new PersonPetHouseContext()) { var petToFind = db.Pets.FirstOrDefault(x => x.Id == petId); return(petToFind); } }
public List <Pet> GetAllPets() { using (var db = new PersonPetHouseContext()) { var listOfPets = db.Pets.ToList(); return(listOfPets); } }
public House CreateHouse(House house) { using (var db = new PersonPetHouseContext()) { db.Add(house); db.SaveChanges(); return(house); } }
public House DeleteHouseById(int houseId) { using (var db = new PersonPetHouseContext()) { var houseToDelete = db.Houses.FirstOrDefault(x => x.Id == houseId); db.Houses.Remove(houseToDelete); db.SaveChanges(); return(houseToDelete); } }
public bool Login(string email, string password) { using var db = new PersonPetHouseContext(); var personByEmail = db.Persons.FirstOrDefault(person => person.Email == email); if (personByEmail.Password == password) { return(true); } return(false); }
public List <Pet> GetMyPets(int personId) { using var db = new PersonPetHouseContext(); // get person, join the pets //var personWithPets = db.Persons.Include(x => x.Pets).FirstOrDefault(x => x.Id == personId); //return personWithPets.Pets; // haal alle pets met de juiste personid op var listOfPets = db.Pets.Where(x => x.PersonId == personId).ToList(); return(listOfPets); }
public Pet ChangeOwner(int petId, int newOwnerId) { using (var db = new PersonPetHouseContext()) { var petToChange = db.Pets.FirstOrDefault(p => p.Id == petId); var newPetOwner = db.Persons.FirstOrDefault(p => p.Id == newOwnerId); petToChange.Person = newPetOwner; db.Pets.Update(petToChange); db.SaveChanges(); return(petToChange); } }
public Pet UpdatePetById(int petId, Pet petEditValues) { using (var db = new PersonPetHouseContext()) { var petToUpdate = db.Pets.FirstOrDefault(x => x.Id == petId); petToUpdate.Name = petEditValues.Name; petToUpdate.Type = petEditValues.Type; petToUpdate.DateOfBirth = petEditValues.DateOfBirth; db.Pets.Update(petToUpdate); db.SaveChanges(); return(petToUpdate); } }
public House UpdateHouseById(int houseId, House houseEditValues) { using (var db = new PersonPetHouseContext()) { var houseToUpdate = db.Houses.FirstOrDefault(x => x.Id == houseId); houseToUpdate.Street = houseEditValues.Street; houseToUpdate.Number = houseEditValues.Number; houseToUpdate.PostalCode = houseEditValues.PostalCode; houseToUpdate.Community = houseEditValues.Community; db.Houses.Update(houseToUpdate); db.SaveChanges(); return(houseToUpdate); } }
public List <House> GetAllHousesByPostal(string postalCode) { using (var db = new PersonPetHouseContext()) { List <House> listOfHouses = new List <House>(); foreach (var house in db.Houses) { if (house.PostalCode == postalCode) { listOfHouses.Add(house); } } return(listOfHouses); } }
public void DeletePerson(int id, string email, string currentPassword) { using var db = new PersonPetHouseContext(); var currentUserByEmailAndPwAndId = db.Persons .FirstOrDefault(x => x.Email == email && x.Password == currentPassword && x.Id == id); if (currentUserByEmailAndPwAndId != null) { db.Persons.Remove(currentUserByEmailAndPwAndId); db.SaveChanges(); } else { throw new UnauthorizedAccessException("invalid email and/or currentpassword and/or id"); } }
public void ChangePassword(string email, string currentPassword, string newPassword) { using var db = new PersonPetHouseContext(); var currentUserByEmailAndPw = db.Persons.FirstOrDefault(x => x.Email == email && x.Password == currentPassword); if (currentUserByEmailAndPw != null) { currentUserByEmailAndPw.Password = newPassword; db.Persons.Update(currentUserByEmailAndPw); db.SaveChanges(); } else { throw new UnauthorizedAccessException("invalid email and/or currentpassword"); } }
public void DeletePetById(int petId) { using (var db = new PersonPetHouseContext()) { var petToDelete = db.Pets.FirstOrDefault(x => x.Id == petId); if (petToDelete != null) { db.Pets.Remove(petToDelete); db.SaveChanges(); } else { throw new UnauthorizedAccessException("invalid pet id"); } } }