Example #1
0
        public static async Task <IActionResult> QueryByStore(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/company/{companyCode}/store/{storeCode}/query")]
            HttpRequest req,
            string companyCode,
            string storeCode,
            ILogger log)
        {
            using (var context = new StockDbContext())
            {
                var items = await context.Stocks
                            .Where(x => x.CompanyCode == companyCode && x.StoreCode == storeCode && x.TransactionType != TransactionType.引当)
                            .GroupBy(x => new { x.TerminalCode, x.ItemCode })
                            .Select(x => new QueryByStoreResult {
                    TerminalCode = x.Key.TerminalCode, ItemCode = x.Key.ItemCode, Quantity = x.Sum(xs => xs.Quantity)
                })
                            .ToArrayAsync();

                var response = new QueryResponse <QueryByStoreResult>
                {
                    Items = items
                };

                return(new OkObjectResult(response));
            }
        }
 public OrderCreatedHandler(StockDbContext dbContext, ILogger <OrderCreatedHandler> logger,
                            IKafkaMessageProducer kafkaMessageProducer)
 {
     _dbContext            = dbContext;
     _logger               = logger;
     _kafkaMessageProducer = kafkaMessageProducer;
 }
Example #3
0
        public static async Task <IActionResult> QueryByItem(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/company/{companyCode}/store/{storeCode}/terminal/{terminalCode}/item/{itemCode}/query")]
            HttpRequest req,
            string companyCode,
            string storeCode,
            string terminalCode,
            string itemCode,
            ILogger log)
        {
            using (var context = new StockDbContext())
            {
                var item = await context.Stocks
                           .Where(x => x.CompanyCode == companyCode && x.StoreCode == storeCode &&
                                  x.TerminalCode == terminalCode && x.ItemCode == itemCode && x.TransactionType != TransactionType.引当)
                           .GroupBy(x => x.ItemCode)
                           .Select(x => new QueryByItem {
                    ItemCode = x.Key, Quantity = x.Sum(xs => xs.Quantity)
                })
                           .FirstOrDefaultAsync();

                var response = item ?? new QueryByItem {
                    ItemCode = itemCode, Quantity = 0
                };

                return(new OkObjectResult(response));
            }
        }
        public void SyncLocalDatabaseWithServer()
        {
            StockDbContext localContext  = new StockDbContext("Data Source= .\\;Initial Catalog=StockDb;Persist Security Info=True;User ID=ayoobfar_ali;Password=119801;MultipleActiveResultSets=true");
            StockDbContext serverContext = new StockDbContext("Data Source = www.elecontrol.ir\\MSSQLSERVER2019; Initial Catalog = elecont1_data; Persist Security Info = True; User ID = elecont1_nejati; Password = Ali11980*; MultipleActiveResultSets = true");

            List <SymbolGroup> localSymbolGroup  = localContext.SymbolGroups.ToList();
            List <SymbolGroup> serverSymbolGroup = serverContext.SymbolGroups.ToList();

            foreach (SymbolGroup symbol in localSymbolGroup)
            {
                if (!serverSymbolGroup.Any(s => s.Id == symbol.Id))
                {
                    serverContext.SymbolGroups.Add(symbol);
                }
            }

            List <Symbol> localSymbol  = localContext.Symbols.ToList();
            List <Symbol> serverSymbol = serverContext.Symbols.ToList();

            foreach (Symbol symbol in localSymbol)
            {
                if (!serverSymbol.Any(s => s.Id == symbol.Id))
                {
                    serverContext.Symbols.Add(symbol);
                }
            }



            int numberOfChanges = serverContext.SaveChanges();

            return;
        }
Example #5
0
 public StockController(IConfiguration configuration, IHttpClientFactory httpClientFactory, StockDbContext context)
 {
     _secretToken        = configuration.GetSection("ApiKeys")["SecretKey"];
     _client             = httpClientFactory.CreateClient();
     _client.BaseAddress = new Uri("https://cloud.iexapis.com/stable/");
     _context            = context;
 }
Example #6
0
 public StockService(IStockRepo stockRepo, IStockExchangeApi stockExchangeApi,
                     StockDbContext db)
 {
     _stockRepo        = stockRepo;
     _stockExchangeApi = stockExchangeApi;
     _db = db;
 }
 public CreateStockForProductHandler(
     StockDbContext context,
     IBus bus)
 {
     this.context = context;
     this.bus     = bus;
 }
Example #8
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            StockDbContext stockDbContext = new StockDbContext();
            Shareholder    shareholder    = listShareholder.Find(s => s.Name == comboBoxName.SelectedItem.ToString());
            Symbol         stockInfo      = listSymbol.Find(s => s.NamePersian == comboBoxStockInfo.SelectedItem.ToString());

            TradeType tradeType     = radioButtonBuy.Checked ? TradeType.Buy : TradeType.Sell;
            int       volume        = int.Parse(textBoxVolume.Text);
            double    pricePerShare = double.Parse(textBoxPricePerShare.Text);
            double    totalPrice    = double.Parse(textBoxTotalPrice.Text);
            DateTime  date          = dateTimePicker1.Value.Date;

            StockTrading newStockTrading = new StockTrading();

            newStockTrading.ShareholderId = shareholder.Id;
            newStockTrading.SymbolId      = stockInfo.Id;
            newStockTrading.TradeType     = tradeType;
            newStockTrading.Volume        = volume;
            newStockTrading.PricePerShare = pricePerShare;
            newStockTrading.TotalPrice    = totalPrice;
            newStockTrading.Date          = date;

            try
            {
                stockDbContext.StockTradings.Add(newStockTrading);
                stockDbContext.SaveChanges();
                labelMessage.Text = "OK" + DateTime.Now.ToLongTimeString();
            }
            catch (Exception ex)
            {
                labelMessage.Text = ex.Message;
            }
        }
        private void Asset_Form_Load(object sender, EventArgs e)
        {
            this.con          = new StockDbContext();
            this.stockResult  = getStockList();
            this.symbolResult = getSymbolList();
            this.stockTotal   = getTotal(stockResult);
            // this.dividendTotal = getTotal(dividendResult);

            setRateDefault();
            setTotalMoney(this.yen, this.usd);

            setDgv(dataGridView1, this.symbolResult);
            setDgv(dataGridView2, this.stockResult);

            chart1.DataSource                 = this.symbolResult;
            chart2.DataSource                 = this.symbolResult;
            chart2.Series[0].Label            = "#PERCENT{P2}";
            chart2.Series[0].LegendText       = "#VALX";
            chart2.Series[0]["PieLabelStyle"] = "Outside";
            chart2.Series[0].BorderColor      = System.Drawing.Color.FromArgb(0, 0, 0);
            chart2.Series[0].BorderWidth      = 1;


            Utilities.setRowNumber(dataGridView1);
            Utilities.setRowNumber(dataGridView2);
        }
Example #10
0
 public bool Update(CategoryModel entity)
 {
     try
     {
         using (StockDbContext context = new StockDbContext())
             using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
             {
                 var category = unitofwork.GetRepository <Category>().GetById(entity.CategoryId);
                 category.CategoryName = entity.CategoryName;
                 category.Description  = entity.Description;
                 unitofwork.GetRepository <Category>().Update(category);
                 int saveCount = unitofwork.SaveChanges();
                 if (saveCount == 0)
                 {
                     return(false);
                 }
                 return(true);
             }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
Example #11
0
        public EfUnitOfWork(StockDbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("boş");
            }

            _dbContext = dbContext;
        }
Example #12
0
        public EfTransactionRepository(StockDbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext boş");
            }

            _dbContext  = dbContext;
            _repository = new EfRepository <T>(_dbContext);
        }
Example #13
0
        private void initComboboxName()
        {
            StockDbContext stockDbContext = new StockDbContext();

            listShareholder = stockDbContext.Shareholders.ToList();
            foreach (Shareholder s in listShareholder)
            {
                comboBoxName.Items.Add(s.Name);
            }
        }
Example #14
0
 public EmployeeModel GetById(Guid id)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             var           employee      = unitOfWork.GetRepository <Employee>().GetById(id);
             EmployeeModel employeeModel = StockMapper.EmployeeModelMap(employee);
             return(employeeModel);
         }
 }
Example #15
0
        public EfRepository(StockDbContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext can not be null");
            }

            _dbContext = dbContext;
            _dbSet     = _dbContext.Set <T>();
        }
Example #16
0
        private void initComboboxSymbols()
        {
            StockDbContext stockDbContext = new StockDbContext();

            listSymbol = stockDbContext.Symbols.ToList();
            foreach (Symbol s in listSymbol)
            {
                comboBoxStockInfo.Items.Add(s.NamePersian);
            }
        }
Example #17
0
        private void initCumboboxGroup()
        {
            StockDbContext stockDbContext = new StockDbContext();

            customGroups = stockDbContext.CustomGroups.ToList();
            foreach (CustomGroup group in customGroups)
            {
                comboBoxGroup.Items.Add(group.Name);
            }
            comboBoxGroup.SelectedIndex = 0;
            comboBoxGroup_SelectedIndexChanged(null, null);
        }
Example #18
0
        private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            StockDbContext stockDbContext = new StockDbContext();

            comboBoxSymbol.Items.Clear();
            groupMembers = stockDbContext.CustomGroupMembers.Where(
                member => member.GroupId == customGroups[comboBoxGroup.SelectedIndex].Id).ToList();
            foreach (CustomGroupMember groupMember in groupMembers)
            {
                comboBoxSymbol.Items.Add(stockDbContext.Symbols.First(s => s.Id == groupMember.SymbolId).NamePersian);
            }
            comboBoxSymbol.SelectedIndex = 0;
            Symbol temp = GetSelectedSymbol();
        }
Example #19
0
 public bool Delete(Guid id)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
         {
             unitofwork.GetRepository <Employee>().Delete(id);
             int saveCount = unitofwork.SaveChanges();
             if (saveCount == 0)
             {
                 return(false);
             }
             return(true);
         }
 }
Example #20
0
 public bool Delete(OrderModel entity)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             Order order = StockMapper.OrderMap(entity);
             unitOfWork.GetRepository <Order>().Delete(order);
             int saveCount = unitOfWork.SaveChanges();
             if (saveCount == 0)
             {
                 return(false);
             }
             return(true);
         }
 }
Example #21
0
 public bool Delete(EmployeeModel entity)
 {
     using (StockDbContext context = new StockDbContext())
         using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
         {
             Employee employee = StockMapper.EmployeeMap(entity);
             unitOfWork.GetRepository <Employee>().Delete(employee);
             int saveCount = unitOfWork.SaveChanges();
             if (saveCount == 0)
             {
                 return(false);
             }
             return(true);
         }
 }
Example #22
0
        public void GetPortfolio(int shareholderId)
        {
            Dictionary <int, int> shareholderPortfolio = new Dictionary <int, int>();
            StockDbContext        stockDbContext       = new StockDbContext();
            List <StockTrading>   shareholderTrades    = stockDbContext.StockTradings.Where(stockTrading => stockTrading.ShareholderId == shareholderId).ToList();

            foreach (StockTrading stockTrading in shareholderTrades)
            {
                if (!shareholderPortfolio.ContainsKey(stockTrading.SymbolId))
                {
                    shareholderPortfolio.Add(stockTrading.SymbolId, 0);
                }
                shareholderPortfolio[stockTrading.SymbolId] += stockTrading.Volume;
            }
        }
        public void CanDownloadDataFromUrl()
        {
            //SymbolLiveData symbolLiveData = new SymbolLiveData("("http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=6110133418282108&c=44+");
            //http://www.tsetmc.com/tsev2/data/instinfofast.aspx?i=26014913469567886&c=39+

            StockDbContext     stockDbContext = new StockDbContext();
            List <Symbol>      symbols        = stockDbContext.Symbols.ToList();
            List <LiveDataUrl> liveDataUrls   = stockDbContext.LiveDataUrls.ToList();
            SymbolLiveData     symbolLiveData = new SymbolLiveData(liveDataUrls.First(a => a.SymbolId == 1).Url);
            Task <SymbolData>  symbolDataTask = symbolLiveData.GetLiveDataAsync();

            SymbolData symbolData = symbolDataTask.Result;

            Assert.That(symbolData.Time.Length > 1);
        }
Example #24
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            //todo get data from form fields and put it in the database
            StockDbContext    dbContext        = new StockDbContext();
            FormStockExchange newStockExchange = new FormStockExchange();

            try
            {
                newStockExchange.
                //dbContext.StockExchanges.Add(null);

                labelMessage.Text = "Done at " + DateTime.Now.ToString();
            }
            catch (Exception ex)
            {
            }
        }
        private void History_Form_Load(object sender, EventArgs e)
        {
            con = new StockDbContext();

            var query = from c in con.Stocks
                        where c.User == Utilities.User.Email
                        orderby c.CreateAt descending
                        select new DataBinding {
                Symbol = c.Symbol, Shares = c.Shares, CreateAt = c.CreateAt, Price = c.Price
            };

            con.Database.Log = Console.WriteLine;

            this.dataGridView1.DataSource = query.ToList();
            Utilities.setRowNumber(this.dataGridView1);
            Utilities.setDataGridViewOption(this.dataGridView1);
            this.lb_updatetime.Text = "Update : " + DateTime.Now;
        }
Example #26
0
        public List <CategoryModel> GetAlls()
        {
            using (StockDbContext context = new StockDbContext())
                using (IUnitOfWork unitOfWork = new EfUnitOfWork(context))
                {
                    var category = unitOfWork.GetRepository <Category>().GetAll();

                    List <CategoryModel> categoryModels = category.Select(s => new CategoryModel()
                    {
                        CategoryId   = s.CategoryId,
                        CategoryName = s.CategoryName,
                        Description  = s.Description,
                        Picture      = s.Picture
                    }).ToList();

                    return(categoryModels);
                }
        }
Example #27
0
        public void Can_Create_Text_File_For_Building_Table_Data()
        {
            StockDbContext dbContext = new StockDbContext();

            Symbol[] symbols = dbContext.Symbols.ToArray();

            string path = @"c:\temp\Symbol.txt";

            File.WriteAllText(path, "\\[StockDb].[stock].[Symbol]" + Environment.NewLine);


            foreach (Symbol symbol in symbols)
            {
                string newDataRow = $"INSERT INTO [StockDb].[stock].[Symbol]  VALUES ({symbol.Id} , '{symbol.SymbolPersian}','{ symbol.SymbolLatin}'" +
                                    $" '{symbol.NameLatin}' , '{symbol.NamePersian}' , {symbol.GroupId})";
                File.AppendAllText(path, newDataRow + Environment.NewLine);
            }
            Assert.That(symbols.Length > 0);
        }
Example #28
0
        public void Can_Create_Text_File_For_Building_Table_Data()
        {
            StockDbContext dbContext = new StockDbContext();

            SymbolGroup[] symbolGroups = dbContext.SymbolGroups.ToArray();

            string path = @"c:\temp\SymbolGroup.txt";

            File.WriteAllText(path, "\\[StockDb].[stock].[SymbolGroup]" + Environment.NewLine);


            foreach (SymbolGroup symbolGroup in symbolGroups)
            {
                string newDataRow = "INSERT INTO [StockDb].[stock].[StockGroup]  VALUES (" +
                                    symbolGroup.Id + ",'" + symbolGroup.Name + "')";
                File.AppendAllText(path, newDataRow + Environment.NewLine);
            }
            Assert.That(symbolGroups.Length > 0);
        }
Example #29
0
        public Model.Result.CustomerAddResult AddCustomer(CustomerAddRequest request)
        {
            CustomerAddResult result = new CustomerAddResult();

            try
            {
                if (request != null && request.CustomerModel != null)
                {
                    using (StockDbContext context = new StockDbContext())
                        using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
                        {
                            Customer customer = new Customer
                            {
                                CustomerId   = Guid.NewGuid(),
                                City         = request.CustomerModel.City,
                                CompanyName  = request.CustomerModel.CompanyName,
                                Address      = request.CustomerModel.Address,
                                Region       = request.CustomerModel.Region,
                                Phone        = request.CustomerModel.Phone,
                                ContactTitle = request.CustomerModel.ContactTitle,
                                ContactName  = request.CustomerModel.ContactName,
                                PostalCode   = request.CustomerModel.PostalCode,
                                Country      = request.CustomerModel.Country,
                                Fax          = request.CustomerModel.Fax,
                            };
                            unitofwork.GetRepository <Customer>().Add(customer);
                            result.SaveCount = unitofwork.SaveChanges();
                            if (result.SaveCount > 0)
                            {
                                return(result);
                            }
                        }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(result);
        }
Example #30
0
        public bool Delete(CustomerModel entity)
        {
            try
            {
                if (entity != null)
                {
                    using (StockDbContext context = new StockDbContext())
                        using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
                        {
                            Customer customer = new Customer
                            {
                                CustomerId   = Guid.NewGuid(),
                                City         = entity.City,
                                CompanyName  = entity.CompanyName,
                                Address      = entity.Address,
                                Region       = entity.Region,
                                Phone        = entity.Phone,
                                ContactTitle = entity.ContactTitle,
                                ContactName  = entity.ContactName,
                                PostalCode   = entity.PostalCode,
                                Country      = entity.Country,
                                Fax          = entity.Fax,
                            };

                            unitofwork.GetRepository <Customer>().Delete(customer);
                            int saveCount = unitofwork.SaveChanges();
                            if (saveCount == 0)
                            {
                                return(false);
                            }
                            return(true);
                        }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(true);
        }