public CustomerRepository() { Mapper.CreateMap<DomainModels.Customer, Customer>(); Mapper.CreateMap<Customer, DomainModels.Customer>(); DbContext context = new RETAILContext(); DbContextAdapter contextAdaptor = new DbContextAdapter(context); IObjectSetFactory objectSetFactory = contextAdaptor; _repository = new Repository<Customer>(objectSetFactory); IObjectContext objectContext = contextAdaptor; _uow = new UnitOfWork(objectContext); }
public void DeleteCustomersByAddress(string address) { using (RETAILContext context = new RETAILContext()) { List<Customer> entities = context.Customers.AsQueryable().Where(c => c.Address == address).ToList(); foreach (var entity in entities) { context.Set<Customer>().Remove(entity); } context.SaveChanges(); } }
public List<DomainModels.Customer> GetCustomersByAddress(string address) { using (RETAILContext context = new RETAILContext()) { List<Customer> entities = context.Customers.AsQueryable().Where(c => c.Address == address).ToList(); List<DomainModels.Customer> customers = new List<DomainModels.Customer>(); foreach (var entity in entities) { DomainModels.Customer customer = Mapper.Map<Customer, DomainModels.Customer>(entity); customers.Add(customer); } return customers; } }
public void DeleteAllCustomers() { using (RETAILContext context = new RETAILContext()) { List<Customer> entities = context.Customers.AsQueryable().ToList(); foreach (var entity in entities) { context.Set<Customer>().Remove(entity); } context.SaveChanges(); //context.ExecuteStoreCommand("TRUNCATE TABLE [RETAIL].[STORE].[Customer]"); } }
public void InsertCustomer(DomainModels.Customer customer) { using (RETAILContext context = new RETAILContext()) { Customer entity = Mapper.Map<DomainModels.Customer, Customer>(customer); context.Customers.Add(entity); context.SaveChanges(); customer.Id = entity.Id; } }
public void UpdateCustomer(DomainModels.Customer customer) { using (RETAILContext context = new RETAILContext()) { Customer entity = context.Customers.AsQueryable().Single(c => c.Id == customer.Id); entity.Name = customer.Name; entity.Address = customer.Address; entity.Phone = customer.Phone; context.SaveChanges(); } }