Exemplo n.º 1
0
        public void ExecuteOrdersTest()
        {
            var client = new StocksRepository(_consumerToken, _accessToken);

            // one of the sandbox accounts
            const int accountId = 30049872;

            var orders =
                new List <Order>
            {
                new Order
                {
                    IsSale   = false,
                    Price    = 1m,
                    Quantity = 1,
                    Symbol   = "HP"
                },
                new Order
                {
                    IsSale   = true,
                    Price    = 1m,
                    Quantity = 1,
                    Symbol   = "MSFT"
                }
            };

            var response = client.ExecuteOrders(accountId, orders);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Any());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert Stocks
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> InsertStocks(StockVM entity)
        {
            var result = string.Empty;

            try
            {
                StockDetails stockdetail = new StockDetails();
                var          dataProduct = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(entity.ProductId));
                stockdetail.StockQuantity     = dataProduct.Quantity;
                stockdetail.TransQuantity     = decimal.Subtract(dataProduct.Quantity, entity.Quantity);
                stockdetail.TotalQuantity     = entity.Quantity;
                stockdetail.Date              = entity.Date;
                stockdetail.PurcheaseId       = entity.PurcheaseId;
                stockdetail.SalesId           = entity.SalesId;
                stockdetail.PurcheaseReturnId = entity.PurcheaseReturnId;
                stockdetail.SalesReturnId     = entity.SalesReturnId;
                stockdetail.StockStutes       = entity.StockStutes;
                result = await new StockDetailsBL(logger).InsertStockDetails(stockdetail);
                result = await new StocksRepository(logger).Insert(entity);
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert Purchases
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> InsertPurchases(Purchases entity)
        {
            var result = string.Empty;

            using (TransactionScope txScope = new TransactionScope())
            {
                try
                {
                    IEnumerable <Purchases> pud = new List <Purchases>();
                    pud = new PurchasesRepository(logger).GetAll().Result;
                    if (pud.Any(c => c.InvoiecNo.Equals(entity.InvoiecNo)))
                    {
                        throw new ArgumentNullException("Already this InvoiecNo is exist!", "");
                    }
                    var pudid = 1;
                    if (pud.Any())
                    {
                        pudid = pud.Last().Id + 1;
                    }
                    entity.Id = pudid;
                    result    = await new PurchasesRepository(logger).Insert(entity);
                    foreach (var data in entity.PurcheaseDetails)
                    {
                        data.PurchaseId = pudid;
                        result          = await new PurcheaseDetailsRepository(logger).Insert(data);
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(data.ProductId));
                        if (stockdata != null)
                        {
                            if (stockdata.Quantity < data.Quantity)
                            {
                                stockdata.Quantity = decimal.Add(stockdata.Quantity, data.Quantity);;
                            }
                            else if (stockdata.Quantity > data.Quantity)
                            {
                                stockdata.Quantity = decimal.Subtract(stockdata.Quantity, data.Quantity);
                            }
                            stockdata.FinalUnitPrice = data.UnitePrice;
                            result = await new StocksRepository(logger).Update(stockdata);
                        }
                        else
                        {
                            Stocks svm = new Stocks {
                                ProductId = data.ProductId, FinalUnitPrice = data.UnitePrice, Quantity = data.Quantity
                            };
                            result = await new StocksRepository(logger).Insert(svm);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    result = "Fail~" + ex.Message.ToString();
                    throw ex;
                }
                finally {
                    txScope.Complete();
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public void ParallelTokenBucketTest()
        {
            var client = new StocksRepository(_consumerToken, _accessToken);

            var tokens =
                new[] {
                new { client, consumerToken = _consumerToken, accessToken = _accessToken },
                new { client, consumerToken = _consumerToken, accessToken = _accessToken },
                new { client, consumerToken = _consumerToken, accessToken = _accessToken },
                new { client, consumerToken = _consumerToken, accessToken = _accessToken }
            };

            var accounts = new List <Account>();

            var sw = new Stopwatch();

            sw.Start();

            Parallel.ForEach(
                tokens,
                t => accounts.AddRange(t.client.GetAccounts())
                );

            sw.Stop();

            Assert.IsNotNull(accounts);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Insert Purchases
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> InsertPurchases(Purchases entity)
        {
            var     result    = string.Empty;
            StockVM stockdata = new StockVM();

            using (TransactionScope txScope = new TransactionScope())
            {
                try
                {
                    foreach (var data in entity.PurcheaseDetails)
                    {
                        data.ProReturn = true;
                        result         = await new PurcheaseDetailsRepository(logger).Update(data);
                        stockdata      = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId == data.ProductId);
                        if (stockdata != null)
                        {
                            stockdata.Quantity = decimal.Subtract(stockdata.Quantity, data.Quantity);
                            result             = await new StocksRepository(logger).Update(stockdata);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    result = "Fail~" + ex.Message.ToString();
                    throw ex;
                }
                finally {
                    txScope.Complete();
                    txScope.Dispose();
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update Purchases
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> UpdatePurchases(Purchases entity)
        {
            var result = string.Empty;

            try
            {
                using (TransactionScope txScope = new TransactionScope())
                {
                    //Insert in Purchease
                    result = await new PurchasesRepository(logger).Update(entity);
                    var purd = new PurcheaseDetailsRepository(logger).GetAll().Result.Where(c => c.PurchaseId.Equals(entity.Id));
                    //Delete in PurcheaseDetail
                    foreach (var data in purd)
                    {
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(data.ProductId));
                        if (stockdata != null)
                        {
                            stockdata.Quantity = stockdata.Quantity - data.Quantity;
                            result             = await new StocksRepository(logger).Update(stockdata);
                        }
                        result = await new PurcheaseDetailsRepository(logger).Delete(data.Id);
                    }
                    foreach (PurcheaseDetails datas  in entity.PurcheaseDetails.ToList())
                    {
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(datas.ProductId));
                        if (stockdata != null)
                        {
                            if (stockdata.Quantity < datas.Quantity)
                            {
                                var Quantity = decimal.Add(stockdata.Quantity, datas.Quantity);
                                stockdata.Quantity = Quantity;
                            }
                            else if (stockdata.Quantity > datas.Quantity)
                            {
                                stockdata.Quantity = decimal.Subtract(stockdata.Quantity, datas.Quantity);
                            }
                            stockdata.UnitPrice = datas.UnitePrice;
                            result = await new StocksRepository(logger).Update(stockdata);
                        }
                        else
                        {
                            StockVM svm = new StockVM {
                                ProductId = datas.ProductId, UnitPrice = datas.UnitePrice, Quantity = datas.Quantity
                            };
                            result = await new StocksRepository(logger).Insert(svm);
                        }
                        datas.PurchaseId = entity.Id;
                        result           = await new PurcheaseDetailsRepository(logger).Insert(datas);
                    }
                    txScope.Complete();
                }
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 7
0
        public void GetOAuthUserActionUriTest()
        {
            var client = new StocksRepository(_consumerToken);

            var userActionUri = client.GetUserAuthorizationUrl();

            Assert.IsNotNull(userActionUri);
        }
Exemplo n.º 8
0
        public void GetAccountByIdTest()
        {
            var client = new StocksRepository(_consumerToken, _accessToken);

            // one of the sandbox accounts
            const int accountId = 30049872;
            var       actual    = client.GetAccountById(accountId);

            Assert.IsNotNull(actual);
        }
Exemplo n.º 9
0
        public RepositoryFactory()
        {
            var daoFactory     = new DAOFactory(DatabaseType.MYSQL);
            var builderFactory = new ConverterFactory(new DomainFactory(),
                                                      new EntityFactory(),
                                                      this,
                                                      daoFactory);

            ProductsRepository = new ProductsRepository(daoFactory.ProductEntityDAO, builderFactory);
            StocksRepository   = new StocksRepository(daoFactory.StockEntityDAO, builderFactory);
            TagsRepository     = new TagsRepository(daoFactory.TagEntityDAO, builderFactory);
        }
Exemplo n.º 10
0
        public void GetAccountsTest()
        {
            var sw = new Stopwatch();

            sw.Start();

            var client = new StocksRepository(_consumerToken, _accessToken, true);

            var accounts = client.GetAccounts();

            sw.Stop();

            Assert.IsNotNull(accounts);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Update Sales
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> UpdateSales(Sales entity)
        {
            var result = String.Empty;

            using (TransactionScope txScope = new TransactionScope())
            {
                try
                {
                    result = await new SalesRepository(logger).Update(entity);
                    var purd = new SalesDetailsRepository(logger).GetAll().Result.Where(c => c.SalesId.Equals(entity.Id));
                    //Delete in PurcheaseDetail
                    foreach (var data in purd)
                    {
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(data.ProductId));
                        if (stockdata != null)
                        {
                            stockdata.Quantity = decimal.Subtract(stockdata.Quantity, data.SalesQuantity);
                            result             = await new StocksRepository(logger).Update(stockdata);
                        }
                        result = await new SalesDetailsRepository(logger).Delete(data.Id);
                    }
                    foreach (var data in entity.SalesDetails)
                    {
                        data.SalesId = entity.Id;
                        result       = await new SalesDetailsRepository(logger).Insert(data);
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(data.ProductId));
                        if (stockdata != null)
                        {
                            stockdata.Quantity = decimal.Add(stockdata.Quantity, data.SalesQuantity);
                            result             = await new StocksRepository(logger).Update(stockdata);
                        }
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    throw ex;
                }
                finally
                {
                    txScope.Complete();
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Insert Sales
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Message</returns>
        public async Task <string> InsertSales(Sales entity)
        {
            var result = String.Empty;

            using (TransactionScope txScope = new TransactionScope())
            {
                try
                {
                    IEnumerable <Sales> sad = new List <Sales>();
                    sad = new SalesRepository(logger).GetAll().Result;

                    if (sad.Any(c => c.InvoiecNo.Equals(entity.InvoiecNo)))
                    {
                        throw new ArgumentNullException("Already this InvoiecNo is exist!", "");
                    }
                    var sadid = 1;
                    if (sad.Any())
                    {
                        sadid = sad.Last().Id + 1;
                    }
                    entity.Id = sadid;
                    result    = await new SalesRepository(logger).Insert(entity);
                    foreach (var data in entity.SalesDetails)
                    {
                        data.SalesId = sadid;
                        result       = await new SalesDetailsRepository(logger).Insert(data);
                        var stockdata = new StocksRepository(logger).GetAll().Result.FirstOrDefault(c => c.ProductId.Equals(data.ProductId));
                        if (stockdata != null)
                        {
                            stockdata.Quantity = decimal.Subtract(stockdata.Quantity, data.SalesQuantity);
                        }
                        result = await new StocksRepository(logger).Update(stockdata);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    throw ex;
                }
                finally
                {
                    txScope.Complete();
                }
                return(result);
            }
        }
Exemplo n.º 13
0
        public void DisplayProducts()
        {
            Console.WriteLine("Chargement...");
            ProductsRepository productsRepository = new ProductsRepository();
            var listProduct = productsRepository.GetAllProducts();

            Clear();
            Echo("Liste des produits : \n");

            PrintTableHeader(true, "Id", "CategoryId", "Name", "Description", "Price", "Stock", "Date d'expiration");
            foreach (Product aProduct in listProduct)
            {
                StocksRepository stocksRepository = new StocksRepository();
                var stockOfProduct = stocksRepository.GetStockByProductId(aProduct.Id);
                var dateTime       = stocksRepository.ConvertTimeStampToStringDate(stockOfProduct.Expiry);

                PrintLineCells(true, $"{aProduct.Id}", $"{aProduct.CategoryId}", aProduct.Name, aProduct.Description, $"{aProduct.Price}", $"{stockOfProduct.Quantity}", dateTime);
            }
            Echo(PrintLine());
        }
Exemplo n.º 14
0
        public SearchShortDates()
        {
            Clear();

            string dateSearch         = AskForDate();
            bool   isProductValidated = ValidateProduct(dateSearch);

            if (isProductValidated)
            {
                Clear();
                Echo("Liste des produits dont la date de consommation se terminant avant ou le " + dateSearch + " : \n");
                PrintTableHeader(true, "Id", "Name", "Prix", "Stock", "Date d'expiration");

                StocksRepository   stocksRepository   = new StocksRepository();
                ProductsRepository productsRepository = new ProductsRepository();

                var stringDateSearch = stocksRepository.ConvertStringDateToTimeStamp(dateSearch);
                var listProducts     = productsRepository.GetAllProducts();

                foreach (Product aProduct in listProducts)
                {
                    var stockProduct = stocksRepository.GetStockByProductId(aProduct.Id);
                    var stringExpiry = stocksRepository.ConvertTimeStampToStringDate(stockProduct.Expiry);
                    int result       = stringDateSearch.CompareTo(stockProduct.Expiry);

                    if (result >= 0)
                    {
                        PrintLineCells(true, $"{aProduct.Id}", aProduct.Name, $"{aProduct.Price}", $"{stockProduct.Quantity}", stringExpiry);
                    }
                    else
                    {
                    }
                }
                Echo(PrintLine());
                WaitForKeyPress();
            }
        }
Exemplo n.º 15
0
        //Naming convention ok

        public AddProduct()
        {
            Clear();
            int categoryId = AskForCategory();

            Clear();
            string name = AskForName();

            Clear();
            string description = AskCommand("Description (optionnelle):");

            Clear();
            float price = AskForFloat("Entrez le prix (avec une virgule) :");

            Clear();
            int quantity = AskForInteger("Stock de ce produit: ");

            Clear();
            string expirationDate = AskCommand("Rentrez la date limite de consommation du produit (ex: 03/12/2020) :");

            Clear();

            var product = new Product {
                CategoryId = categoryId, Name = name, Description = description, Price = price,
            };

            ProductsRepository productsRepository = new ProductsRepository();
            StocksRepository   stockRepository    = new StocksRepository();
            bool isProductValidated = ValidateProduct(product, expirationDate, quantity);

            if (isProductValidated)
            {
                Clear();
                Echo("Ajout du produit en base...");

                try
                {
                    productsRepository.AddProduct(product);
                } catch (Exception e)
                {
                    Style.SelectColor(ConsoleColor.Red);
                    Echo("Impossible d'ajouter le produit en base");
                    //TODO Message d'erreur ?
                    Echo("Message d'erreur");
                    Echo(e.Message);
                    Style.SelectColor(ConsoleColor.White);
                    AskKeyPress();
                    return;
                }

                Style.Green("Le produit a bien été créé.", true);

                try
                {
                    var timeConvert = stockRepository.ConvertStringDateToTimeStamp(expirationDate);

                    if (timeConvert != 0)
                    {
                        var listProduct = productsRepository.getLastProduct();
                        var stock       = new Stock {
                            Quantity = quantity, ProductId = listProduct.Id, Expiry = timeConvert
                        };
                        stockRepository.AddStock(stock);
                        AskKeyPress();
                    }
                    else
                    {
                        Echo("La date à mal été rentrée, veuillez réessayer");
                        AskKeyPress();
                    }
                } catch (Exception e)
                {
                    Style.SelectColor(ConsoleColor.Red);
                    Echo("Impossible d'ajouter le stock en base");
                    //TODO Message d'erreur ?
                    Echo("Message d'erreur");
                    Echo(e.Message);
                    Style.SelectColor(ConsoleColor.White);
                    AskKeyPress();
                    return;
                }
            }
            else
            {
                Clear();
                Style.Yellow("La création de produit a été annulée.", true);
                AskKeyPress();
            }
        }