private void RedeemDone(Account account, GoodiePack goodiePack) { Db.Query().CommandText("update accountcampaignitems set redeemed=1,redeemdate=@now where accountid=@accountID and campaignid=@campaignID") .SetParameter("@now", DateTime.Now) .SetParameter("@accountID", account.Id) .SetParameter("@campaignID", goodiePack.CampaignId) .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLUpdateError); }
private IEnumerable <GoodiePack> GetGoodiePacks(Account account) { var campaignIds = GetNonRedeemedCampaignIds(account).ToArray(); if (campaignIds.IsNullOrEmpty()) { return(Enumerable.Empty <GoodiePack>()); } var campaignStr = campaignIds.ArrayToString(); return(Db.Query() .CommandText("select * from campaigngoodiepacks where campaignid in (" + campaignStr + ")") .Execute() .Select(record => { var goodiePack = new GoodiePack { Id = record.GetValue <int>("id"), Name = record.GetValue <string>("name"), Description = record.GetValue <string>("description"), Credit = record.GetValue <int?>("credit"), Ep = record.GetValue <int?>("ep"), CampaignId = record.GetValue <int>("campaignid"), Faction = record.GetValue <string>("faction") }; var items = new List <ItemInfo>(); for (var i = 0; i < GoodiePack.ITEMS_COUNT; i++) { var itemInfo = ItemInfo.None; var definition = record.GetValue <int?>("item" + i); if (definition != null) { var qty = record.GetValue <int?>("quantity" + i) ?? 1; itemInfo = new ItemInfo((int)definition, qty) { IsRepackaged = true }; } items.Add(itemInfo); } goodiePack.Items = items; return goodiePack; }).ToArray()); }
public IDictionary <string, object> Redeem(Account account, Character character, GoodiePack goodiePack) { var result = new Dictionary <string, object>(); if (goodiePack.Credit != null) { character.AddToWallet(TransactionType.GoodiePackCredit, (double)goodiePack.Credit); } if (goodiePack.Ep != null) { //ExtensionHelper.AddExtensionPenaltyPoints(account, -1*(int) _ep, true); var epData = _accountManager.GetEPData(account, character); result.Add(k.extension, epData); } var publicContainer = character.GetPublicContainerWithItems(); foreach (var itemInfo in goodiePack.Items.Where(itemInfo => itemInfo != ItemInfo.None)) { publicContainer.CreateAndAddItem(itemInfo, i => { i.Owner = character.Eid; }); } publicContainer.Save(); RedeemDone(account, goodiePack); var items = publicContainer.ToDictionary(); result.Add(k.container, items); result.Add("goodiepack", goodiePack.ToDictionary()); return(result); }