public void SellAndBuyShares(int firstClientID, int secondClientID, ClientsSharesEntity shareType, int numberOfSoldShares) { if (numberOfSoldShares > shareType.Amount) { throw new ArgumentException($"Cannot sell {numberOfSoldShares} that more than client have {shareType.Amount}"); } if (firstClientID == secondClientID) { throw new ArgumentException($"Cannot sell shares to yourself"); } ClientsSharesInfo sharesInfo = new ClientsSharesInfo() { ClientID = shareType.ClientID, ShareID = shareType.ShareID, Amount = -numberOfSoldShares }; clientsSharesService.ChangeClientsSharesAmount(sharesInfo); sharesInfo.Amount *= -1; sharesInfo.ClientID = secondClientID; clientsSharesService.ChangeClientsSharesAmount(sharesInfo); decimal shareCost = (decimal)shareService.GetAllShares().Where(x => x.ShareID == shareType.ShareID).Select(x => x.ShareCost).FirstOrDefault(); clientService.ChangeMoney(firstClientID, shareCost * numberOfSoldShares); clientService.ChangeMoney(secondClientID, -(shareCost * numberOfSoldShares)); }
public ActionResult <StatisticsViewModel <IEnumerable <ShareViewModel> > > Get() { var dto = new StatisticsDTO(); var data = service.GetAllShares(dto).Select(p => Mapper.Map <ShareViewModel>(p)).ToList(); var statistics = Mapper.Map <StatisticsViewModel <IEnumerable <ShareViewModel> > >(dto); statistics.Data = data; return(statistics); }
public void Initialize() { clientService = Substitute.For <IClientService>(); shareService = Substitute.For <IShareService>(); clientsSharesService = Substitute.For <IClientsSharesService>(); shareService.GetAllShares().Returns(new List <ShareEntity>() { new ShareEntity() { ShareID = 1, ShareCost = 10 } }); }
private void processUserInput(string userInput) { string[] splitedUserInput = userInput.Split(' ', '\t', ';'); switch (splitedUserInput[0].ToLower()) { case "addclient": ClientRegistrationInfo clientInfo = new ClientRegistrationInfo() { FirstName = splitedUserInput[1], LastName = splitedUserInput[2], PhoneNumber = splitedUserInput[3] }; registerEntity(validator.ValidateClientInfo, clientService.RegisterClient, clientInfo); break; case "addshare": ShareRegistrationInfo shareInfo = new ShareRegistrationInfo() { Name = splitedUserInput[1], Cost = decimal.Parse(splitedUserInput[2]) }; registerEntity(validator.ValidateShareInfo, shareService.RegisterShare, shareInfo); break; case "changesharestoclient": ClientsSharesInfo clientsShareInfo = new ClientsSharesInfo() { ClientID = int.Parse(splitedUserInput[1]), ShareID = int.Parse(splitedUserInput[2]), Amount = int.Parse(splitedUserInput[3]) }; registerEntity(validator.ValidateShareToClient, clientsSharesService.ChangeClientsSharesAmount, clientsShareInfo); break; case "changeclientmoney": changeClientsMoney(splitedUserInput); break; case "showorange": showClientsList(clientService.GetClientsFromOrangeZone()); break; case "showblack": showClientsList(clientService.GetClientsFromBlackZone()); break; case "showfullclients": showClientsList(clientService.GetAllClients()); break; case "showfullshares": var fullList = shareService.GetAllShares(); logger.WriteInfo(phraseProvider.GetPhrase("ShareHeader")); foreach (ShareEntity share in fullList) { string sharesInfo = $"{share.ShareID.ToString()} {share.ShareName} {share.ShareCost.ToString()}"; logger.WriteInfo(sharesInfo); } logger.WriteInfo("Successfully showed full share list"); break; case "help": logger.WriteInfo(phraseProvider.GetPhrase("Help")); break; case "e": break; default: logger.WriteWarn("Unknown command"); return; } }
public void FindSellOffers(BuyOfferDTO buyOffer, UserDTO currentUser, StatisticsDTO statistics) { if (currentUser.Value < buyOffer.Amount * buyOffer.Price) { return; } var offers = _sellOfferService.GetAll(statistics).Where(o => o.Price <= buyOffer.Price).OrderBy(o => o.Price); foreach (var offer in offers) { int tradedAmount; if (buyOffer.Amount < offer.Amount) { var price = offer.Amount * offer.Price; offer.Amount -= buyOffer.Amount; tradedAmount = buyOffer.Amount; var targetUser = _userService.GetUserById(offer.SellerId, statistics); //money got exchanged targetUser.Value += price; currentUser.Value -= price; currentUser.Password = null; targetUser.Password = null; _userService.EditUser(currentUser.Id, currentUser, statistics); _userService.EditUser(targetUser.Id, targetUser, statistics); //shares were taken from source var targetedShare = _shareService.GetShareById(offer.ShareId, statistics); targetedShare.Amount -= buyOffer.Amount; _shareService.EditShare(targetedShare.Id, targetedShare, statistics); //if current user has company share add them if not create entry for them var currentUserShare = _shareService.GetAllShares(statistics).Where(c => c.OwnerId == currentUser.Id).Where(c => c.StockId == buyOffer.StockId).FirstOrDefault(); if (currentUserShare != null) { currentUserShare.Amount += buyOffer.Amount; _shareService.EditShare(currentUserShare.Id, currentUserShare, statistics); } else { currentUserShare = new ShareDTO { OwnerId = currentUser.Id, Amount = buyOffer.Amount, StockId = buyOffer.StockId, }; _shareService.AddShare(currentUserShare, statistics); } //Modify offer that we took shares from _sellOfferService.Edit(offer, statistics); buyOffer.Amount = 0; } else { var price = offer.Amount * offer.Price; buyOffer.Amount -= offer.Amount; tradedAmount = offer.Amount; var targetUser = _userService.GetUserById(offer.SellerId, statistics); //money got exchanged targetUser.Value += price; currentUser.Value -= price; currentUser.Password = null; targetUser.Password = null; _userService.EditUser(currentUser.Id, currentUser, statistics); _userService.EditUser(targetUser.Id, targetUser, statistics); //taking shares from seller offer var targetedShare = _shareService.GetShareById(offer.ShareId, statistics); targetedShare.Amount -= offer.Amount; _shareService.EditShare(targetedShare.Id, targetedShare, statistics); //giving shares to buyer var currentUserShare = _shareService.GetAllShares(statistics).Where(c => c.OwnerId == currentUser.Id).Where(c => c.StockId == buyOffer.StockId).FirstOrDefault(); if (currentUserShare != null) { currentUserShare.Amount += buyOffer.Amount; _shareService.EditShare(currentUserShare.Id, currentUserShare, statistics); } else { currentUserShare = new ShareDTO { OwnerId = currentUser.Id, Amount = buyOffer.Amount, StockId = buyOffer.StockId, }; _shareService.AddShare(currentUserShare, statistics); } //deleting offer _sellOfferService.Delete(offer.Id, statistics); } TransactionDTO transaction = new TransactionDTO { Amount = tradedAmount, Price = offer.Price, BuyerId = currentUser.Id, SellerId = offer.SellerId, StockId = buyOffer.StockId, Date = DateTime.Now }; _transactionService.Add(transaction, statistics); } if (buyOffer.Amount > 0) { buyOffer.BuyerId = currentUser.Id; _buyOfferService.Add(buyOffer, statistics); //freeze users money equivalent to amount of shares he wants to buy left after searching through the market currentUser.Value -= buyOffer.Amount * buyOffer.Price; currentUser.Password = null; _userService.EditUser(currentUser.Id, currentUser, statistics); } CalculatePriceChange(buyOffer.StockId, statistics); }
public ActionResult <IEnumerable <ShareDto> > Get() { var shareDtos = _shareService.GetAllShares(); return(shareDtos.ToList()); }
// GET: Share public ActionResult Index() { var l = shse.GetAllShares(); return(View(l)); }
public ActionResult Index() { // Default Dictionaries Dictionary <string, double> dictAccounts = new Dictionary <string, double>() { { "accounts", 0 } }; ViewBag.PercentageAccounts = dictAccounts; Dictionary <string, double> dictTransactions = new Dictionary <string, double>() { { "transactions", 0 } }; ViewBag.PercentageTransactions = dictTransactions; Dictionary <string, double> dictInvoices = new Dictionary <string, double>() { { "invoices", 0 } }; ViewBag.PercentageInvoices = dictInvoices; Dictionary <string, double> dictShares = new Dictionary <string, double>() { { "shares", 0 } }; ViewBag.PercentageShares = dictShares; Dictionary <string, double> dictBrokers = new Dictionary <string, double>() { { "brokers", 0 } }; ViewBag.PercentageBrokers = dictBrokers; /***********************************/ List <Accounts> totalAccounts = serviceAccounts.getAllAccount(); List <Transaction> totalTransactions = serviceTransactions.GetMany().ToList(); List <invoice> totalInvoices = serviceInvoices.getAllInvoices(); List <share> totalShares = serviceShares.GetAllShares(); List <broker> totalBrokers = serviceBrokers.GetAllBrokers(); // Totals int totalLoans = serviceLoans.GetLoans().Count(); ViewBag.totalLoans = totalLoans; ViewBag.idLastLoan = null; if (totalLoans != 0) { ViewBag.idLastLoan = totalLoans; } //ViewBag.totalInvoices = serviceInvoices.GetMany().Count(); ViewBag.totalBrokers = totalBrokers.Count(); ViewBag.totalShares = totalShares.Count(); ViewBag.idLastAccount = null; ViewBag.idLastTransaction = null; // Review Last Link && ViewBag(dict<T>) if (totalAccounts.Count() != 0) { ViewBag.idLastAccount = totalAccounts.Last().Id; dictAccounts = getTauxAccounts(totalAccounts); if (dictAccounts.Count() != 0) { ViewBag.PercentageAccounts = dictAccounts; } } if (totalTransactions.Count() != 0) { ViewBag.idLastTransaction = totalTransactions.Last().Id; dictTransactions = getTauxTransactions(totalTransactions); if (dictTransactions.Count() != 0) { ViewBag.PercentageTransactions = dictTransactions; } } // Shares Fill if (totalShares.Count() != 0) { dictShares = getTauxShares(totalShares); if (dictShares.Count() != 0) { ViewBag.PercentageShares = dictShares; } } // Invoices Fill if (totalInvoices.Count() != 0) { dictInvoices = getTauxInvoices(totalInvoices); if (dictInvoices.Count() != 0) { ViewBag.PercentageInvoices = dictInvoices; } } // Brokers Fill if (totalBrokers.Count() != 0) { dictBrokers = getTauxBrokers(totalBrokers); if (dictBrokers.Count() != 0) { ViewBag.PercentageBrokers = dictBrokers; } } /***********************************/ return(View()); }