Ejemplo n.º 1
0
        //
        // GET: /Demo/
        public ActionResult Index()
        {
            var db = new NorthwindDbContext();
            var customers = db.Customers.ToList();

            return View(customers);
        }
Ejemplo n.º 2
0
 public IEnumerable<Order> Get()
 {
     using (var dbContext = new NorthwindDbContext())
     {
         return (from o in dbContext.Orders select o).ToList();
     }
 }        
Ejemplo n.º 3
0
 public Product Get(int id)
 {
     using (var dbContext = new NorthwindDbContext())
     {
         return (from p in dbContext.Products where p.ProductID == id select p).FirstOrDefault();
     }
 }
 public IEnumerable<Supplier> Get()
 {
     using (var dbContext = new NorthwindDbContext())
     {
         return dbContext.Suppliers.ToList();
     }
 }
 public IEnumerable<Category> Get()
 {
     using (var dbContext = new NorthwindDbContext())
     {
         return dbContext.Categories.ToList();
     }
 }
Ejemplo n.º 6
0
 public IEnumerable<Order> Get(int id)
 {
     using (var dbContext = new NorthwindDbContext())
     {
         return (from o in dbContext.Orders where o.OrderID == id select o).ToList();
     }
 }
Ejemplo n.º 7
0
        public IEnumerable<Product> Get()
        {
            try
            {
                using (var dbContext = new NorthwindDbContext())
                {
                    return dbContext.Products.ToList();
                }
            }
            catch (Exception exception)
            {
                new LogEvent(exception.Message).Raise();
            }

            return new List<Product>();
        }
Ejemplo n.º 8
0
        public HttpResponseMessage GetOrdersForCustomer(string customerId)
        {
            try
            {
                using (var dbContext = new NorthwindDbContext())
                {
                    var orders = (from o in dbContext.Orders.Include("OrderDetails") where o.CustomerID == customerId select o).ToList();

                    return Request.CreateResponse(HttpStatusCode.OK, orders);
                }
            }
            catch (Exception exception)
            {
                new LogEvent(exception.Message).Raise();
            }

            return new HttpResponseMessage(HttpStatusCode.InternalServerError);
        }
Ejemplo n.º 9
0
        //const string CustomersKey = "_Customers";
        //const string EmployeesKey = "_Employees";
        //const string ShippersKey = "_Shippers";
        //const string ProductIDKey = "_ProductID";

        public NorthwindDAL(NorthwindDbContext injectedContext, IMemoryCache memoryCache, ILogger <HomeController> logger)
        {
            _db     = injectedContext;
            _cache  = memoryCache;
            _logger = logger;
        }
Ejemplo n.º 10
0
 public OrderRepository(NorthwindDbContext northwindDbContext) : base(northwindDbContext)
 {
 }
Ejemplo n.º 11
0
 public GetProductQueryHandler(NorthwindDbContext context, IMapper mapper, ILogger <GetProductQueryHandler> logger)
 {
     this._mapper    = mapper;
     this._logger    = logger;
     this._dbContext = context;
 }
Ejemplo n.º 12
0
 public DefaultEditionsCreator(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 13
0
 public EFTest(ITestOutputHelper testOutputHelper)
 {
     _testOutputHelper   = testOutputHelper;
     _northwindDbContext = new NorthwindDbContext();
 }
        private List <Order> CreateTestOrders(NorthwindDbContext context)
        {
            // Create test entities
            var category1 = new Category
            {
                CategoryName = "Test Category 1"
            };
            var category2 = new Category
            {
                CategoryName = "Test Category 2"
            };
            var product1 = new Product
            {
                ProductName = "Test Product 1",
                UnitPrice   = 10M,
                Category    = category1
            };
            var product2 = new Product
            {
                ProductName = "Test Product 2",
                UnitPrice   = 20M,
                Category    = category2
            };
            var product3 = new Product
            {
                ProductName = "Test Product 3",
                UnitPrice   = 30M,
                Category    = category2
            };
            var customer1 = context.Customers
                            .Include(c => c.Territory)
                            .Include(c => c.CustomerSetting)
                            .Single(c => c.CustomerId == TestCustomerId1);
            var customer2 = context.Customers
                            .Include(c => c.Territory)
                            .Include(c => c.CustomerSetting)
                            .Single(c => c.CustomerId == TestCustomerId1);
            var detail1 = new OrderDetail {
                Product = product1, Quantity = 11, UnitPrice = 11M
            };
            var detail2 = new OrderDetail {
                Product = product2, Quantity = 12, UnitPrice = 12M
            };
            var detail3 = new OrderDetail {
                Product = product2, Quantity = 13, UnitPrice = 13M
            };
            var detail4 = new OrderDetail {
                Product = product3, Quantity = 14, UnitPrice = 14M
            };
            var order1 = new Order
            {
                OrderDate    = DateTime.Today,
                Customer     = customer1,
                OrderDetails = new List <OrderDetail>
                {
                    detail1,
                    detail2,
                }
            };
            var order2 = new Order
            {
                OrderDate    = DateTime.Today,
                Customer     = customer2,
                OrderDetails = new List <OrderDetail>
                {
                    detail3,
                    detail4,
                }
            };

            // Persist entities
            context.Orders.Add(order1);
            context.Orders.Add(order2);
            context.SaveChanges();

            // Detach entities
            var objContext = ((IObjectContextAdapter)context).ObjectContext;

            objContext.Detach(order1);
            objContext.Detach(order2);

            // Clear reference properties
            product1.Category         = null;
            product2.Category         = null;
            product3.Category         = null;
            customer1.Territory       = null;
            customer2.Territory       = null;
            customer1.CustomerSetting = null;
            customer2.CustomerSetting = null;
            detail1.Product           = null;
            detail2.Product           = null;
            detail3.Product           = null;
            detail4.Product           = null;
            order1.OrderDetails       = new List <OrderDetail> {
                detail1, detail2
            };
            order2.OrderDetails = new List <OrderDetail> {
                detail3, detail4
            };

            // Return orders
            return(new List <Order> {
                order1, order2
            });
        }
 public NorthwindData(NorthwindDbContext context)
 {
     this.context = context;
 }
 // TODO: Всегда ли класс должен требовать зависимости через конструктор или, например, в данном
 // случае логичнее будет, чтобы он сам создал себе провайдер элементов ?
 public EmployeesManager(NorthwindDbContext context, IItemsProvider <Employees> employeesProvider)
 {
     _context     = context;
     _empProvider = employeesProvider;
 }
Ejemplo n.º 17
0
 protected override void Seed(NorthwindDbContext context)
 {
 }
 public CreateRoomCommandHandler(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 19
0
 public WebApiFixture()
 {
     systemUnderTest    = SystemUnderTest.ForStartup <Tests.Startup>();
     northWindDbContext = (NorthwindDbContext)systemUnderTest.Services.GetService(typeof(NorthwindDbContext));
     mapper             = (IMapper)systemUnderTest.Services.GetService(typeof(IMapper));
 }
Ejemplo n.º 20
0
 public CustomersController(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 21
0
 public EmployeeController(NorthwindDbContext northwindDbContext) => _northwindDbContext = northwindDbContext;
Ejemplo n.º 22
0
 public EmployeesWithManagersQueryHandler(NorthwindDbContext context)
 {
     _context = context;
 }
 public EmployeeController(NorthwindDbContext db)
 {
     this.db = db;
 }
 public PublisherNavigationPropertiesSynchronizer(GameStoreDbContext gameStoreDbContext,
                                                  NorthwindDbContext northwindDbContext)
 {
     _gameStoreDbContext = gameStoreDbContext;
     _northwindDbContext = northwindDbContext;
 }
Ejemplo n.º 25
0
 public OrdersViewComponent(NorthwindDbContext context)
 {
     _context = context;
 }
 public UpdateCustomerCommandHandler(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 27
0
 public HomeController(NorthwindDbContext context, ICompositeViewEngine compositeViewEngine) : base(compositeViewEngine)
 {
     _context = context;
 }
 public DeleteProductCommandHandler(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 29
0
 public GetCustomersListQueryHandlerTests(QueryTestFixture fixture)
 {
     _context = fixture.Context;
     _mapper  = fixture.Mapper;
 }
        private List <Employee> CreateTestEmployees(NorthwindDbContext context)
        {
            // Create test entities
            var area1 = new Area {
                AreaName = "Northern"
            };
            var area2 = new Area {
                AreaName = "Southern"
            };
            var territory1 = context.Territories.Single(t => t.TerritoryId == TestTerritoryId1);
            var territory2 = context.Territories.Single(t => t.TerritoryId == TestTerritoryId2);
            var territory3 = context.Territories.Single(t => t.TerritoryId == TestTerritoryId3);

            territory1.Area = area1;
            territory2.Area = area2;
            territory3.Area = area2;
            var employee1 = new Employee
            {
                FirstName   = "Test",
                LastName    = "Employee1",
                City        = "San Fransicso",
                Country     = "USA",
                Territories = new List <Territory> {
                    territory1, territory2
                }
            };
            var employee2 = new Employee
            {
                FirstName   = "Test",
                LastName    = "Employee2",
                City        = "Sacramento",
                Country     = "USA",
                Territories = new List <Territory> {
                    territory2, territory3
                }
            };

            // Persist entities
            context.Employees.Add(employee1);
            context.Employees.Add(employee2);
            context.SaveChanges();

            // Detach entities
            var objContext = ((IObjectContextAdapter)context).ObjectContext;

            objContext.Detach(employee1);
            objContext.Detach(employee2);

            // Clear reference properties
            territory1.Area       = null;
            territory2.Area       = null;
            territory3.Area       = null;
            employee1.Territories = new List <Territory> {
                territory1, territory2
            };
            employee2.Territories = new List <Territory> {
                territory2, territory3
            };

            // Return employees
            return(new List <Employee> {
                employee1, employee2
            });
        }
Ejemplo n.º 31
0
 public NorthwindRepository(NorthwindDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 32
0
 public CommandTestBase()
 {
     _context = NorthwindContextFactory.Create();
 }
Ejemplo n.º 33
0
 public EntityFrameworkRepository(NorthwindDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 34
0
 public SuppliersController(NorthwindDbContext context)
 {
     _context = context;
 }
        private readonly INotificationService _notificationService; // Usage shown in CreateRoomCommandHandler

        public UpdateRoomCommandHandler(NorthwindDbContext context, INotificationService notificationService)
        {
            _context             = context;
            _notificationService = notificationService;
        }
Ejemplo n.º 36
0
 public UnitTest1()
 {
     this.db = new NorthwindDbContext();
 }
Ejemplo n.º 37
0
 public GetCustomersListQueryHandler(NorthwindDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public SampleDataController(NorthwindDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 39
0
 public VoteGameCommandHandler(NorthwindDbContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }