Saturday, March 1, 2014

beginnings of an Entity Framework repository

using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluffyNothing.Core.Interfaces.DatabaseIntegration;
using FluffyNothing.Core.Objects;
namespace FluffyNothing.Infrastructure.DatabaseIntegration
{
   public class PersonRepository : IPersonRepository
   {
      public void AddPerson(Person person)
      {
         using (var db = new PersonContext())
         {
            db.People.Add(person);
            db.SaveChanges();
         }
      }
      
      public List<Person> GetPersons()
      {
         using (var db = new PersonContext())
         {
            var people = from person in db.People
                      select person;
            return people.ToList();
         }
      }
      
      public List<Person> GetPersons(string email)
      {
         using (var db = new PersonContext())
         {
            var people = from person in db.People
                      where person.Email.Equals(email)
                      select person;
            return people.ToList();
         }
      }
      
      public List<Person> GetPersons(string email, string password)
      {
         using (var db = new PersonContext())
         {
            var people = from person in db.People
                      where person.Email.Equals(email) && person.Password.Equals(password)
                      select person;
            return people.ToList();
         }
      }
      
      public void UpdatePerson(Person person)
      {
         using (var db = new PersonContext())
         {
            db.Entry(person).State = EntityState.Modified;
            db.SaveChanges();
         }
      }
   }
}

No comments:

Post a Comment