public void ProductRepository_UpdateProduct_1IfUpdate()
 {
     ProductRepository produtoRepository = new ProductRepository();
     int actual = produtoRepository.Updates(new Product { ProductID = 1, Name = "Gurte IceCream", CategoryID = 1, Code = "200", PurchasePrice = 1, SalePrice = 2, Stock = new Stock { ProductID = 1, ManageStock = true, MaximunQuantity = 200, MinimunQuantity = 20 } });
     //ClearConnection();
     Assert.AreEqual(1, actual);
 }
        // GET: Product
        public ActionResult Index(string sort = "Name", bool sortReverse = false, int pageNumber = 1, string searchFor = "")
        {
            ViewBag.CurrentSort = sortReverse;

            using (var productRep = new ProductRepository())
            {
                ViewBag.OnePageOfProducts = ((List<Product>)productRep.Get(sort, ViewBag.CurrentSort, searchFor)).ToPagedList(pageNumber, 10);
            }

            var allProducts = new List<ProductViewModel>();
            foreach (var item in ViewBag.OnePageOfProducts)
            {
                allProducts.Add(new ProductViewModel()
                {
                    Id = item.Id,
                    Name = item.Name,
                    Description = item.Description,
                    Preco = item.Preco,
                    PhotoOutput = item.Photo == null ? string.Empty : 
                        String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
                });
            }

            ViewBag.AllProducts = allProducts;

            return View();
        }
 public void ProductRepository_GetAll_1()
 {
     ProductRepository produtoRepository = new ProductRepository();
     int actual = produtoRepository.GetAlls().Count();
     //ClearConnection();
     Assert.AreEqual(0, actual);
 }
 public void ProductRepository_GetByID_GurteIceCream()
 {
     ProductRepository produtoRepository = new ProductRepository();
     Product actual = produtoRepository.GetByIds(1);
     //ClearConnection();
     Assert.AreEqual("Gurte IceCream",actual.Name);
 }
 public SubscriptionController()
 {
     _repo = new VetRepository(new FnRDbContext());
     _subRepo = new SubscriptionRepository(new FnRDbContext());
     _userRepo = new UserRepository(new FnRDbContext());
     _productRepo = new ProductRepository(new FnRDbContext());
 }
 public void ProductRepository_CreateProduct_2IfCreate()
 {
     ProductRepository produtoRepository = new ProductRepository();
     int actual = produtoRepository.Creates(new Product { Name = "Choco IceCream", CategoryID = 1, Code = "200", PurchasePrice = 1, SalePrice = 2, Stock = new Stock { ManageStock = true, MaximunQuantity = 200, MinimunQuantity = 20 } });
        // ClearConnection();
     Assert.AreEqual(2, actual);
 }
		//[TestMethod]
		public void FindAllProducts()
		{
			ProductRepository repository = new ProductRepository();
			var ret = repository.FindAll();
			repository = new ProductRepository();
			ret = repository.FindAll();
		}
        public void SaveProduct_CreateNewProduct_NewProductShouldBeInsertedToDatabase()
        {
            int id = -1;

            var expected = new GGTestProduct
            {
                Name = "Test Product",
                Category = "Test Category",
                IsExpired = true
            };

            using (var repository = new ProductRepository())
            {
                id = repository.SaveProduct(expected);
            }

            // Verify result
            GGTestProduct actual;

            using (var session = NHibernateHelper.OpenSession())
            {
                actual = session.Get<GGTestProduct>(id);
            }

            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Category, actual.Category);
            Assert.AreEqual(expected.IsExpired, actual.IsExpired);
        }
        public static void Clear()
        {
            IRepository<Client> _clientRepository = new ClientRepository();
            IRepository<Product> _productRepository = new ProductRepository();
            IRepository<Manager> _managerRepository = new ManagerRepository();

            IEnumerable<Client> clientRepository = _clientRepository.GetItems();
            IEnumerable<Product> productRepository = _productRepository.GetItems();
            IEnumerable<Manager> managerRepository = _managerRepository.GetItems();

            foreach (var item in clientRepository)
            {
                _clientRepository.Remove(item);
            }

            foreach (var item in productRepository)
            {
                _productRepository.Remove(item);
            }

            foreach (var item in managerRepository)
            {
                _managerRepository.Remove(item);
            }
        }
 // PUT api/products/5
 public IEnumerable<Product> Put(int id, [FromBody]Product value)
 {
     ProductRepository repo = new ProductRepository();
     value.ProductId = id;
     repo.Update(value);
     return repo.Retrieve();
 }
        public void ProductRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            IProductRepository productRepository = new ProductRepository(unitOfWork);

            var book = new Book()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                ISBN = "ABC",
                Publisher = "Krasiss Press",
                Title = "The book title",
                UnitPrice = 40,
                Description = "Any book description",
                AmountInStock = 1
            };

            //Act

            productRepository.Add(book);
            productRepository.UnitOfWork.Commit();

            //Assert

            var result = productRepository.Get(book.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == book.Id);
        }
 // GET: Product/Details/5
 public ActionResult Details(int id)
 {
     using (var productRep = new ProductRepository())
     {
         return View(productRep.GetById(id));
     }
 }
        public void Update_Product0_name_to_nill()
        {

            
            AutoMapper.Mapper.CreateMap<DataAvail.UralAppModel.Product, Product>()
                .ForMember(p => p.id, opt => opt.MapFrom(p => p.Id))
                .ForMember(p => p.name, opt => opt.MapFrom(p => p.Name));

            AutoMapper.Mapper.CreateMap<Product, DataAvail.UralAppModel.Product>()
                .ForMember(p => p.Id, opt => opt.MapFrom(p => p.id))
                .ForMember(p => p.Name, opt => opt.MapFrom(p => p.name));

            Product product = new Product { id = 0, name = "hip" };

            using (var model = new UralAppModel.Model())
            {
                ProductRepository repo = new ProductRepository();

                repo.SetContext(model);

                repo.GetAll(new Microsoft.Data.Services.Toolkit.QueryModel.ODataQueryOperation());

                repo.Save(product);
            }


            /*
            UralAppServ.DataServiceProvider prr = new UralAppServ.DataServiceProvider(new Uri(@"http://localhost:3360/Service.svc/"));
            var r = prr.Products.Where(p => p.id == 0).First();
            r.name = "nill";
            //prr.AttachTo("Products", r);
            prr.UpdateObject(r);
            prr.SaveChanges();
             */
        }
        public ActionResult Index(int pageNumber = 1)
        {
            using (var productRep = new ProductRepository())
            {
                ViewBag.OnePageOfProducts = productRep.Get().ToPagedList(pageNumber, 8);
            }

            var allProducts = new List<ProductViewModel>();
            foreach (var item in ViewBag.OnePageOfProducts)
            {
                allProducts.Add(new ProductViewModel()
                {
                    Id = item.Id,
                    Name = item.Name,
                    Description = item.Description,
                    Preco = item.Preco,
                    PhotoOutput = item.Photo == null ? string.Empty :
                        String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
                });
            }

            var countProducts = allProducts.Count();

            ViewBag.FirstRowOfProductList = countProducts.Equals(0) ? null : allProducts.Take(4);
            if (countProducts > 4)
                ViewBag.SecondRowOfProductList = countProducts.Equals(0) ? null : allProducts.GetRange(4, countProducts - 4);

            return View();
        }
Пример #15
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                Product product;
                var productRepository = new ProductRepository();
                if (id > 0)
                {
                    var products = productRepository.Retrieve();
                    product = products.FirstOrDefault(p => p.ProductId == id);
                    if (product == null)
                    {
                        return NotFound();
                    }
                }
                else
                {
                    product = productRepository.Create();
                }
                return Ok(product);
            }
            catch (Exception ex)
            {

                return InternalServerError(ex);
            }
        }
Пример #16
0
        //
        // GET: /Shop/
        public ActionResult Index()
        {
            var rep = new ProductRepository();
            var list = rep.Table.ToList();

            return View();
        }
Пример #17
0
        public ActionResult ListaAtualizar(Guid Id)
        {
            ProductRepository<Product> dao = new ProductRepository<Product>();
            Product produto = dao.ListarPorId(Id);

            return View(produto);
        }
Пример #18
0
 public ActionResult Delete(Guid Id)
 {
     ProductRepository<Product> dao = new ProductRepository<Product>();
     Product produto = dao.ListarPorId(Id);
     dao.Delete(produto);
     return RedirectToAction("index", "Product");
 }
 public static void TestProductRepository()
 {
     using (var repository = new ProductRepository(new AdventureWorksContext()))
     {
         var productsBySubCategory = repository.GetGetProductsForSubCategory(1);
     }
 }
Пример #20
0
        public ActionResult Update(Product produto )
        {
            ProductRepository<Product> dao = new ProductRepository<Product>();
            dao.Update(produto);

            return RedirectToAction("index", "Product");
        }
Пример #21
0
        static void Main(string[] args)
        {
            using (var dataContext = new CustomerDataContext())
            {
                var orderRepository = new Repository<Order>(dataContext);
                Order order = orderRepository.SearchFor(o => o.CustomerID == 38).Single();

                var orderItemsRepository = new Repository<OrderItem>(dataContext);
                var orderitems = orderItemsRepository.SearchFor(ot => ot.Order.Equals(order));

                var productrep = new ProductRepository(dataContext);
                var products = productrep.FindProductByOrderItems(orderitems.ToList());

                Console.WriteLine(" Products for {0} "+Environment.NewLine
                    +"----------------------", order.Customer.Name);

                foreach (var product in products)
                {
                    Console.WriteLine(product.Name);
                }

                Console.ReadKey();



            }
        }
Пример #22
0
 public UnitOfWork(DataContext context)
 {
     _context = context;
     Stores = new StoreRepository(_context);
     Products = new ProductRepository(_context);
     HasA = new HasARepository(_context);
 }
Пример #23
0
        public IEnumerable<Product> Get(string search)
        {
            var productRepository = new ProductRepository();
            var products = productRepository.Retrieve();

            return products.Where(p => p.ProductCode.Contains(search));
        }
Пример #24
0
        public CategoryDboTest()
        {
            productRepository = new ProductRepository(DbContextFactory);

            repository = new CategoryRepository(DbContextFactory);
            dataService = new CategoryDataService(repository, UnitOfWork);
        }
Пример #25
0
        public ActionResult About()
        {
            // Generiskt Repository - Här skapas ett repository för Category
            // Repositoryt kräver typer som implementerar IEntity
            Repository<Category> categoryRepo = new Repository<Category>();

            // Samtliga metoder som finns med i det generiska repositoriet
            var categories = categoryRepo.FindAll();

            var filteredCategories = categoryRepo.FindAll(c => c.Name.Contains("sport"));

            var category = categoryRepo.FindByID(0);

            category.Name = "New Name!";
            categoryRepo.Save(category);

            categoryRepo.Delete(category);

            ProductRepository productRepo = new ProductRepository();

            var products = productRepo.FindAll(); // + övriga "grund"-metoder

            // Metoder implementerade i ProductRepository:
            var productsForCategory = productRepo.FindProductsByCategoryID(0);

            var productsWithEmptyName = productRepo.FindAll(ProductRepository
                                                            .FilterProductsWithEmptyDescription);

            return View();
        }
 public CatalogTasksImplementation(DepartmentRepository department_repository, DepartmentItemMapper departmentItemMapper, ProductRepository product_repository, ProductItemMapper product_item_mapper)
 {
     this.department_repository = department_repository;
     this.product_item_mapper = product_item_mapper;
     this.product_repository = product_repository;
     this.departmentItemMapper = departmentItemMapper;
 }
 public void ShouldUpdateTheStockForProduct()
 {
     var productRepository = new ProductRepository(@"Repository\Products.txt", "Product");
        // productRepository.UpdateStock(2);
     var products = productRepository.GetAll().ToArray();
     Assert.AreEqual(2, products[1].Stock);
 }
Пример #28
0
 public FCDatabaseContext(SqlConnection connection)
 {
     _connection = connection;
     _products = new ProductRepository(connection);
     _restaurants = new RestaurantRepository(connection);
     _reviews = new ReviewRepository(connection);
 }
Пример #29
0
 public TradeController()
 {
     this.saleRep = new SaleRepository();
     this.managerRep = new ManagerRepository();
     this.productRep = new ProductRepository();
     formattedSales = new List<FormattedSale>();
 }
Пример #30
0
        static void Main(string[] args)
        {
            using (var context = new DatabaseContext())
            {
                ICustomerRepository customers = new CustomerRepository(context);
                IProductRepository products = new ProductRepository(context);

                var github = new Customer() { IsActive = true, Name = "GitHub" };
                var microsoft = new Customer() {IsActive = true, Name = "Microsoft"};
                var apple = new Customer() { IsActive = false, Name = "Apple" };

                customers.Create(github);
                customers.Create(microsoft);
                customers.Create(apple);

                var windows = new Product()
                {
                    CustomerId = microsoft.Id,
                    Description = "The best OS!",
                    Name = "Windows 10",
                    Sku = "AWESOME1"
                };

                var sourceControl = new Product()
                {
                    CustomerId = github.Id,
                    Description = "The best hosted source control solution!",
                    Name = "GitHub Enterprise",
                    Sku = "AWESOME2"
                };

                var iphone = new Product()
                {
                    CustomerId = apple.Id,
                    Description = "The best phone ever created!",
                    Name = "iPhone 6S",
                    Sku = "AWESOME3"
                };

                products.Create(windows);
                products.Create(sourceControl);
                products.Create(iphone);

                foreach (var customer in customers.All.WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);
                }

                foreach (var customer in customers.GetAllWithProducts().WhereNameBeginsWith("Git").WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);

                    foreach (var product in customer.Products)
                    {
                        Console.WriteLine("-- {0}", product.Name);
                    }
                }
            }
        }
Пример #31
0
        private static async Task Main(string[] args)
        {
            string connectionString       = ConfigurationUtilities.GetConnectionStringFromConnectionKey("ProductsDb");
            var    productsOptionsBuilder = new DbContextOptionsBuilder();

            productsOptionsBuilder.UseSqlServer(connectionString);

            var productsRespository = new ProductRepository(new ProductContext());

            var material1 = new Material("Some-Material1", "Some-Description1", 2.50M);
            var material2 = new Material("Some-Material2", "Some-Description2", 4.75M);
            var material3 = new Material("Some-Material3", "Some-Description3", 7.25M);

            var partList1 = new List <ProductPart>
            {
                new ProductPart("Some-Part1", "grams", 1.0M, new List <Material> {
                    material1, material3
                }),
                new ProductPart("Some-Part2", "grams", 3.0M, new List <Material> {
                    material2, material3
                }),
            };

            var partList2 = new List <ProductPart>
            {
                new ProductPart("Some-Part1", "grams", 6.0M, new List <Material> {
                    material1, material3
                }),
                new ProductPart("Some-Part3", "grams", 5.0M, new List <Material> {
                    material2, material3, material1
                }),
            };

            var product1 = new Product
            {
                Name         = "Some-Product1",
                ProductParts = partList1
            };

            productsRespository.Insert(product1);
            await productsRespository.SaveChangesAsync();

            var product2 = new Product
            {
                Name         = "Some-Product2",
                ProductParts = partList2
            };

            productsRespository.Insert(product2);
            await productsRespository.SaveChangesAsync();

            var products = productsRespository.GetProducts();

            var ordersRepository = new OrderRepository(new OrderContext());
            var order1           = new Order
            {
                Items = new List <OrderItem>
                {
                    new OrderItem
                    {
                        ProductId = product1.Id,
                        Quantity  = 3,
                        UnitPrice = 5
                    }
                },
                OrderDate = DateTime.Now
            };

            ordersRepository.Insert(order1);
            await ordersRepository.SaveChangesAsync();


            var order2 = new Order
            {
                Items = new List <OrderItem>
                {
                    new OrderItem
                    {
                        ProductId = product2.Id,
                        Quantity  = 3,
                        UnitPrice = 5
                    }
                },
                OrderDate = DateTime.Now
            };

            ordersRepository.Insert(order2);
            await ordersRepository.SaveChangesAsync();


            var order3 = new Order
            {
                Items = new List <OrderItem>
                {
                    new OrderItem
                    {
                        ProductId = product2.Id,
                        Quantity  = 9,
                        UnitPrice = 2
                    }
                },
                OrderDate = DateTime.Now
            };

            ordersRepository.Insert(order3);
            await ordersRepository.SaveChangesAsync();


            var orders = ordersRepository.GetOrders();
        }
 public void TestInitialize()
 {
     SUT = new ProductRepository(new Product(1, "Lapte", "Se bea", DateTime.Parse("1/1/2010"), DateTime.Parse("1/1/2020"), 100, 20), new Product(1, "Pizza", "Se bea", DateTime.Parse("1/1/2010"), DateTime.Parse("1/1/2020"), 100, 20), new Product(1, "Paine", "Se bea", DateTime.Parse("1/1/2010"), DateTime.Parse("1/1/2020"), 100, 20));
 }
Пример #33
0
 public ProductViewModel()
 {
     _productView       = ProductFactory.createProduct();
     _productRepository = new ProductRepository();
 }
 public void TestSetup()
 {
     //AppDbContextExtensions db = new AppDbContextExtensions();
     Database.SetInitializer(new AppDbContextExtensions());
     Repo = new ProductRepository();
 }
Пример #35
0
 public void Init()
 {
     storeRepo    = new StoreRepository(context);
     productRepo  = new ProductRepository(context);
     categoryRepo = new CategoryRepository(context);
 }
 public ProfileController(UserManager <User> userManager, ProductRepository productManager)
 {
     _userManager       = userManager;
     _productRepository = productManager;
 }
Пример #37
0
 public static Product GetProductById(int id)
 {
     return(ProductRepository.GetProductById(id));
 }
Пример #38
0
        public ActionResult Delete(Product product)
        {
            ProductRepository.DeleteProduct(product);

            return(Redirect("/home/index"));
        }
        public async Task TestWholeInfrastructureBeingHere()
        {
            //PLEASE TAKE CARE IF THE CONFIG MATCHES YOUR OWN MONGODB SETTINGS!
            var mongoConfig         = new MongoConfig("mongodb://localhost", "test-blog");
            var databaseProvider    = Factory.CreateDatabaseProvider(mongoConfig);
            var transactionProvider = Factory.CreateTransactionProvider(databaseProvider);

            var productRepository     = new ProductRepository(transactionProvider, databaseProvider);
            var productInfoRepository = new ProductInfoRepository(transactionProvider, databaseProvider, productRepository);
            var recipeRepository      = new RecipeRepository(transactionProvider, databaseProvider, productRepository);
            var storageRepository     = new StorageRepository(transactionProvider, databaseProvider);

            // Clear database :)
            await deleteAllItemsFromDatabase(productRepository, productInfoRepository, recipeRepository, storageRepository);

            var ingredient = new Ingredient
            {
                Amount = 100,
                Name   = "Wirkstoff A",
                Unit   = DBI_Apotheke.Core.Workloads.Modules.Unit.MG
            };
            var idPi = new ObjectId();
            var list = new List <Ingredient>();

            list.Add(ingredient);
            var productInfo = new ProductInfo
            {
                Brand       = "Aspiring",
                Id          = idPi,
                Ingredients = list,
                Name        = "AspirinComplex"
            };

            productInfo = await productInfoRepository.InsertItem(productInfo);

            var product1 = new Product
            {
                Amount        = 200,
                Id            = new ObjectId(),
                Price         = 20,
                ProductInfoId = productInfo.Id,
                PZN           = 01,
                Unit          = DBI_Apotheke.Core.Workloads.Modules.Unit.G
            };
            var product2 = new Product
            {
                Amount        = 200,
                Id            = new ObjectId(),
                Price         = 10,
                ProductInfoId = productInfo.Id,
                PZN           = 02,
                Unit          = DBI_Apotheke.Core.Workloads.Modules.Unit.G
            };
            var recipe = new Recipe
            {
                Address = "Burger Sta?e",
                Id      = new ObjectId(),
                Issuer  = "Kirchi",
                Name    = "Elias",
                PZNs    = new List <int>()
                {
                    1, 2
                }
            };

            product1 = await productRepository.InsertItem(product1);

            product2 = await productRepository.InsertItem(product2);

            recipe = await recipeRepository.InsertItem(recipe);

            var storage1 = new Storage
            {
                Id          = new ObjectId(),
                Amount      = 100,
                PZN         = 1,
                StorageSite = "Hamburg"
            };
            var storage2 = new Storage
            {
                Id          = new ObjectId(),
                Amount      = 100,
                PZN         = 2,
                StorageSite = "Hamburg"
            };

            storage1 = await storageRepository.InsertItem(storage1);

            storage2 = await storageRepository.InsertItem(storage2);

            _testOutputHelper.WriteLine("Test if everything was received!");

            _testOutputHelper.WriteLine("Id: " + productInfo.Id.ToString() + " Object: " + productInfo.ToString());
            _testOutputHelper.WriteLine("Id: " + product1.Id.ToString() + " Object: " + product1.ToString());
            _testOutputHelper.WriteLine("Id: " + product2.Id.ToString() + " Object: " + product2.ToString());
            _testOutputHelper.WriteLine("Id: " + product1.Id.ToString() + " Object: " + product1.ToString());
            _testOutputHelper.WriteLine("Id: " + recipe.Id.ToString() + " Object: " + recipe.ToString());
            _testOutputHelper.WriteLine("Id: " + storage1.Id.ToString() + " Object: " + storage1.ToString());
            _testOutputHelper.WriteLine("Id: " + storage2.Id.ToString() + " Object: " + storage2.ToString());

            var productsInfoByIngreadients = await productInfoRepository.GetByIngredient("Wirkstoff A");

            var productsInfo = await productInfoRepository.GetAllItems();


            productsInfoByIngreadients.Should().HaveCount(1);
            productsInfo.Should().HaveCount(1);
            productsInfo.Should().BeEquivalentTo(productsInfoByIngreadients);


            product1 = await productRepository.GetByPzn(recipe.PZNs.IndexOf(0));

            product2 = await productRepository.GetByPzn(recipe.PZNs.IndexOf(1));

            var products = await productRepository.GetAllItems();

            products.Should().HaveCount(2);
            products.Should().BeEquivalentTo(new List <Product> {
                product1, product2
            });


            var actualRecipe = await recipeRepository.GetItemById(recipe.Id);

            actualRecipe.Should().BeEquivalentTo(recipe);

            var totalPrice = await recipeRepository.GetTotalPrice(actualRecipe !);

            totalPrice.Should().BeApproximately(30, 0.1);

            var actualStorage = await storageRepository.GetItemById(storage1.Id);

            actualStorage.Should().BeEquivalentTo(storage1);

            var actualStorage2 = await storageRepository.GetItemById(storage2.Id);

            actualStorage2.Should().BeEquivalentTo(storage2);

            actualStorage = await storageRepository.GetByPzn(product1.PZN);

            actualStorage.Should().BeEquivalentTo(storage1);

            actualStorage2 = await storageRepository.GetByPzn(product2.PZN);

            actualStorage2.Should().BeEquivalentTo(storage2);
        }
Пример #40
0
 public ValuesController(EbuyContext context)
 {
     this.context = context;
     this._rep    = new ProductRepository(this.context);
 }
Пример #41
0
 public ProductController()
 {
     _repo = new ProductRepository();
 }
Пример #42
0
 public UnitOfWork(ProductDbContext context)
 {
     _context = context;
     Product  = new ProductRepository(context);
 }
Пример #43
0
 public UnitOfWork(ProductApplicationContext context)
 {
     _context       = context;
     Products       = new ProductRepository(_context);
     ProductOptions = new ProductOptionRepository(_context);
 }
Пример #44
0
 public ProductController(ILogger <ProductController> logger,
                          ProductRepository productRepository)
 {
     _logger            = logger;
     _productRepository = productRepository;
 }
Пример #45
0
 public ProductService()
 {
     _productRepository = new ProductRepository();
 }
        public FileResult SalesReportReseller(string userid = "")
        {
            string userRowKey = string.Empty;

            if (userid == string.Empty)
            {
                var user = Membership.GetUser();
                userRowKey = (user.ProviderUserKey as string);
            }
            else
            {
                userRowKey = userid;
            }

            var chamber     = new CompanyRepository().GetByRowKey(userRowKey);
            var historyList = new List <TransactionHistoryModel>();

            //get companies
            var allCompanies = CompanyHelper.GetAllCompaniesFromCache();
            //get subscriptions
            var allSubscriptions = CompanySubscriptionHelper.GetAllCompanySubscriptionsFromCache();
            //get transactions
            var allTransactions = new TransactionRepository().GetAll().ToArray();
            //get all products
            var allProducts = new ProductRepository().GetAll().ToArray();

            //query for list  of subscriptions for members
            var allHistoryTier1 = allSubscriptions.Where(s => s.Chamber1 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray();
            var allHistoryTier2 = allSubscriptions.Where(s => s.Chamber2 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray();
            var allHistoryTier3 = allSubscriptions.Where(s => s.Chamber3 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray();
            var allHistoryTier4 = allSubscriptions.Where(s => s.Chamber4 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray();

            //add tier 1 history
            historyList.AddRange(
                allHistoryTier1.Select(h => new TransactionHistoryModel(
                                           h.RowKey,
                                           allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name,
                                           allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,
                                           allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName,
                                           h.StartDateTime,
                                           GetTierCommission("1"),
                                           chamber.Name))
                );

            //add tier 2 history
            historyList.AddRange(
                allHistoryTier2.Select(h => new TransactionHistoryModel(
                                           h.RowKey,
                                           allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name,
                                           allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,
                                           allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName,
                                           h.StartDateTime,
                                           GetTierCommission("2"),
                                           chamber.Name))
                );

            //add tier 3 history
            historyList.AddRange(
                allHistoryTier3.Select(h => new TransactionHistoryModel(
                                           h.RowKey,
                                           allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name,
                                           allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,
                                           allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName,
                                           h.StartDateTime,
                                           GetTierCommission("3"),
                                           chamber.Name))
                );

            //add tier 4 history
            historyList.AddRange(
                allHistoryTier4.Select(h => new TransactionHistoryModel(
                                           h.RowKey,
                                           allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name,
                                           allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,
                                           allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName,
                                           h.StartDateTime,
                                           GetTierCommission("4") * allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,//todo: optimize
                                           chamber.Name))
                );

            var orderedHistoryNoTotalsList   = historyList.OrderBy(h => h.TransactionTimeStamp).ToList();
            var orderedHistoryWithTotalsList = new List <TransactionHistoryModel>();

            double runningTotal = 0;

            orderedHistoryNoTotalsList.ForEach(h =>
            {
                h.ChamberRunningTotal = runningTotal + h.Commission;
                orderedHistoryWithTotalsList.Add(h);
            });

            //generate csv
            StringBuilder csvStringBuilder = new StringBuilder();

            CsvConfig <TransactionHistoryModel> .OmitHeaders = false;

            orderedHistoryNoTotalsList.ForEach(oh =>
            {
                var csv = CsvSerializer.SerializeToString <TransactionHistoryModel>(oh);
                csvStringBuilder.Append(csv);
                CsvConfig <TransactionHistoryModel> .OmitHeaders = true;
            });

            return(File(ASCIIEncoding.ASCII.GetBytes(csvStringBuilder.ToString()), "text/csv", "sales.csv"));
        }
 public ProductRegisteredHandler(ProductRepository productRepository)
 {
     this.productRepository = productRepository;
 }
Пример #48
0
        private void DeleteProduct()
        {
            ProductRepository productRepository = new ProductRepository();

            productRepository.Delete(SelectedProduct);
        }
Пример #49
0
 //Dependency Injection
 public ProductsController(IHostingEnvironment environment, IConfiguration configuration, ProductRepository productRepository)
 {
     Repository = productRepository;
 }
Пример #50
0
        private void AddProduct()
        {
            ProductRepository productRepository = new ProductRepository();

            productRepository.Add(SelectedProduct);
        }
Пример #51
0
 public static bool IsEmpty()
 {
     return(ProductRepository.IsEmpty());
 }
 public ProductsController(ProductRepository productRepository)
 {
     _productRepository = productRepository;
 }
Пример #53
0
 public StoreBusiness(IUnitOfWork _unitOfWork)
 {
     unitOfWork             = _unitOfWork;
     productRepository      = new ProductRepository(unitOfWork);
     productImageRepository = new ProductImageRepository(unitOfWork);
 }
Пример #54
0
 public void SetUp()
 {
     this.productRepository = new ProductRepository("Data Source=C:/Users/gtc12/source/repos/SeeSharpWebshop/SeesharpWebshop/App_Data/shop.db");
 }
 public void TestCleanup()
 {
     SUT = null;
 }
Пример #56
0
 public ProductManager()
 {
     telemetria = new Trace();
     repository = new ProductRepository();
 }
Пример #57
0
 private ProductsController()
 {
     repository = ProductRepository.GetRepository();
     products   = repository.GetProducts();
 }
Пример #58
0
 public void SetValues()
 {
     AddProductComboBox.ItemsSource    = ProductRepository.GetAll();
     RemoveProductComboBox.ItemsSource = Order.Products.ToList();
 }
Пример #59
0
 public ProductManagerController()
 {
     context           = new ProductRepository();
     productCategories = new ProductCategoryRepository();
 }
 public ProductManagerController()
 {
     context = new ProductRepository();
 }