public IActionResult Get([FromBody] StockRequest request) { return(Ok(new Response() { Success = true, Message = "NotImplemented" })); }
public async Task <IActionResult> Edit(int id, [Bind("Quantity, ApprovalStatus")] StockRequest stockRequest) { if (id != stockRequest.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(stockRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockRequestExists(stockRequest.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(stockRequest)); }
private static async Task Main() { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); using (var channel = GrpcChannel.ForAddress("http://localhost:5012")) { var stockMarketService = channel.CreateGrpcService <IStockMarketService>(); while (true) { Console.WriteLine("Symbol: "); string symbol = Console.ReadLine(); if (String.IsNullOrWhiteSpace(symbol)) { break; } var request = new StockRequest { Symbol = symbol }; var stockResult = await stockMarketService.GetStockAsync(request); foreach (var stock in stockResult.Stocks) { PrintStockInfo(stock); } } } Console.WriteLine("Press a key to exit"); Console.ReadKey(); }
public void UpdateStock_SeeUpdated() { // Arrange // Create sample data var testData = new StockDB { Name = "test-Stock", Price = 1000, LastUpdated = "09/04/2020 10:36:52" }; var stockRequest = new StockRequest { Name = "test-Stock", Price = 2000, }; // Act // Test if mapper returns with updated price var result = _mapper.ToStockDBModel(testData, stockRequest); // Assert Assert.AreEqual(2000, result.Price); }
public async Task <IActionResult> Edit(int id, [Bind("StockRequestID,StoreID,ProductID,Quantity")] StockRequest stockRequest) { if (id != stockRequest.StockRequestID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(stockRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockRequestExists(stockRequest.StockRequestID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", stockRequest.ProductID); ViewData["StoreID"] = new SelectList(_context.Stores, "StoreID", "StoreID", stockRequest.StoreID); return(View(stockRequest)); }
public void Mapper_ToStockDBModel_ReturnsStockDB() { // Arrange StockRequest stockDB = new StockRequest { Name = "SendStockTest", Price = 123.45f }; var expectedStockDB = new StockDB(); expectedStockDB.Name = "SendStockTest"; expectedStockDB.Price = 123.45f; expectedStockDB.LastUpdated = System.DateTime.Now.ToString(); var mapper = new Mapper(); StockDB result; // Act result = mapper.ToStockDBModel(stockDB); // Assert Assert.AreEqual(expectedStockDB.Name, result.Name); Assert.AreEqual(expectedStockDB.Price, result.Price); }
public void Mapper_ToStockDBModelOverride_ReturnsStockDB() { // Arrange string currentTime = System.DateTime.Now.ToString(); StockDB stockDB = new StockDB { Name = "StockDBName", Price = 111.22f, LastUpdated = currentTime }; StockRequest stockRequest = new StockRequest { Name = "StockRequestName", Price = 222.33f }; var expectedStockDB = new StockDB(); expectedStockDB.Name = "StockDBName"; expectedStockDB.Price = 222.33f; expectedStockDB.LastUpdated = currentTime; var mapper = new Mapper(); StockDB result; // Act result = mapper.ToStockDBModel(stockDB, stockRequest); // Assert Assert.AreEqual(expectedStockDB.Name, result.Name); Assert.AreEqual(expectedStockDB.Price, result.Price); }
public async Task <IActionResult> AddItem([Bind("StoreID,ProductID,Quantity")] StockRequest stockRequest) { if (ModelState.IsValid) { try { _context.StockRequests.Add(stockRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } //*** Should Add Successful information return(RedirectToAction(nameof(Index))); } ViewData["StoreID"] = stockRequest.StoreID; IEnumerable <Product> currentProducts = _context.StoreInventories.Include(i => i.Product) .Where(i => i.StoreID == stockRequest.StoreID).Select(i => i.Product); var newProducts = _context.Products.Except(currentProducts); ViewData["ProductID"] = new SelectList(newProducts, "ProductID", "Name", stockRequest.ProductID); return(View()); }
public async ValueTask <StockStats> GetStatisticsAsync(StockRequest request) { var cacheKey = $"{request.Symbol}_{request.Region}"; if (!_cache.TryGetValue(cacheKey, out StockStats? stats)) { // key not in cache, so fetch data var queryString = $"?symbol={request.Symbol}®ion={request.Region}"; var response = await _httpClient.GetAsync(queryString); response.EnsureSuccessStatusCode(); stats = await response.Content.ReadFromJsonAsync <StockStats>(); var cacheEntryOptions = new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(_stockOptions.CacheDurationInMinutes) }; // save data to cache _cache.Set(cacheKey, stats, cacheEntryOptions); } return(stats !); }
public Task <Stock> GetStock(StockRequest request) { var stock = new Stock(); try { List <string> headers; List <string> values; (headers, values) = SplitCSV(GetCSV(_settings.StockWebServiceUrl.Replace("{stock_code}", request.StockCode))); stock.Symbol = values[headers.IndexOf("Symbol")]; NumberFormatInfo formatProvider = new NumberFormatInfo { NumberDecimalSeparator = "." }; stock.DateTime = DateTime.ParseExact(values[headers.IndexOf("Date")] + " " + values[headers.IndexOf("Time")], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); stock.Open = Convert.ToDouble(values[headers.IndexOf("Open")], formatProvider); stock.Close = Convert.ToDouble(values[headers.IndexOf("Close")], formatProvider); stock.High = Convert.ToDouble(values[headers.IndexOf("High")], formatProvider); stock.Low = Convert.ToDouble(values[headers.IndexOf("Low")], formatProvider); stock.Volume = Convert.ToDouble(values[headers.IndexOf("Volume")], formatProvider); } catch (Exception) { } return(Task.FromResult(stock)); }
public void ProcessRequest(int id) { StockRequest toRemove = null; foreach (var request in list) // interate stockRequests { if (request.Id == id && request.GetAvailability() == true) { // found correct stock request var il = inventory.GetInventoryList(); foreach (var item in il) { if (item.Name.Equals(request.Product)) { toRemove = request; // update store qty UpdateStore(request); // decrement owner qty UpdateOwner(request); } } } } list.Remove(toRemove); WriteStockRequest(); //return false; }
public async Task <IActionResult> MakeStockRequest([Bind("StoreID,ProductID,Quantity")] StockRequest stockRequest) { if (ModelState.IsValid) { FetchStore(); stockRequest.StoreID = Store.StoreID; _context.Add(stockRequest); // if this product wasn't previously in stock, add it to the store stock with quantity 1 if (!Store.StoreInventoryList.Any(si => si.ProductID == stockRequest.ProductID)) { _context.Add(new StoreInventory { StoreID = Store.StoreID, Product = _context.Products.Find(stockRequest.ProductID), StockLevel = 1 }); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockRequest)); }
public async Task <IActionResult> NewRequest(int ProductID, [Bind("StoreID,ProductID,StockLevel")] StoreInventory StoreInventory) { if (ProductID != StoreInventory.ProductID) { return(NotFound()); } if (ModelState.IsValid) { var newRequest = new StockRequest(); newRequest.ProductID = ProductID; newRequest.StoreID = StoreInventory.StoreID; newRequest.Quantity = StoreInventory.StockLevel; try { _context.StockRequests.Add(newRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } return(RedirectToAction(nameof(StoreInventory))); } StoreInventory.Product = await _context.Products.SingleOrDefaultAsync(m => m.ProductID == ProductID); StoreInventory.Store = await _context.Stores.SingleOrDefaultAsync(s => s.StoreID == StoreInventory.StoreID); return(View(StoreInventory)); }
public async Task <IActionResult> AddNewItem(int id, [Bind("ProductID,Quantity,StoreID")] StockRequest StockRequest) { if (id != StockRequest.ProductID) { return(NotFound()); } var StoreID = CheckStoreID(); StockRequest.StoreID = StoreID; if (ModelState.IsValid) { try { _context.Add(StockRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } return(RedirectToAction(nameof(NewItemRequest))); } StockRequest.Product = await _context.Products.SingleOrDefaultAsync(m => m.ProductID == id); return(View(StockRequest)); }
public async Task UpdateStock(StockRequest stockRequest) { var response = await _stockTradingRepository.GetItem(stockRequest.Name); var result = _mapper.ToStockDBModel(response, stockRequest); await _stockTradingRepository.UpdateStock(result); }
/// <summary> /// Indexes this instance. /// </summary> /// <param name="parametersSearch">The parameters search.</param> /// <param name="pageSizeString">The page size string.</param> /// <param name="page">The page.</param> /// <returns></returns> public async Task <IActionResult> Index(string parametersSearch, string pageSizeString, int page) { int pageSize = 20; page = page > 0 ? page : 1; if (!string.IsNullOrEmpty(pageSizeString)) { pageSize = int.Parse(pageSizeString); } StockRequest request = new StockRequest() { Page = new PagingRequest() { PageIndex = page - 1, PageSize = pageSize } }; try { StockListViewModel model = null; if (!string.IsNullOrEmpty(parametersSearch)) { request = JsonConvert.DeserializeObject <StockRequest>(parametersSearch); } request.Page = new PagingRequest() { PageIndex = page - 1, PageSize = pageSize }; var result = await this.PostAsync <BaseModel <Stock> >(HttpUriFactory.GetStocksRequest(this.options.Value.APIUrl), request); if (result != null) { int pageCount = (result.TotalCount + pageSize - 1) / pageSize; var nextPage = page == pageCount ? page : (page + 1); var previousPage = page > 1 ? (page - 1) : page; model = this.CreateDefaultVM <StockListViewModel, StockRequest>(request, parametersSearch, page, pageSize, nextPage, previousPage, pageCount, "Stock", "Index"); model.Templates = result.Models; } else { model = this.CreateDefaultVM <StockListViewModel, StockRequest>(request, parametersSearch, page, pageSize, 1, 1, 1, "Stock", "Index"); } if (TempData["Message"] != null) { ViewBag.Message = TempData["Message"]; } return(View(model)); } catch (Exception ex) { ViewBag.Message = ex.Message; Utilities.LogAppError(this.logger, ex); return(View(this.CreateDefaultVM <StockListViewModel, StockRequest>(request, parametersSearch, page, pageSize, 1, 1, 1, "Stock", "Index"))); } }
public override async Task <StockData> GetStock(StockRequest request, ServerCallContext context) { var token = context.CancellationToken; var stock = await _stockService.SearchStock(request.Symbol, request.Date.ToDateTime(), token); await Task.Delay(2000); // look busy return(stock.ToStockData()); }
public StockDB ToStockDBModel(StockDB stockDB, StockRequest stockRequest) { return(new StockDB { Name = stockDB.Name, Price = stockRequest.Price, LastUpdated = DateTime.UtcNow.ToString() }); }
public void LoadStockRequests() { //users = Models.User.GetAll(); stockRequests = StockRequest.GetAll(); this.flpStockRequests.Controls.Clear(); stockRequests.ForEach(stockrequest => { if (stockrequest.Completed == 0) { var btn = new Button(); btn.BackColor = SystemColors.ControlLightLight; btn.Width = this.flpStockRequests.Width - 30; btn.Height = 60; btn.Text = $"Stock Request ({stockrequest.Id}) : Product: {stockrequest.Product.Name} -> {stockrequest.Quantity} pieces"; btn.Font = new Font("Segoe UI Black", 12); btn.TextAlign = ContentAlignment.MiddleLeft; btn.MouseEnter += new EventHandler((s, ev) => { btn.BackColor = SystemColors.ControlLight; btn.Cursor = Cursors.Hand; }); btn.MouseLeave += new EventHandler((s, ev) => { btn.BackColor = SystemColors.ControlLightLight; }); //Open a ViewStockRequestForm for this stockrequest when clicking on it btn.Click += new EventHandler((s, ev) => { ViewStockRequestForm form = new ViewStockRequestForm(stockrequest); form.Show(); this.Close(); }); this.flpStockRequests.Controls.Add(btn); } }); if (StockRequest.GetAllPendingRequests().Count == 0) { var btn = new Button(); btn.BackColor = SystemColors.ControlLightLight; btn.Width = this.flpStockRequests.Width - 30; btn.Height = 60; btn.Text = $"No stock requests"; btn.Font = new Font("Segoe UI Black", 12); btn.TextAlign = ContentAlignment.MiddleCenter; this.flpStockRequests.Controls.Add(btn); } }
public async Task <IActionResult> Create([Bind("StoreID, ProductID, Quantity")] StockRequest stockRequest) { if (ModelState.IsValid) { _context.Add(stockRequest); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(StoreStockRequests))); } return(View()); }
public IActionResult GetStocks([FromBody] StockRequest request) { try { return(Ok(this.stockManager.GetStocks())); } catch (Exception ex) { Utilities.LogAppError(this.logger, ex); return(BadRequest(ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } }
public async Task <IActionResult> Create(Order order) { bool isValidOrder = true; foreach (var orderItem in order.OrderItems) { using (HttpClient client = new HttpClient()) { var stockRequest = new StockRequest { ItemId = orderItem.ItemId }; var content = new StringContent(JsonConvert.SerializeObject(stockRequest), Encoding.UTF8, "application/json"); var response = client.PostAsync(_configuration["StockService"], content).Result; var stockResponse = JsonConvert.DeserializeObject <StockResponse>(await response.Content.ReadAsStringAsync()); if (orderItem.Qty > stockResponse.Stock) { isValidOrder = false; break; } } } if (isValidOrder) { //Send shipment using (HttpClient client = new HttpClient()) { var shipmentRequest = new ShipmentRequest { CustomerEmail = order.Customer.Email, CustomerName = order.Customer.Name, OrderId = order.OrderNr, ShipmentItems = order.OrderItems.Select(o => new ShipmentItem { ItemId = o.ItemId, Qty = o.Qty }).ToList() }; var content = new StringContent(JsonConvert.SerializeObject(shipmentRequest), Encoding.UTF8, "application/json"); var result = await client.PostAsync(_configuration["ShipmentService"], content); } return(Ok()); } else { return(BadRequest("No stock available")); } }
public async Task <IActionResult> Create([Bind("StockRequestID,StoreID,ProductID,Quantity")] StockRequest stockRequest) { if (ModelState.IsValid) { _context.Add(stockRequest); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", stockRequest.ProductID); ViewData["StoreID"] = new SelectList(_context.Stores, "StoreID", "StoreID", stockRequest.StoreID); return(View(stockRequest)); }
public async Task <IActionResult> Create([Bind("Id, ProductId, StaffId, Quantity, ApprovalStatus")] StockRequest stockRequest) { if (ModelState.IsValid) { stockRequest.ProductId = 1; stockRequest.StaffId = 1; _context.Add(stockRequest); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockRequest)); }
public async Task <IActionResult> SellStock([FromBody] StockRequest request) { try { var accessToken = Request.Headers["Authorization"]; var response = await _service.SELL(request, accessToken); return(Ok(response)); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <IEnumerable <ChatRoomMessageDto> > ProcessHubMessage(HubMessageDto hubMessage) { var chatRoomMessageDto = _mapper.Map <ChatRoomMessageDto>(hubMessage); var responseMessages = new List <ChatRoomMessageDto>(); responseMessages.Add(chatRoomMessageDto); // if (hubMessage.IsCommandMessage) { switch (hubMessage.CommandName) { case SupportedBotCommands.STOCK: if (string.IsNullOrEmpty(hubMessage.CommandParameter)) { goto default; } var request = new StockRequest { StockCode = hubMessage.CommandParameter, RequestedBy = hubMessage.FromUser, ConnectionId = hubMessage.ConnectionId }; await _stockRequesterService.RequestStock(request); break; default: var message = string.IsNullOrEmpty(hubMessage.CommandParameter) ? "Command parameter cannot be empty." : "Sorry but I don't know that command. Try something like /stock={symbol}"; responseMessages .Add(new ChatRoomMessageDto { ChatRoomCode = hubMessage.ChatRoomCode, ChatRoomId = hubMessage.ChatRoomId, FromUser = "******", OcurredAt = DateTimeOffset.UtcNow, MessageText = message }); break; } return(responseMessages); } await _chatRoomMessageService.Create(chatRoomMessageDto); return(responseMessages); }
public async Task <IActionResult> DeleteConfirmed(int id) { StockRequest s = await _context.StockRequests.SingleOrDefaultAsync(m => m.StockRequestID == id); bool available = await owner.IsStockAvailable(s); if (available) { //_context.StockRequests.Remove(s); await owner.PerformStockRequest(s); } //_context.StockRequests.Remove(stockRequest); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ViewStockRequestForm(StockRequest stockRequest) { this.currentstockRequest = stockRequest; InitializeComponent(); this.BackColor = ApplicationColors.PrimaryDark; this.btnFulfillRequest.BackColor = ApplicationColors.Red; lblProductTag.BackColor = ApplicationColors.LightOrange; lblQuantityTag.BackColor = ApplicationColors.LightOrange; lblWorkerTag.BackColor = ApplicationColors.LightOrange; this.lblItemName.Text = stockRequest.Product.Name; this.lblItemQuantity.Text = stockRequest.Quantity.ToString(); this.lblWorker.Text = stockRequest.User.Name; }
public IActionResult AddNewItem(int?id) { if (id == null || id > 10) { return(NotFound()); } var StoreID = CheckStoreID(); var NewRequest = new StockRequest(); NewRequest.StoreID = StoreID; NewRequest.Product = _context.Products.Single(x => x.ProductID == id); NewRequest.ProductID = (int)id; NewRequest.Quantity = 0; return(View(NewRequest)); }
public void StockWebServiceTest2() { var stockRequest = new StockRequest { StockCode = "aapl.US" }; Stock stock = _stockWS.GetStock(stockRequest).Result; _output.WriteLine(JsonSerializer.Serialize(stock, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true })); Assert.True(stock.Open > 0); }
public async Task UpdateStockAsync( StockRequest request ) { Guid traderId = request.TraderId; if( !this.userStocks.ContainsKey( traderId ) ) { ITraderGrain trader = GrainFactory.GetGrain<ITraderGrain>( traderId ); await trader.FollowStockAsync( this ); this.userStocks.Add( traderId, new HashSet<Stock>() ); } var stocks = request.Stocks; foreach( Stock stock in stocks ) { this.userStocks[traderId].Add( stock ); var quota = await this.GetQuotaAsync( stock ); stock.Quota = quota; } this.subscribers.Notify( notification => notification.UpdateStocks( request.Stocks ) ); }
// protected IList _stockRequestsFrom = new ArrayList(); public void AddStockRequestFrom(StockRequest stockRequest) { stockRequest.BranchFrom = this; _stockRequestsFrom.Add(stockRequest); }
// protected IList _stockRequestsTo = new ArrayList(); public void AddStockRequestTo(StockRequest stockRequest) { stockRequest.BranchTo = this; _stockRequestsTo.Add(stockRequest); }
public StockRequestEntry( Product strItemCode, int nQuantity, StockRequest stockRequest ) { this._strItemCode = strItemCode; this._nQuantity = nQuantity; this._stockRequest = stockRequest; }