コード例 #1
0
        public virtual Order GetFullOrder(string orderId)
        {
            try
            {
                var order =
                    OrderRepository.GetSingle(
                        x => x.Id.ToString().Equals(orderId, StringComparison.CurrentCultureIgnoreCase));

                order.OrderLines =
                    OrderLineRepository.GetList(
                        x => x.OrderId.ToString().Equals(orderId, StringComparison.CurrentCultureIgnoreCase));

                order.Currency = CurrencyRepository.GetSingle(x => x.Id.Equals(order.CurrencyId));

                order.User = UserRepository.GetSingle(x => x.Id.Equals(order.UserId));

                return(order);
            }
            catch (Exception ex)
            {
                Log("Error getting full order: GetFullOrder() Id:" + orderId + Environment.NewLine + ex.Message);
            }

            return(null);
        }
コード例 #2
0
 public OrderLineController(OrdersRepository ordrepo, OrderLineRepository olrepo, ProductRepository prorepo, InventoryRepository invrepo)
 {
     _ordersRepo    = ordrepo;
     _orderlineRepo = olrepo;
     _productRepo   = prorepo;
     _inventoryRepo = invrepo;
 }
コード例 #3
0
        public void Get_Returns_Order_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLineToAdd = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLineToAdd);

                context.SaveChanges();

                //Act
                var orderLine = orderLineRepository.Get(orderLineToAdd.Id);

                //Assert
                Assert.IsNotNull(orderLine);
            }
        }
コード例 #4
0
        public static OrderLineRepository GetOrderLineRepository(IUnitOfWork unitOfWork)
        {
            var repository = new OrderLineRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
コード例 #5
0
        public void Add_Returns_1_When_Adding_Valid_Order()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                //Act
                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLine = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLine);

                var result = context.SaveChanges();

                //Assert
                Assert.AreEqual(5, result); //Because we added five entities
            }
        }
コード例 #6
0
        public static OrderLineRepository GetOrderLineRepository()
        {
            var repository = new OrderLineRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
コード例 #7
0
ファイル: Facade.cs プロジェクト: Darwiish/MovieShopWeb
 public OrderLineRepository GetOrderLineRepository()
 {
     if (orderLineRepo == null)
     {
         orderLineRepo = new OrderLineRepository();
     }
     return orderLineRepo;
 }
コード例 #8
0
 internal PoSUnitOfWork(string connString)
 {
     _context       = new PoSContext(connString);
     _empRepo       = new EmployeeRepository(_context);
     _userRepo      = new UserRepository(_context);
     _productRepo   = new ProductRepository(_context);
     _orderRepo     = new OrderRepository(_context);
     _orderLineRepo = new OrderLineRepository(_context);
 }
コード例 #9
0
        private void GetCouponProperties(int couponId, out int usageLimit, out int actualUsage, out string couponCode)
        {
            var instances = CouponInstanceRepository.GetMany(x => x.CouponId == couponId).ToList();
            var ids       = instances.Select(i => i.Id).ToList();

            usageLimit  = instances.Any() ? (instances.Count == 1 ? instances[0].UsageLimit : instances.Count) : 0;
            couponCode  = instances.Any() ? (instances.Count == 1 ? instances[0].CouponCode : string.Empty) : string.Empty;
            actualUsage = instances.Any() ? OrderLineRepository.Count(x => x.CouponInstanceId != null && ids.Contains((int)x.CouponInstanceId)) : 0;
        }
 public PoSUnitOfWork(IPoSContext context)
 {
     _context       = context;
     _empRepo       = new EmployeeRepository(_context);
     _userRepo      = new UserRepository(_context);
     _productRepo   = new ProductRepository(_context);
     _orderRepo     = new OrderRepository(_context);
     _orderLineRepo = new OrderLineRepository(_context);
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: PeterAnckaert/VivesRental
        static IUnitOfWork CreateUnitOfWork(IVivesRentalDbContext context)
        {
            var productRepository   = new ProductRepository(context);
            var articleRepository   = new ArticleRepository(context);
            var orderRepository     = new OrderRepository(context);
            var orderLineRepository = new OrderLineRepository(context);
            var customerRepository  = new CustomerRepository(context);

            return(new UnitOfWork(context, productRepository, articleRepository, orderRepository, orderLineRepository, customerRepository));
        }
コード例 #12
0
        public ActionResult ProcessDCOrder(OrderViewModel _order)
        {
            IOrderRepository     OrderRepo     = new OrderRepository();
            IOrderLineRepository OrderLineRepo = new OrderLineRepository();
            Order order = _order.ConvertToOrder();

            OrderRepo.UpdateOrder(order);
            OrderLineRepo.SaveAllOrderLines(order);
            FurtherOrderStatus(order.ID, _order.SelectedStatus, " ");
            return(RedirectToAction("StockControl"));
        }
コード例 #13
0
        public void OrderLineRepositoryCRUDTest()
        {
            var context = new NoodleDbContext("NoodleDb");

            context.Init();

            IOrderLineRepository repository = new OrderLineRepository(context);

            var id = Guid.NewGuid();

            var record = new OrderLine
            {
                Id         = id,
                BasePrice  = .1f,
                BaseQty    = .1f,
                Price      = .1f,
                Priority   = 1,
                Qty        = .1f,
                Amount     = 10,
                BaseAmount = 10
            };

            repository.Create(record);

            record.BasePrice  = .2f;
            record.BaseQty    = .2f;
            record.Price      = .2f;
            record.Priority   = 2;
            record.Qty        = .2f;
            record.Amount     = 11;
            record.BaseAmount = 11;

            repository.Update(record);

            var updatedRecord = repository.GetById(id);

            Assert.AreEqual(record.Id, updatedRecord.Id);
            Assert.AreEqual(record.BasePrice, updatedRecord.BasePrice);
            Assert.AreEqual(record.BaseQty, updatedRecord.BaseQty);
            Assert.AreEqual(record.Price, updatedRecord.Price);
            Assert.AreEqual(record.Priority, updatedRecord.Priority);
            Assert.AreEqual(record.Qty, updatedRecord.Qty);
            Assert.AreEqual(record.Amount, updatedRecord.Amount);
            Assert.AreEqual(record.BaseAmount, updatedRecord.BaseAmount);

            repository.Delete(record.Id);

            var deletedRecord = repository.GetById(id);

            Assert.IsNull(deletedRecord);
        }
コード例 #14
0
 public void Save(Order order)
 {
     if (order.IsDirty)
     {
         //sets up connection if required, command and sql
         ICommand command = BuildCommandForSave(order);
         command.Execute();
         OrderLineRepository orderLineRepo = GetOrderLineRepo();
         foreach (OrderLine line in order.OrderLines)
         {
             orderLineRepo.Save(line);
         }
     }
 }
コード例 #15
0
        public ActionResult DeleteProductFromOrder(Models.ViewModels.OLChangeViewModel ocm, string _returnURL)
        {
            var identity = (ClaimsIdentity)User.Identity;

            try
            {
                IOrderLineRepository OrderLineRepo = new OrderLineRepository();
                OrderLineRepo.RemoveOrderLineFromOrder(ocm.ProdID, ocm.OrderID);
                SendMessageTroughSignalR(Convert.ToInt16(identity.Claims.Last().Value), "Product succesvol verwijderd");
            }
            catch
            {
                SendMessageTroughSignalR(Convert.ToInt16(identity.Claims.Last().Value), "Er ging iets mis tijdens het verwijderen van het product, probeer het opnieuw.");
            }

            return(Redirect(_returnURL));
        }
コード例 #16
0
 public SchemaRepositoryContainer()
 {
     #region Entity Repositories
     BuyingGroup                = new BuyingGroupRepository();
     BuyingGroups_Archive       = new BuyingGroups_ArchiveRepository();
     CustomerCategory           = new CustomerCategoryRepository();
     CustomerCategories_Archive = new CustomerCategories_ArchiveRepository();
     Customer            = new CustomerRepository();
     Customers_Archive   = new Customers_ArchiveRepository();
     CustomerTransaction = new CustomerTransactionRepository();
     InvoiceLine         = new InvoiceLineRepository();
     Invoice             = new InvoiceRepository();
     OrderLine           = new OrderLineRepository();
     Order       = new OrderRepository();
     SpecialDeal = new SpecialDealRepository();
     #endregion
     // If not implemented this method is removed during compilation
     LoadCustomRepositories();
 }
コード例 #17
0
 public ActionResult OrderProduct(int Amount, int ProdID)
 {
     if (Amount > 0)
     {
         var identity = (ClaimsIdentity)User.Identity;
         IOrderRepository     OrderRepo         = new OrderRepository();
         IOrderLineRepository OrderLineRepo     = new OrderLineRepository();
         IProductRepository   ProductRepository = new ProductRepository();
         OrderLine            OL  = new OrderLine(ProductRepository.GetProductByID(ProdID), Amount);
         Order            Order   = OrderRepo.CheckForOpenOrder(Convert.ToInt16(identity.Claims.Last().Value));
         List <OrderLine> results = Order.Products.FindAll(x => x.Product.ID == ProdID);
         if (results.Count >= 1)
         {
             OrderLineRepo.EditOrderedAmount(Order.ID, ProdID, Amount + results[0].Amount);
         }
         else
         {
             OrderLineRepo.AddOrderLineToOrder(OL, Order.ID);
         }
     }
     return(RedirectToAction("Ordering"));
 }
コード例 #18
0
        public ActionResult ChangeProductInOrder(Models.ViewModels.OLChangeViewModel ocm)
        {
            if (ocm.Amount == 0)
            {
                DeleteProductFromOrder(ocm, "/Home/ShoppingCart");
                return(RedirectToAction("ShoppingCart"));
            }
            var identity = (ClaimsIdentity)User.Identity;

            try
            {
                IOrderLineRepository OrderLineRepo = new OrderLineRepository();
                OrderLineRepo.EditOrderedAmount(ocm.OrderID, ocm.ProdID, ocm.Amount);
                SendMessageTroughSignalR(Convert.ToInt16(identity.Claims.Last().Value), "Product succesvol aangepast");
            }
            catch
            {
                SendMessageTroughSignalR(Convert.ToInt16(identity.Claims.Last().Value), "Er ging iets mis tijdens het wijzigen, probeer het opnieuw.");
            }

            return(RedirectToAction("ShoppingCart"));
        }
コード例 #19
0
        static void Main(string[] args)
        {
            CustomerRepository  crepo     = new CustomerRepository(context);
            LocationRepository  locrepo   = new LocationRepository(context);
            InventoryRepository invrepo   = new InventoryRepository(context);
            OrdersRepository    ordrepo   = new OrdersRepository(context);
            OrderLineRepository ordlirepo = new OrderLineRepository(context);
            GenericRepository <pamela_soulis_project0DataAccess.Model.Product, pamelasoulisproject0Library.Product> prepo = new GenericRepository <pamela_soulis_project0DataAccess.Model.Product, pamelasoulisproject0Library.Product>(context);



            Console.WriteLine("Hello! Welcome to the store!");
            while (true)
            {
                Console.WriteLine("a:\tDisplay store locations.");
                Console.WriteLine("b:\tYou are a new customer.");
                //for presentation, to show that the new customer was added successfully
                Console.WriteLine("c:\tDisplay customers.");
                Console.WriteLine("d:\tYou are a returning customer.");
                Console.WriteLine("e:\tYou want to view your order history.");
                Console.WriteLine("f:\tYou want to place an order.");
                Console.WriteLine("z:\tTo display location order history.");


                Console.WriteLine("q:\tExit.");
                var input = Console.ReadLine();



                //display store locations to customers
                if (input == "a")
                {
                    var TheLocationsAvailable = locrepo.GetAll().ToList();
                    foreach (var store in TheLocationsAvailable)
                    {
                        Console.WriteLine($"Location: {store.Name} with ID number {store.LocationId}.");
                    }
                }



                //add a customer to the DB given user input
                else if (input == "b")
                {
                    Console.WriteLine("Enter your firstname: ");
                    string name1 = Console.ReadLine();
                    Console.WriteLine("Enter your lastname: ");
                    string name2       = Console.ReadLine();
                    var    newCustomer = crepo.AddingANewCustomer(name1, name2);
                    crepo.Insert(newCustomer);
                    crepo.SaveToDB();
                }


                //display all customers to check if last one was added successfully
                else if (input == "c")
                {
                    var AllTheCustomers = crepo.GetAll().ToList();
                    foreach (var person in AllTheCustomers)
                    {
                        Console.WriteLine($"Here are our returning customers: {person.FirstName} {person.LastName} with ID number {person.CustomerId}.");
                    }
                }



                //get a customer by id
                else if (input == "d")
                {
                    Console.WriteLine("Enter your ID number: ");
                    int id = int.Parse(Console.ReadLine());
                    var ReturningCustomer = crepo.GetById(id);
                    Console.WriteLine($"Hi {ReturningCustomer.FirstName} {ReturningCustomer.LastName}! Welcome back!");
                }



                //display customer order history
                else if (input == "e")
                {
                    Console.WriteLine("Enter your customer ID number: ");
                    int CustomerIdOrderHistory = int.Parse(Console.ReadLine());

                    var customerOrderHistory = crepo.GetWithNavigations(CustomerIdOrderHistory);
                    foreach (var order in customerOrderHistory.Orders)
                    {
                        Console.WriteLine($"On {order.Date} at {order.Time} you ordered {string.Join(", ", order.OrderLine.Select(ol => ol.Product.Name))}.");
                    }
                }



                //Display products, display inventory, add an order
                else if (input == "f")
                {
                    Console.WriteLine("Enter your customer ID number: ");
                    int orderingCustomerId = int.Parse(Console.ReadLine());


                    var TheProductsAvailable = prepo.GetAll().ToList();
                    foreach (var item in TheProductsAvailable)
                    {
                        Console.WriteLine($"Product: {item.Name} with Id {item.ProductId}. We are selling this item for ${item.Price}.");
                    }

                    Console.WriteLine("Enter a location ID to place an order at this store.");
                    int location1 = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter a product ID to add it to your cart.");
                    int product1 = int.Parse(Console.ReadLine());

                    //display the amount left of a product at a particular location
                    var locationInventory = locrepo.GetWithNavigations(location1);

                    foreach (var productAmount in locationInventory.Inventory)
                    {
                        if (productAmount.ProductId == product1)
                        {
                            Console.WriteLine($" We have {productAmount.Quantity} left at this location.");
                        }
                    }

                    //check if customer asks for too much product based on inventory available
                    Console.WriteLine("How many would you like?");
                    int amountOfProduct = int.Parse(Console.ReadLine());
                    while (amountOfProduct <= 0)
                    {
                        Console.WriteLine("Invalid input, please enter a valid product quantity.");
                    }

                    //get the max amount available to order for this product
                    var maxAmountForOrder = invrepo.GetProductQuantity(product1);


                    if (maxAmountForOrder.Quantity == 0)
                    {
                        Console.WriteLine($"We apologize, but this product is out of stock.");
                    }
                    else if (amountOfProduct > maxAmountForOrder.Quantity)
                    {
                        Console.WriteLine($" Oups, seems like you tried to order too much! We only have {maxAmountForOrder.Quantity}.");
                    }
                    else
                    {
                        //add the order
                        int thisNewOrderId = ordrepo.NewOrder();
                        var newOrder       = ordrepo.AddingANewOrder(orderingCustomerId, location1);
                        ordrepo.Insert(newOrder);
                        ordrepo.SaveToDB();
                        var thisNewOrder = ordlirepo.AddingANewOrderLine(thisNewOrderId, product1, amountOfProduct);
                        ordlirepo.Insert(thisNewOrder);
                        ordlirepo.SaveToDB();



                        //decrease inventory
                        maxAmountForOrder.Quantity = maxAmountForOrder.Quantity - amountOfProduct;
                        var newInventory = invrepo.UpdateTheQuantity(product1, location1, maxAmountForOrder.Quantity);
                        Console.WriteLine($"We now only have {newInventory.Quantity} of this product.");
                        invrepo.SaveToDB();

                        var customerOrderHistory = crepo.GetWithNavigations(orderingCustomerId);
                        foreach (var order in customerOrderHistory.Orders)
                        {
                            Console.WriteLine($"Congratulations! Your order for {string.Join(", ", order.OrderLine.Select(ol => ol.Product.Name))} was placed successfully.");
                        }
                    }
                }


                //display location order history
                else if (input == "z")
                {
                    Console.WriteLine("Please enter the location ID number.");
                    int theLocationID        = int.Parse(Console.ReadLine());
                    var locationOrderHistory = locrepo.GetOrderHistory(theLocationID);
                    foreach (var order in locationOrderHistory.Orders)
                    {
                        Console.WriteLine($"On {order.Date} {string.Join(", ", order.OrderLine.Select(ol => ol.Product.Name))} was ordered from this location");
                    }
                }



                //display order details
                //else if (input == "x")
                //{
                //    Console.WriteLine("Enter your order ID number: ");
                //    int id = int.Parse(Console.ReadLine());
                //    var ReturningCustomerOrderHistory = ordrepo.GetById(id); //orderId
                //    Console.WriteLine($"You placed your last order at {ReturningCustomerOrderHistory.Date} {ReturningCustomerOrderHistory.Time}");
                //}



                else if (input == "q")
                {
                    break;
                }
                else
                {
                    Console.WriteLine($"Invalid input \"{input}\".");
                }
            }
        }
コード例 #20
0
ファイル: RepositoryHelper.cs プロジェクト: hem226/MVC5P
		public static OrderLineRepository GetOrderLineRepository()
		{
			var repository = new OrderLineRepository();
			repository.UnitOfWork = GetUnitOfWork();
			return repository;
		}
コード例 #21
0
 //讓 各個 RePository 共用 同一個 Connection
 public BaseController()
 {
     repo   = RepositoryHelper.GetProductRepository();
     olRepo = RepositoryHelper.GetOrderLineRepository(repo.UnitOfWork);
 }
コード例 #22
0
ファイル: RepositoryHelper.cs プロジェクト: hem226/MVC5P
		public static OrderLineRepository GetOrderLineRepository(IUnitOfWork unitOfWork)
		{
			var repository = new OrderLineRepository();
			repository.UnitOfWork = unitOfWork;
			return repository;
		}