public PaymentMethod(CreditCard creditCard, PurchaseType purchaseType, int installments = 1) { CreditCard = creditCard; PurchaseType = purchaseType; Installments = installments; }
public ActionResult Edit(PurchaseType purchasetype) { if (ModelState.IsValid) { db.Entry(purchasetype).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(purchasetype); }
public ActionResult Create(PurchaseType purchasetype) { if (ModelState.IsValid) { db.PurchaseTypes.Add(purchasetype); db.SaveChanges(); return RedirectToAction("Index"); } return View(purchasetype); }
public List <PurchaseType> GetAll() { List <PurchaseType> purchaseTypes = new List <PurchaseType>(); using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("PurchaseTypesSelectAll", cn); cmd.CommandType = CommandType.StoredProcedure; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { PurchaseType currentRow = new PurchaseType(); currentRow.PurchaseTypeID = (int)dr["PurchaseTypeID"]; currentRow.PurchaseTypeName = dr["PurchaseTypeName"].ToString(); purchaseTypes.Add(currentRow); } } } return(purchaseTypes); }
public void Test() { // 生成操作对象实例、组装链式结构 IHandler handler1 = new InternalHandler(); IHandler handler2 = new DiscountHandler(); IHandler handler3 = new MailHandler(); IHandler handler4 = new RegularHandler(); handler1.Successor = handler3; handler3.Successor = handler2; handler2.Successor = handler4; IHandler head = handler1; handler1.HasBreakPoint = true; handler1.Break += this.Break; handler3.HasBreakPoint = true; handler3.Break += this.Break; Request request = new Request(20, PurchaseType.Regular); head.HandleRequest(request); currentType = PurchaseType.Internal; // 为第一个断点做的准备 Assert.AreEqual <double>(20, request.Price); }
public VirtualGood Complete() { VirtualGood good; PurchaseType purchase = null; if (currency == Currency.Dollars) { purchase = new PurchaseWithMarket(sku, price); } if (currency == Currency.Seeds) { purchase = new PurchaseWithVirtualItem("seed", Mathf.CeilToInt(price)); } if (consumable) { good = new SingleUseVG(name, description, id, purchase); } else { good = new LifetimeVG(name, description, id, purchase); } return(good); }
/** Private functions **/ /** * Transforms given JObject to StoreInfo * * @param JObject * @throws JSONException */ private static void fromJObject(JObject JObject) { mVirtualItems = new Dictionary <String, VirtualItem>(); mPurchasableItems = new Dictionary <String, PurchasableVirtualItem>(); mGoodsCategories = new Dictionary <String, VirtualCategory>(); mGoodsUpgrades = new Dictionary <String, List <UpgradeVG> >(); mCurrencyPacks = new List <VirtualCurrencyPack>(); mGoods = new List <VirtualGood>(); mCategories = new List <VirtualCategory>(); mCurrencies = new List <VirtualCurrency>(); mNonConsumables = new List <NonConsumableItem>(); JToken value; if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCIES, out value)) { JArray virtualCurrencies = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCIES); for (int i = 0; i < virtualCurrencies.Count; i++) { JObject o = virtualCurrencies.Value <JObject>(i); VirtualCurrency c = new VirtualCurrency(o); mCurrencies.Add(c); mVirtualItems.Add(c.getItemId(), c); } } if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCYPACKS, out value)) { JArray currencyPacks = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCYPACKS); for (int i = 0; i < currencyPacks.Count; i++) { JObject o = currencyPacks.Value <JObject>(i); VirtualCurrencyPack pack = new VirtualCurrencyPack(o); mCurrencyPacks.Add(pack); mVirtualItems.Add(pack.getItemId(), pack); PurchaseType purchaseType = pack.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType) .getMarketItem().getProductId(), pack); } } } // The order in which VirtualGoods are created matters! // For example: VGU and VGP depend on other VGs if (JObject.TryGetValue(StoreJSONConsts.STORE_GOODS, out value)) { JObject virtualGoods = JObject.Value <JObject>(StoreJSONConsts.STORE_GOODS); JToken valueVg; if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_SU, out valueVg)) { JArray suGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_SU); for (int i = 0; i < suGoods.Count; i++) { JObject o = suGoods.Value <JObject>(i); SingleUseVG g = new SingleUseVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_LT, out valueVg)) { JArray ltGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_LT); for (int i = 0; i < ltGoods.Count; i++) { JObject o = ltGoods.Value <JObject>(i); LifetimeVG g = new LifetimeVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_EQ, out valueVg)) { JArray eqGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_EQ); for (int i = 0; i < eqGoods.Count; i++) { JObject o = eqGoods.Value <JObject>(i); EquippableVG g = new EquippableVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_PA, out valueVg)) { JArray paGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_PA); for (int i = 0; i < paGoods.Count; i++) { JObject o = paGoods.Value <JObject>(i); SingleUsePackVG g = new SingleUsePackVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_UP, out valueVg)) { JArray upGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_UP); for (int i = 0; i < upGoods.Count; i++) { JObject o = upGoods.Value <JObject>(i); UpgradeVG g = new UpgradeVG(o); addVG(g); List <UpgradeVG> upgrades = mGoodsUpgrades[g.getGoodItemId()]; if (upgrades == null) { upgrades = new List <UpgradeVG>(); mGoodsUpgrades.Add(g.getGoodItemId(), upgrades); } upgrades.Add(g); } } } // Categories depend on virtual goods. That's why the have to be initialized after! if (JObject.TryGetValue(StoreJSONConsts.STORE_CATEGORIES, out value)) { JArray virtualCategories = JObject.Value <JArray>(StoreJSONConsts.STORE_CATEGORIES); for (int i = 0; i < virtualCategories.Count; i++) { JObject o = virtualCategories.Value <JObject>(i); VirtualCategory category = new VirtualCategory(o); mCategories.Add(category); foreach (String goodItemId in category.getGoodsItemIds()) { mGoodsCategories.Add(goodItemId, category); } } } if (JObject.TryGetValue(StoreJSONConsts.STORE_NONCONSUMABLES, out value)) { JArray nonConsumables = JObject.Value <JArray>(StoreJSONConsts.STORE_NONCONSUMABLES); for (int i = 0; i < nonConsumables.Count; i++) { JObject o = nonConsumables.Value <JObject>(i); NonConsumableItem non = new NonConsumableItem(o); mNonConsumables.Add(non); mVirtualItems.Add(non.getItemId(), non); PurchaseType purchaseType = non.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType) .getMarketItem().getProductId(), non); } } } }
public Request(double price, PurchaseType type) { this.price = price; this.type = type; }
public HandlerBase(PurchaseType type, IHandler successor) { this.type = type; this.successor = successor; }
// // GET: /PurchaseType/Details/5 public ViewResult Details(int id) { PurchaseType purchasetype = db.PurchaseTypes.Find(id); return(View(purchasetype)); }
/** * Replaces an old virtual item with a new one by doing the following: * 1. Determines the type of the given virtual item. * 2. Looks for the given virtual item in the relevant list, according to its type. * 3. If found, removes it. * 4. Adds the given virtual item. * * @param virtualItem the virtual item that replaces the old one if exists. */ public static void replaceVirtualItem(VirtualItem virtualItem) { mVirtualItems.Add(virtualItem.getItemId(), virtualItem); if (virtualItem is VirtualCurrency) { for (int i = 0; i < mCurrencies.Count; i++) { if (mCurrencies[i].getItemId() == virtualItem.getItemId()) { mCurrencies.RemoveAt(i); break; } } mCurrencies.Add((VirtualCurrency)virtualItem); } if (virtualItem is VirtualCurrencyPack) { VirtualCurrencyPack vcp = (VirtualCurrencyPack)virtualItem; PurchaseType purchaseType = vcp.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vcp); } for (int i = 0; i < mCurrencyPacks.Count; i++) { if (mCurrencyPacks[i].getItemId() == vcp.getItemId()) { mCurrencyPacks.RemoveAt(i); break; } } mCurrencyPacks.Add(vcp); } if (virtualItem is VirtualGood) { VirtualGood vg = (VirtualGood)virtualItem; if (vg is UpgradeVG) { List <UpgradeVG> upgrades = mGoodsUpgrades[((UpgradeVG)vg).getGoodItemId()]; if (upgrades == null) { upgrades = new List <UpgradeVG>(); mGoodsUpgrades.Add(((UpgradeVG)vg).getGoodItemId(), upgrades); } upgrades.Add((UpgradeVG)vg); } PurchaseType purchaseType = vg.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vg); } for (int i = 0; i < mGoods.Count; i++) { if (mGoods[i].getItemId() == vg.getItemId()) { mGoods.RemoveAt(i); break; } } mGoods.Add(vg); } /* * if (virtualItem is NonConsumableItem) { * NonConsumableItem non = (NonConsumableItem) virtualItem; * * PurchaseType purchaseType = non.GetPurchaseType(); * if (purchaseType is PurchaseWithMarket) { * mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem() * .getProductId(), non); * } * * for(int i=0; i<mNonConsumables.Count; i++) { * if (mNonConsumables[i].getItemId() == non.getItemId()) { * mNonConsumables.RemoveAt(i); * break; * } * } * mNonConsumables.Add(non); * }*/ }
public bool IsPurchased(PurchaseType purchaseType) // IDevicePurchase { return(purchaseProvider.IsPurchased(purchaseType)); }
public void Purchase(PurchaseType purchaseType) // IDevicePurchase { purchaseProvider.Purchase(purchaseType); }
public HandlerBase(PurchaseType type) : this(type,null) { }
public Request(double price ,PurchaseType type) { this.price = price; this.type = type; }
public HandlerBase(PurchaseType type,IHandler successor) { this.type = type; this.successor = successor; }
/** Constructor * * @param mName see parent * @param mDescription see parent * @param mItemId see parent * @param purchaseType see parent */ public LifetimeVG(String mName, String mDescription, String mItemId, PurchaseType purchaseType) : base(mName, mDescription, mItemId, purchaseType) { }
public static string ImportPurchases(VaporStoreDbContext context, string xmlString) { var sb = new StringBuilder(); var xmlSerializer = new XmlSerializer(typeof(ImportPurchaseDto[]), new XmlRootAttribute("Purchases")); using StringReader stringReader = new StringReader(xmlString); ImportPurchaseDto[] purchaseDtos = (ImportPurchaseDto[])xmlSerializer.Deserialize(stringReader); var purchases = new List <Purchase>(); foreach (var purchaseDto in purchaseDtos) { if (!IsValid(purchaseDto)) { sb.AppendLine(ErrorMessage); continue; } object purchaseTypeObj; bool isPurchaseTypeValid = Enum.TryParse(typeof(PurchaseType), purchaseDto.PurchaseType, out purchaseTypeObj); if (!isPurchaseTypeValid) { sb.AppendLine(ErrorMessage); continue; } PurchaseType purchaseType = (PurchaseType)purchaseTypeObj; DateTime date; bool isDateValid = DateTime.TryParseExact(purchaseDto.Date, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out date); if (!isDateValid) { sb.AppendLine(ErrorMessage); continue; } Card card = context .Cards .FirstOrDefault(c => c.Number == purchaseDto.CardNumber); if (card == null) { sb.AppendLine(ErrorMessage); continue; } Game game = context .Games .FirstOrDefault(g => g.Name == purchaseDto.GameTitle); if (game == null) { sb.AppendLine(ErrorMessage); continue; } Purchase p = new Purchase() { Type = purchaseType, Date = date, ProductKey = purchaseDto.Key, Game = game, Card = card }; purchases.Add(p); sb.AppendLine(String.Format(SuccessfullyImportedPurchase, p.Game.Name, p.Card.User.Username)); } context.Purchases.AddRange(purchases); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
protected string GetPurchaseTypePrice(PurchaseType purchaseType) { var purchaseWithMarket = purchaseType as PurchaseWithMarket; if (purchaseWithMarket != null) { return !string.IsNullOrEmpty(purchaseWithMarket.MarketItem.MarketPriceAndCurrency) ? purchaseWithMarket.MarketItem.MarketPriceAndCurrency : purchaseWithMarket.MarketItem.Price.ToString("C", CultureInfo.CurrentCulture); } var purchaseWithVirtualItem = purchaseType as PurchaseWithVirtualItem; if (purchaseWithVirtualItem != null) { return purchaseWithVirtualItem.Amount.ToString("G7") + " " + StoreInfo.GetItemByItemId(purchaseWithVirtualItem.TargetItemId).Name + "s"; } return string.Empty; }
public static string ImportPurchases(VaporStoreDbContext context, string xmlString) { StringBuilder sb = new StringBuilder(); var purcasesXml = XmlConverter.Deserializer <PurchaseInputModel>(xmlString, "Purchases"); List <Purchase> purchases = new List <Purchase>(); foreach (var xmlPurchase in purcasesXml) { if (!IsValid(xmlPurchase)) { sb.AppendLine(ErrorMessage); continue; } object purchaseTypeObj; bool isPurchaseTypeValid = Enum.TryParse(typeof(PurchaseType), xmlPurchase.PurchaiseType, out purchaseTypeObj); if (!isPurchaseTypeValid) { sb.AppendLine(ErrorMessage); continue; } PurchaseType purchaseType = (PurchaseType)purchaseTypeObj; DateTime date; bool isDateValid = DateTime.TryParseExact(xmlPurchase.Date, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out date); if (!isDateValid) { sb.AppendLine(ErrorMessage); continue; } var card = context.Cards.FirstOrDefault(x => x.Number == xmlPurchase.Card); var game = context.Games.FirstOrDefault(x => x.Name == xmlPurchase.GameTitle); if (card == null || game == null) { sb.AppendLine(ErrorMessage); continue; } var purchase = new Purchase { Type = purchaseType, ProductKey = xmlPurchase.Key, Date = date, Card = card, Game = game, }; purchases.Add(purchase); var username = context.Users. Where(x => x.Id == purchase.Card.UserId).Select(x => x.Username).FirstOrDefault(); //sb.AppendLine($"Imported {xmlPurchase.GameTitle} for {purchase.Card.User.Username}"); sb.AppendLine($"Imported {xmlPurchase.GameTitle} for {username}"); } context.Purchases.AddRange(purchases); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public UUID StartPurchaseOrATMTransfer(UUID agentId, uint amountBuying, PurchaseType purchaseType, string gridName) { bool success = false; UserAccount ua = Registry.RequestModuleInterface <IUserAccountService>().GetUserAccount(null, agentId); if (ua == null) { return(UUID.Zero); } string agentName = ua.Name; UUID RegionID = UUID.Zero; string RegionName = ""; if (purchaseType == PurchaseType.InWorldPurchaseOfCurrency) { IClientCapsService client = Registry.RequestModuleInterface <ICapsService>().GetClientCapsService(agentId); if (client != null) { IRegionClientCapsService regionClient = client.GetRootCapsService(); RegionID = regionClient.Region.RegionID; RegionName = regionClient.Region.RegionName; } } else if (purchaseType == PurchaseType.ATMTransferFromAnotherGrid) { RegionName = "Grid:" + gridName; } else { RegionName = "Unknown"; } UUID purchaseID = UUID.Random(); success = m_database.UserCurrencyBuy(purchaseID, agentId, agentName, amountBuying, m_options.RealCurrencyConversionFactor, new RegionTransactionDetails { RegionID = RegionID, RegionName = RegionName }, (int)purchaseType); StarDustUserCurrency currency = UserCurrencyInfo(agentId); if (m_options.AutoApplyCurrency && success) { Transaction transaction; m_database.UserCurrencyBuyComplete(purchaseID, 1, "AutoComplete", m_options .AutoApplyCurrency.ToString (), "Auto Complete", out transaction); UserCurrencyTransfer(transaction.ToID, m_options. BankerPrincipalID, UUID.Zero, UUID.Zero, transaction.Amount, "Currency Purchase", TransactionType.SystemGenerated, transaction.TransactionID); RestrictCurrency(currency, transaction, agentId); } else if (success && (m_options.AfterCurrencyPurchaseMessage != string.Empty) && (purchaseType == PurchaseType.InWorldPurchaseOfCurrency)) { SendGridMessage(agentId, String.Format(m_options.AfterCurrencyPurchaseMessage, purchaseID.ToString()), false, UUID.Zero); } if (success) { return(purchaseID); } return(UUID.Zero); }
private CartSummaryLineItem GenerateLineItem(int eventId, Guid? itemId, PurchaseType purchaseType, ProcessType processType, string name, string description, int? purchaseItemId, decimal cost, bool discountable, bool taxable, decimal? stateTax, decimal? localTax, bool removable) { var lineItem = new CartSummaryLineItem { EventId = eventId, SessionKey = itemId, PurchaseType = purchaseType, ProcessType = processType, ItemName = name, ItemDescription = description, PurchaseItemId = purchaseItemId.Value, ItemCost = cost, Discountable = discountable, Taxable = taxable, Removable = removable }; if (lineItem.Taxable) { lineItem.StateTaxPercentage = stateTax; lineItem.LocalTaxPercentage = localTax; } return lineItem; }
public void Consume(PurchaseType purchaseType) // IDevicePurchase { purchaseProvider.Consume(purchaseType); }
public void QuerySkuDetails(string[] querySkuDetails, PurchaseType type) => _payment?.Call("querySkuDetails", querySkuDetails, $"{type}".ToLower());
public HandlerBase(PurchaseType type) { this.type = type; }
/** * Constructor * * @param mName see parent * @param mDescription see parent * @param mItemId see parent * @param purchaseType see parent */ public SingleUseVG(String mName, String mDescription, String mItemId, PurchaseType purchaseType) : base(mName, mDescription, mItemId, purchaseType) { }
/** * Initializes from <code>IStoreAssets</code>. * This happens only once - when the game is loaded for the first time. * * @param storeAssets game economy */ private static void initializeWithStoreAssets(IStoreAssets storeAssets) { // fall-back here if the json doesn't exist, // we load the store from the given {@link IStoreAssets}. mCurrencies = new List <VirtualCurrency>(); mCurrencies.AddRange(storeAssets.GetCurrencies()); mCurrencyPacks = new List <VirtualCurrencyPack>(); mCurrencyPacks.AddRange(storeAssets.GetCurrencyPacks()); mGoods = new List <VirtualGood>(); mGoods.AddRange(storeAssets.GetGoods()); mCategories = new List <VirtualCategory>(); mCategories.AddRange(storeAssets.GetCategories()); //mNonConsumables = new List<NonConsumableItem>(); //mNonConsumables.AddRange(storeAssets.GetNonConsumableItems()); mVirtualItems = new Dictionary <String, VirtualItem>(); mPurchasableItems = new Dictionary <String, PurchasableVirtualItem>(); mGoodsCategories = new Dictionary <String, VirtualCategory>(); mGoodsUpgrades = new Dictionary <String, List <UpgradeVG> >(); foreach (VirtualCurrency vi in mCurrencies) { mVirtualItems.Add(vi.getItemId(), vi); } foreach (VirtualCurrencyPack vi in mCurrencyPacks) { mVirtualItems.Add(vi.getItemId(), vi); PurchaseType purchaseType = vi.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vi); } } foreach (VirtualGood vi in mGoods) { mVirtualItems.Add(vi.getItemId(), vi); if (vi is UpgradeVG) { List <UpgradeVG> upgrades = mGoodsUpgrades[((UpgradeVG)vi).getGoodItemId()]; if (upgrades == null) { upgrades = new List <UpgradeVG>(); mGoodsUpgrades.Add(((UpgradeVG)vi).getGoodItemId(), upgrades); } upgrades.Add((UpgradeVG)vi); } PurchaseType purchaseType = vi.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vi); } } /* * foreach(NonConsumableItem vi in mNonConsumables) { * mVirtualItems.Add(vi.getItemId(), vi); * * PurchaseType purchaseType = vi.GetPurchaseType(); * if (purchaseType is PurchaseWithMarket) { * mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem() * .getProductId(), vi); * } * }*/ foreach (VirtualCategory category in mCategories) { foreach (String goodItemId in category.getGoodsItemIds()) { mGoodsCategories.Add(goodItemId, category); } } save(); }
public void Update(PurchaseType purchaseType) { repository.Update(purchaseType); }
// // GET: /PurchaseType/Delete/5 public ActionResult Delete(int id) { PurchaseType purchasetype = db.PurchaseTypes.Find(id); return(View(purchasetype)); }
public void Add(PurchaseType purchaseType) { context.PurchaseTypes.Add(purchaseType); context.SaveChanges(); }
public HandlerBase(PurchaseType type) : this(type, null) { }
public GUIPurchasable(PurchaseType type, string id, string name, string description, List<IPlatformEditor> editors) { this.type = type; this.id = id; this.displayName = name; this.description = description; this.editors = editors; }
/// <summary> /// Initializes a new instance of the <see cref="PurchasableVirtualItem"/> class. /// </summary> /// <param name="mName">Name</param> /// <param name="mDescription">Description.</param> /// <param name="mItemId">item identifier.</param> /// <param name="purchaseType">Type of the purchase.</param> public PurchasableVirtualItem(String mName, String mDescription, String mItemId, PurchaseType purchaseType) : base(mName, mDescription, mItemId) { mPurchaseType = purchaseType; mPurchaseType.setAssociatedItem(this); }
void _Break(object sender, CallHandlerEventArgs e) { IHandler handler = e.Handler; //为第二个调用做修改 currentType = PurchaseType.Mail; }
public void Add(PurchaseType purchaseType) { repository.Add(purchaseType); }
public ProductDefinition(string platformSpecificId, PurchaseType type) { this.PlatformSpecificId = platformSpecificId; this.Type = type; }
public void Update(PurchaseType purchaseType) { context.PurchaseTypes.Update(purchaseType); context.SaveChanges(); }
public static string ImportPurchases(VaporStoreDbContext context, string xmlString) { XmlRootAttribute xmlRoot = new XmlRootAttribute("Purchases"); XmlSerializer xmlSerializer = new XmlSerializer(typeof(ImportPurchaseDto[]), xmlRoot); ImportPurchaseDto[] purchaseDtos; using (StringReader sr = new StringReader(xmlString)) { purchaseDtos = (ImportPurchaseDto[])xmlSerializer.Deserialize(sr); } StringBuilder sb = new StringBuilder(); List <Purchase> purchases = new List <Purchase>(); foreach (var purchaseDto in purchaseDtos) { if (!IsValid(purchaseDto)) { sb.AppendLine("Invalid Data"); continue; } string[] types = new string[] { "Retail", "Digital" }; if (types.Any(t => t == purchaseDto.Type) == false) { sb.AppendLine("Invalid Data"); continue; } PurchaseType type = purchaseDto.Type == "Retail" ? PurchaseType.Retail : PurchaseType.Digital; bool isDate = DateTime.TryParseExact(purchaseDto.Date, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date); if (!isDate) { sb.AppendLine("Invalid Data"); continue; } Game game = context.Games.FirstOrDefault(x => x.Name == purchaseDto.Title); if (game == null) { sb.AppendLine("Invalid Data"); continue; } Card card = context.Cards.FirstOrDefault(x => x.Number == purchaseDto.Card); if (card == null) { sb.AppendLine("Invalid Data"); continue; } Purchase purchase = new Purchase() { Type = type, ProductKey = purchaseDto.Key, Date = date, Card = card, Game = game }; purchases.Add(purchase); sb.AppendLine($"Imported {purchase.Game.Name} for {purchase.Card.User.Username}"); } context.Purchases.AddRange(purchases); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public int GetMsgQuota(PurchaseType type, DateTime date) { return (MessagePurchases.Where(mp => mp.PurchaseType == type && (!mp.DoExpire || mp.ExpiryDate.CompareTo(date) > 0)).Select(p => p.MessagesRemaining()).Aggregate((p1, p2) => p1 + p2)); }
/** * Constructor * * @param mName see parent * @param mDescription see parent * @param mItemId see parent * @param purchaseType see parent */ public VirtualGood(String mName, String mDescription, String mItemId, PurchaseType purchaseType) : base(mName, mDescription, mItemId, purchaseType) { }