/// <summary> /// Return whether cart LineItem is equal to promotion Reward /// </summary> public static bool EqualsReward(this LineItem li, GiftReward reward) { return(li.Quantity == reward.Quantity && (li.ProductId == reward.ProductId || li.ProductId.IsNullOrEmpty() && reward.ProductId.IsNullOrEmpty() && (li.Name == reward.Name || reward.Name.IsNullOrEmpty()) && (li.MeasureUnit == reward.MeasureUnit || reward.MeasureUnit.IsNullOrEmpty()) && (li.ImageUrl == reward.ImageUrl || reward.ImageUrl.IsNullOrEmpty()) )); }
//Copy constructor protected GiftReward(GiftReward other) : base(other) { Name = other.Name; CategoryId = other.CategoryId; ProductId = other.ProductId; Quantity = other.Quantity; MeasureUnit = other.MeasureUnit; ImageUrl = other.ImageUrl; }
public PromotionReward[] GetRewards() { var retVal = new GiftReward { Name = Name, CategoryId = CategoryId, ProductId = ProductId, Quantity = Quantity, MeasureUnit = MeasureUnit, ImageUrl = ImageUrl, Description = Description }; return(new PromotionReward[] { retVal }); }
async Task <IonicMessage> GiftAsync(SocketGuildUser fromSgUser, SocketGuildUser toSgUser) { var senderId = fromSgUser.Id; var receiverId = toSgUser.Id; if (toSgUser.IsBot) { RiftBot.Log.Debug("[Gift] Target is bot."); return(await messageService.GetMessageAsync("gift-target-bot", new FormatData(senderId))); } if (fromSgUser.Id == toSgUser.Id) { RiftBot.Log.Debug("[Gift] Ouch, self-gift."); return(await messageService.GetMessageAsync("gift-target-self", new FormatData(senderId))); } (var canGift, var remainingTime) = await CanGift(senderId); if (!canGift) { return(await messageService.GetMessageAsync("gift-cooldown", new FormatData(senderId) { Gift = new GiftData { Cooldown = remainingTime } })); } var dbInventory = await DB.Inventory.GetAsync(senderId); if (dbInventory.Coins < Settings.Economy.GiftPrice) { return(await messageService.GetMessageAsync("gift-nocoins", new FormatData(senderId) { Gift = new GiftData { NecessaryCoins = Settings.Economy.GiftPrice - dbInventory.Coins } })); } await DB.Inventory.RemoveAsync(senderId, new InventoryData { Coins = Settings.Economy.GiftPrice }); var giftItem = new GiftReward(); await rewardService.DeliverToAsync(receiverId, giftItem); GiftSent?.Invoke(null, new GiftSentEventArgs(senderId, receiverId)); GiftReceived?.Invoke(null, new GiftReceivedEventArgs(senderId, fromSgUser.Id)); if (toSgUser.Id == 178443743026872321ul) { GiftedFounder?.Invoke(null, new GiftedFounderEventArgs(receiverId, senderId)); } var developers = await DB.Roles.GetAsync(44); if (IonicHelper.HasRolesAny(toSgUser, developers.RoleId)) { GiftedDeveloper?.Invoke(null, new GiftedDeveloperEventArgs(senderId, receiverId)); } if (await RiftBot.IsModeratorAsync(toSgUser)) { GiftedModerator?.Invoke(null, new GiftedModeratorEventArgs(senderId, receiverId)); } if (!(await DB.Streamers.GetAsync(receiverId) is null)) { GiftedStreamer?.Invoke(null, new GiftedStreamerEventArgs(senderId, receiverId)); } RiftBot.Log.Debug("[Gift] Success."); await DB.Cooldowns.SetLastGiftTimeAsync(senderId, DateTime.UtcNow); await DB.Statistics.AddAsync(senderId, new StatisticData { GiftsSent = 1u }); await DB.Statistics.AddAsync(receiverId, new StatisticData { GiftsReceived = 1u }); return(await messageService.GetMessageAsync("gift-success", new FormatData(senderId) { Gift = new GiftData { TargetId = receiverId }, Reward = giftItem })); }