public async Task CreateOrder(Order order, bool alreadyCharged, bool useDBKey = false) { // New orders should only have one product order entry ProductOrderEntry entry = order.ProductOrderEntries.FirstOrDefault(); if (entry.ListingID != 0) { entry.Listing = listingRepository.GetListingByID(entry.ListingID); } DateTime date = DateTime.Now; order.SaleDate = date; String note = "Admin-created order"; ClaimedProductKey newKey = new ClaimedProductKey(); int priceToCharge = 0; if (order.ProductOrderEntries.Count() > 0) { priceToCharge = order.ProductOrderEntries.First().SalePrice; } if (useDBKey) { ProductKey key = GetProductKey(entry.ListingID); newKey = new ClaimedProductKey(key, order.AppUser, date, note); listingRepository.DeleteProductKey(key.ProductKeyID); unitOfWork.Save(); priceToCharge = newKey.Listing.SaleOrDefaultPrice(); entry.AddClaimedProductKey(newKey);//userRepository.InsertClaimedProductKey(newKey); } if (alreadyCharged == false) { BalanceEntry balanceEntry = new BalanceEntry(); balanceEntry.Date = date; balanceEntry.AppUser = order.AppUser; balanceEntry.Notes = note; balanceEntry.PointsAdjusted = priceToCharge; order.AppUser.Balance -= priceToCharge; //userRepository.UpdateAppUser(order.AppUser); //userRepository.InsertBalanceEntry(balanceEntry); order.AppUser.AddBalanceEntry(balanceEntry); } entry.SalePrice = priceToCharge; order.AppUser.AddOrder(order); //userRepository.InsertOrder(order); await userRepository.UpdateAppUser(order.AppUser); unitOfWork.Save(); }
public async Task DeleteBalanceEntry(int id) { BalanceEntry entry = userRepository.GetBalanceEntryByID(id); entry.AppUser.Balance -= entry.PointsAdjusted; await UserManager.UpdateAsync(entry.AppUser); userRepository.DeleteBalanceEntry(id); unitOfWork.Save(); }
public void UpdateBalanceEntry(BalanceEntry balanceEntry) { BalanceEntry targetBalanceEntry = context.BalanceEntries.Find(balanceEntry.BalanceEntryID); if (targetBalanceEntry != null) { targetBalanceEntry.PointsAdjusted = balanceEntry.PointsAdjusted; targetBalanceEntry.Notes = balanceEntry.Notes; targetBalanceEntry.UserID = balanceEntry.UserID; targetBalanceEntry.Date = balanceEntry.Date; } }
public async Task CreateBalanceEntry(BalanceEntry entry, int objectiveId) { if (objectiveId != 0) { entry.AddObjective(objectiveRepository.GetObjectiveByID(objectiveId)); if (entry.PointsAdjusted == 0) { entry.PointsAdjusted = entry.Objective.FixedReward(); } } entry.AppUser.Balance += entry.PointsAdjusted; await UserManager.UpdateAsync(entry.AppUser); entry.Date = DateTime.Now; userRepository.InsertBalanceEntry(entry); unitOfWork.Save(); }
private void saveButton_Click(object sender, EventArgs e) { try { if (!Regex.IsMatch(balanceTextBox.Text, "^[0-9]")) { throw new Exception("Digit Only!"); } BalanceEntry aBalanceEntry = new BalanceEntry(Convert.ToInt32(memberIdComboBox.Text), Convert.ToInt32(balanceTextBox.Text), dateTimePicker1.Value); string msg = aBalanceEntryBll.save(aBalanceEntry); MessageBox.Show(msg); showDataInDataGridView(); clearTextBoxes(); } catch (FormatException exception) { MessageBox.Show(@"Please enter balance in correct format.", exception.Message); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public void AddEntry(int accountId, decimal value) { var entry = new BalanceEntry (accountId, value); Entries.Add(entry); }
public async Task <IActionResult> GetBalance() { //Account var account = new List <BalanceEntry>(); // Some Options var displayOptions = Global.Configuration.DisplayOptions; // Get Exchange account var fullApi = Global.ExchangeApi.GetFullApi().Result; try { if (fullApi.PublicApiKey.Length > 0 && fullApi.PrivateApiKey.Length > 0) { // Get Tickers & Balances var tickers = await fullApi.GetTickersAsync(); var balances = await fullApi.GetAmountsAsync(); if (tickers.Count() > 1) { var tickerUsd = tickers.Where(t => t.Key.ToUpper().Contains("USD") && t.Key.ToUpper().Contains("BTC")).ToList(); var tickerDisplayCurrency = tickers.Where(t => t.Key.ToUpper().Contains(displayOptions.DisplayFiatCurrency) && t.Key.ToUpper().Contains("BTC")).ToList(); var usdToBtcTicker = tickerUsd.First(t => t.Key.EndsWith("BTC")); var btcToUsdTicker = tickerUsd.First(t => t.Key.StartsWith("BTC")); var dcTicker = new KeyValuePair <string, ExchangeTicker>(); if (tickerDisplayCurrency.Count == 0) { Global.Logger.Information("Account: Display currency at this exchange not available!"); } else { dcTicker = tickerDisplayCurrency.First(t => t.Key.StartsWith("BTC")); } // Calculate stuff foreach (var balance in balances) { // Get selected tickers for Balances var ticker = new List <KeyValuePair <string, ExchangeTicker> >(); // Create balanceEntry var balanceEntry = new BalanceEntry() { DisplayCurrency = displayOptions.DisplayFiatCurrency, Market = balance.Key, TotalCoins = balance.Value, BalanceInUsd = 0, BalanceInBtc = 0, BalanceInDisplayCurrency = 0 }; // Calculate to BTC or USD and check if crypto or not if (!balance.Key.ToUpper().Contains("USD") && !balance.Key.ToUpper().Contains("EUR")) { // Calculate to btc if (!balance.Key.ToUpper().Contains("BTC")) { ticker = tickers.Where(t => t.Key.ToUpper().StartsWith(balance.Key) && t.Key.ToUpper().Contains("BTC")) .ToList(); } } // Calculate to btc else { ticker = tickers.Where(t => t.Key.ToUpper().StartsWith(balance.Key) && t.Key.ToUpper().Contains("BTC")) .ToList(); } // Calculate special market USD, EUR, BTC if (balanceEntry.Market.ToUpper().Contains("USD") || balanceEntry.Market.ToUpper().Contains("EUR") || balanceEntry.Market.ToUpper().Contains("BTC")) { if (balanceEntry.Market.ToUpper().Contains("USD")) { balanceEntry.BalanceInUsd = balance.Value; balanceEntry.BalanceInBtc = balanceEntry.BalanceInUsd * usdToBtcTicker.Value.Last; } if (balanceEntry.Market.ToUpper().Contains("EUR")) { var t = ""; } if (balanceEntry.Market.ToUpper().Contains("BTC")) { balanceEntry.BalanceInBtc = balance.Value; balanceEntry.BalanceInUsd = balanceEntry.BalanceInBtc * btcToUsdTicker.Value.Last; } if (tickerDisplayCurrency.Count >= 1) { balanceEntry.BalanceInDisplayCurrency = balanceEntry.BalanceInBtc * dcTicker.Value.Last; } } // Calculate cryptos without btc else { if (ticker.Count >= 1) { balanceEntry.BalanceInBtc = (balance.Value * ticker[0].Value.Last); balanceEntry.BalanceInUsd = balanceEntry.BalanceInBtc * btcToUsdTicker.Value.Last; if (tickerDisplayCurrency.Count >= 1) { balanceEntry.BalanceInDisplayCurrency = balanceEntry.BalanceInBtc * dcTicker.Value.Last; } } else { Global.Logger.Error("Api has problem to find valid ticker for: " + balance.Key); } } // Add to list account.Add(balanceEntry); } } else { Global.Logger.Information("Possible problem with API, cuz we got no tickers!"); } } else { Global.Logger.Information("No api under configuration"); } } catch (Exception e) { Global.Logger.Error(e.InnerException.Message); } return(new JsonResult(account)); }
public void DrawAuctionWinners(int id) { Auction auction = GetAuctionByID(id); if (auction == null) { return; } if (auction.Winners?.Count > 0 || auction.IsOpen()) { return; } List <AuctionBid> winningBids = auction.WinningBids().ToList(); if (winningBids == null) { return; } auction.Winners = new HashSet <AppUser>(); List <string> keys = auction.GetKeys().ToList(); foreach (AuctionBid bid in winningBids) { auction.Winners.Add(bid.AppUser); if (bid.AppUser.WonAuctions == null) { bid.AppUser.WonAuctions = new HashSet <Auction>(); } bid.AppUser.WonAuctions.Add(auction); string key = String.Empty; if (keys.Count > 0) { key = keys.First(); keys.Remove(key); } ClaimedProductKey userKey; BalanceEntry balanceEntry; ProductKey pKey; if (String.IsNullOrEmpty(key) == false) { pKey = new ProductKey(auction.ListingID, key); } else { pKey = new ProductKey(auction.ListingID, true); } userKey = new ClaimedProductKey(pKey, bid.AppUser, DateTime.Now, auction.Prize() + " Auction"); int cost = bid.BidAmount; if (auction.IsSilent == false) { cost = auction.PublicWinningBid(); } balanceEntry = new BalanceEntry(bid.AppUser, auction.Prize() + " Auction", 0 - cost, DateTime.Now); bid.AppUser.AddBalanceEntry(balanceEntry); bid.AppUser.AddClaimedProductKey(userKey); bid.AppUser.Balance -= cost; userRepository.UpdateAppUserSynch(bid.AppUser); } unitOfWork.Save(); }
public void DeleteBalanceEntry(int balanceEntryId) { BalanceEntry balanceEntry = context.BalanceEntries.Find(balanceEntryId); context.BalanceEntries.Remove(balanceEntry); }
public void InsertBalanceEntry(BalanceEntry balanceEntry) { context.BalanceEntries.Add(balanceEntry); }
public async Task <Order> CreateOrder() { AppUser user = await GetCurrentUser(); ICollection <ShoppingCartEntry> cartEntries = user.ShoppingCartEntries; if (user == null || cartEntries == null || cartEntries.Count == 0 || !user.AssertValidOrder()) { return(null); } DateTime orderDate = DateTime.Now; Order order = new Order(user, orderDate); userRepository.InsertOrder(order); unitOfWork.Save(); foreach (ShoppingCartEntry entry in cartEntries) { IEnumerable <ProductKey> keys = entry.Listing.ProductKeys.Take(entry.Quantity); // part of removed code below //int remainingQuantity = entry.Quantity - keys.Count; foreach (ProductKey productKey in keys) { productKey.Listing.Quantity--; listingRepository.UpdateListingSimple(productKey.Listing); listingRepository.DeleteProductKey(productKey.ProductKeyID); ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); //user.AddClaimedProductKey(claimedKey); userRepository.InsertClaimedProductKey(claimedKey); ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); orderEntry.AddClaimedProductKey(claimedKey); order.AddProductOrderEntry(orderEntry); } #region removed // // the case where there are some product keys, but not enough to fulfill the order (the remainining are keys of child listings bundled together) // // rarely triggered (if ever) // if (entry.Listing.ChildListings != null && entry.Listing.ChildListings.Count > 0 && keys != null && keys.Count > 0 && keys.Count < entry.Quantity) // { // foreach (ProductKey productKey in keys) // { // productKey.Listing.Quantity--; // productKey.Listing.UpdateParentQuantities(); // listingRepository.UpdateListing(productKey.Listing); // listingRepository.DeleteProductKey(productKey.ProductKeyID); // ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); // user.AddClaimedProductKey(claimedKey); // userRepository.InsertClaimedProductKey(claimedKey); // //unitOfWork.Save(); // ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); // order.AddProductOrderEntry(orderEntry); // userRepository.InsertProductOrderEntry(orderEntry); // //unitOfWork.Save(); // orderEntry.AddClaimedProductKey(claimedKey); // } // keys = new List<ProductKey>(); // foreach (Listing childListing in entry.Listing.ChildListings) // { // keys.AddRange(listingRepository.GetProductKeys().Where(k => k.ListingID == childListing.ListingID).Take(remainingQuantity)); // } // } // else if (entry.Listing.ChildListings != null && entry.Listing.ChildListings.Count > 0 && keys.Count < entry.Quantity) // { // foreach (Listing childListing in entry.Listing.ChildListings) // { // keys.AddRange(listingRepository.GetProductKeys().Where(k => k.ListingID == childListing.ListingID).Take(entry.Quantity)); // } // } // if (entry.Listing.ChildListings == null || entry.Listing.ChildListings.Count == 0 || keys.Count == entry.Quantity) // { // foreach (ProductKey productKey in keys) // { // productKey.Listing.Quantity--; // productKey.Listing.UpdateParentQuantities(); // listingRepository.UpdateListing(productKey.Listing); // listingRepository.DeleteProductKey(productKey.ProductKeyID); // ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); // user.AddClaimedProductKey(claimedKey); // userRepository.InsertClaimedProductKey(claimedKey); // //unitOfWork.Save(); // ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); // userRepository.InsertProductOrderEntry(orderEntry); // // unitOfWork.Save(); // orderEntry.AddClaimedProductKey(claimedKey); // order.AddProductOrderEntry(orderEntry); // } // } // else // { // for (int i = 0; i < remainingQuantity; i++) // { // ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); // order.AddProductOrderEntry(orderEntry); // userRepository.InsertProductOrderEntry(orderEntry); // //unitOfWork.Save(); // foreach (Listing childListing in entry.Listing.ChildListings) // { // ProductKey productKey = keys.Where(k => k.Listing.ListingID == childListing.ListingID).First(); // keys.Remove(productKey); // productKey.Listing.Quantity--; // // productKey.Listing.UpdateParentQuantities(); // listingRepository.UpdateListing(productKey.Listing); // listingRepository.DeleteProductKey(productKey.ProductKeyID); // ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); // userRepository.InsertClaimedProductKey(claimedKey); // //unitOfWork.Save(); // orderEntry.AddClaimedProductKey(claimedKey); // user.AddClaimedProductKey(claimedKey); // } // order.AddProductOrderEntry(orderEntry); // } // } // //unitOfWork.Save(); #endregion } DeleteShoppingCart(user); int totalSalePrice = order.TotalSalePrice(); BalanceEntry balanceEntry = new BalanceEntry(user, "Purchase - Order #" + order.OrderID, 0 - totalSalePrice, orderDate); //user.BalanceEntries.Add(balanceEntry); userRepository.InsertBalanceEntry(balanceEntry); user.Balance -= totalSalePrice; //user.AddOrder(order); userRepository.UpdateOrder(order); await userRepository.UpdateAppUserSimple(user); this.unitOfWork.Save(); return(userRepository.GetOrderByID(order.OrderID)); }