Exemplo n.º 1
0
        private string GetFirebaseMessageForCutPointReachedReward(RewardResponse rewardResponse, string lang)
        {
            string message = lang switch
            {
                "EN" => "Congratulations. You reached a cut point (objective)." + " You receipt " + rewardResponse.Points + " points.",
                _ => "Enhorabuena! Has alcanzado un punto de corte (Objetivo)." + " Has ganado " + rewardResponse.Points + " puntos.",
            };

            return(message);
        }
Exemplo n.º 2
0
        private string GetFirebaseMessageForNewReferralReward(RewardResponse rewardResponse, string lang)
        {
            string message = lang switch
            {
                "EN" => "Congratulations. A user invited by you has just joined PlaniFive." + " You receipt " + rewardResponse.Points + " points.",
                _ => "Enhorabuena! Uno de tus usuarios invitados se ha unido a PlaniFive." + " Has ganado " + rewardResponse.Points + " puntos.",
            };

            return(message);
        }
Exemplo n.º 3
0
        private string GetFirebaseMessageForDishBuildReward(RewardResponse rewardResponse, string lang)
        {
            string message = lang switch
            {
                "EN" => "Congratulations. Dr.PlaniFive have approved your dish and it will be visible to other users now." + " You receipt " + rewardResponse.Points + " points.",
                _ => "Enhorabuena! El Dr.PlaniFive ha aprobado tu alimento y estara visible para otros usuarios en la base de datos general." + " Has ganado " + rewardResponse.Points + " puntos.",
            };

            return(message);
        }
Exemplo n.º 4
0
        private string GetFirebaseMessageForCreateEatReward(RewardResponse rewardResponse, string lang, RewardCategoryEnum category)
        {
            var eat = lang == "EN" ? "balaced " : "balanceado ";

            if (category == RewardCategoryEnum.EAT_CREATED)
            {
                eat = "";
            }

            string message = lang switch
            {
                "EN" => "Congratulations. You have been rewarded for creating a " + eat + "plan today." + " You receipt " + rewardResponse.Points + " points.",
                _ => "Enhorabuena! Has sido premiado por crear un plan " + eat + "hoy." + " Has ganado " + rewardResponse.Points + " puntos.",
            };

            return(message);
        }
Exemplo n.º 5
0
        public ActionResult PlaceOrderForGiftCards()
        {
            JsonResponse jsonResponse = new JsonResponse();

            jsonResponse.errors  = new List <string>();
            jsonResponse.RetCode = "1";  //default to error


            try {
                var requestObject = GetAllCartItems();

                RewardResponse objResponse = new RewardResponse();
                RewardsService objReward   = new RewardsService();
                objResponse = objReward.SendDataToProcess(requestObject);

                if (objResponse.Errors.Count > 0)
                {
                    jsonResponse.errors.Add(objResponse.Errors[0].ShortText);
                }
                else if (objResponse.Account.Memberships.BluegreenRewardsMembership.Returns.Count > 0)
                {
                    if (objResponse.Account.Memberships.BluegreenRewardsMembership.Returns[0].RetCode == "1")
                    {
                        jsonResponse.RetCode = "0";
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(objResponse.Account.Memberships.BluegreenRewardsMembership.Returns[0].CodeDesc))
                        {
                            jsonResponse.errors.Add(objResponse.Account.Memberships.BluegreenRewardsMembership.Returns[0].CodeDesc);
                        }
                        else
                        {
                            jsonResponse.errors.Add("Error While Redeeming Rewards. Please Try Again.");
                        }
                    }
                }
            }
            catch (Exception ex) {
                jsonResponse.errors.Add("Error: " + ex.Message);
            }

            return(Json(jsonResponse));
        }
Exemplo n.º 6
0
        public void Execute(SupportedReward reward, OnRewardRedeemedArgs args)
        {
            if (!string.IsNullOrWhiteSpace(args.Message) && int.TryParse(args.Message.Trim(), out int replayId))
            {
                Task.Factory.StartNew(async() =>
                {
                    RewardResponse response = await queue.EnqueueItemAsync(requestFactory.Create(reward, args));

                    if (settings.Twitch.EnableChatBot)
                    {
                        string message = $"{args.DisplayName}, {response.Message}";
                        twitchClient.SendMessage(settings.Twitch.Channel, message, dryRun: settings.Twitch.DryRunMode);
                    }
                }, TaskCreationOptions.LongRunning);
            }
            else
            {
                twitchClient.SendMessage(settings.Twitch.Channel, $"{args.DisplayName}, your request is invalid.", dryRun: settings.Twitch.DryRunMode);
                logger.LogDebug($"{args.TimeStamp}: {args.RewardId} - {args.RewardCost}");
            }
        }
Exemplo n.º 7
0
        public void Execute(SupportedReward reward, OnRewardRedeemedArgs args)
        {
            Task.Factory.StartNew(async() =>
            {
                try
                {
                    logger.LogInformation($"{args.Login} has redeemed {args.RewardTitle}");

                    RewardResponse response = await queue.EnqueueItemAsync(rewardRequestFactory.Create(reward, args));

                    if (settings.Twitch.EnableChatBot)
                    {
                        twitchClient.SendMessage(settings.Twitch.Channel, $"{args.DisplayName}, {response.Message}", dryRun: settings.Twitch.DryRunMode);
                    }
                }
                catch (Exception e)
                {
                    logger.LogError(e, $"Could not queue reward: {reward.Title}");
                }
            }, TaskCreationOptions.LongRunning);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> SetPollResultBasedRequest([FromBody] ListOfPollResultsRequest result)
        {
            var loggedUser = User.GetUserIdFromToken();
            var language   = await _userService.GetUserLanguageFromUserIdAsync(loggedUser);

            // Only 10 points per concept
            var alreadyAnswered = await _pollService.HasAnsweredConceptBeforeAsync(loggedUser, result);

            var message = await _pollService.SetPollResultByQuestionsAsync(loggedUser, result, language);

            /*Reward section*/
            RewardResponse mapped = null;

            if (!alreadyAnswered)
            {
                var answeredPolls = _pollService.GetAnsweredPolls(result);

                var pollId = answeredPolls.FirstOrDefault();
                mapped = await _rewardHelper.HandleRewardAsync(RewardCategoryEnum.POLL_ANSWERED, loggedUser, true, message, pollId);
            }
            /*#end reward section*/

            return(Ok(new ApiOkRewardResponse(message, mapped)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handle the creation of a reward
        /// </summary>
        /// <param name="category">Which type of reward will be</param>
        /// <param name="targetUser">user who will receive the reward</param>
        /// <param name="isPlus">Sum or rest points this reward</param>
        /// <param name="entity1">Info to store in the history</param>
        /// <param name="entity2">Other info to store in the history</param>
        /// <param name="notificationType">How will be the user notified</param>
        /// <param name="devices">Firebase notification targets</param>
        /// <returns>void - notify client that a reward was created via websocket</returns>
        public async Task <RewardResponse> HandleRewardAsync(RewardCategoryEnum category, int targetUser, bool isPlus, object entity1, object entity2,
                                                             NotificationTypeEnum notificationType = NotificationTypeEnum.SIGNAL_R, IEnumerable <Device> devices = null)
        {
            var userStatics = await _userStatisticsService.GetOrCreateUserStatisticsByUserAsync(targetUser);

            var currentPoints = userStatics.Points;
            var cutPoints     = await _cutPointService.GetNextCutPointsAsync(currentPoints, 5);

            var data = new RewardHistoryData
            {
                // Make sure that this is an important info to store in the history
                Entity1 = JsonConvert.SerializeObject(entity1),
                Entity2 = JsonConvert.SerializeObject(entity2)
            };
            var reward = new CreateRewardRequest
            {
                UserId             = targetUser,
                RewardCategoryEnum = (int)category,
                IsPlus             = isPlus,
                Data = JsonConvert.SerializeObject(data),
            };

            var dbReward = await _rewardService.CreateRewardAsync(reward);

            RewardResponse mapped = null;

            // assign only if the reward was created after validations
            if (dbReward != null)
            {
                mapped = new RewardResponse
                {
                    Id               = dbReward.Id,
                    CategoryId       = (int)dbReward.RewardCategory.Category,
                    Category         = dbReward.RewardCategory.Category.ToString(),
                    IsPlus           = dbReward.IsPlus,
                    Points           = dbReward.Points,
                    RewardPoints     = dbReward.RewardPoints,
                    RewardCategoryId = dbReward.RewardCategoryId,
                    UserId           = dbReward.UserId,
                    CreatedAt        = dbReward.CreatedAt
                };

                switch (notificationType)
                {
                case NotificationTypeEnum.SIGNAL_R:
                    await SendSignalRNotificationAsync(HubConstants.REWARD_CREATED, mapped);

                    break;

                case NotificationTypeEnum.FIREBASE:
                    var lang = await _userService.GetUserLanguageFromUserIdAsync(mapped.UserId);

                    var title = (lang == "EN") ? "You have receipt a new reward" : "Has recibido una nueva recompensa";
                    var body  = "";
                    if (category == RewardCategoryEnum.EAT_BALANCED_CREATED_STREAK || category == RewardCategoryEnum.EAT_CREATED_STREAK)
                    {
                        body = GetFirebaseMessageForStreakReward(category, (int)entity1, mapped, lang);
                    }

                    if (category == RewardCategoryEnum.DISH_BUILT)
                    {
                        body = GetFirebaseMessageForDishBuildReward(mapped, lang);
                    }

                    if (category == RewardCategoryEnum.NEW_REFERAL)
                    {
                        body = GetFirebaseMessageForNewReferralReward(mapped, lang);
                    }

                    if (category == RewardCategoryEnum.EAT_BALANCED_CREATED || category == RewardCategoryEnum.EAT_CREATED)
                    {
                        body = GetFirebaseMessageForCreateEatReward(mapped, lang, category);
                    }

                    if (category == RewardCategoryEnum.CUT_POINT_REACHED)
                    {
                        body = GetFirebaseMessageForCutPointReachedReward(mapped, lang);
                    }

                    if (devices != null)
                    {
                        await _notificationService.SendFirebaseNotificationAsync(title, body, devices);
                    }
                    break;

                default:
                    break;
                }

                await HandleCutPointRewardsAsync(cutPoints, targetUser);
            }

            return(mapped);
        }
Exemplo n.º 10
0
        private string GetFirebaseMessageForStreakReward(RewardCategoryEnum category, int streak, RewardResponse rewardResponse, string lang)
        {
            var reason = "";

            switch (category)
            {
            case RewardCategoryEnum.EAT_CREATED_STREAK:
                switch (lang)
                {
                case "EN":
                    reason = "consecutive days planning your eat";
                    break;

                default:
                    reason = "dias consecutivo planificando tu comida";
                    break;
                }
                break;

            case RewardCategoryEnum.EAT_BALANCED_CREATED_STREAK:
                switch (lang)
                {
                case "EN":
                    reason = "consecutive days planning your eat balanced";
                    break;

                default:
                    reason = "dias consecutivo planificando tu comida balanceada";
                    break;
                }

                break;

            default:
                break;
            }

            string message = lang switch
            {
                "EN" => streak.ToString() + " " + reason + ". You receipt " + rewardResponse.Points + " points.",
                _ => streak.ToString() + " " + reason + ". Has recivido " + rewardResponse.Points + " puntos.",
            };

            return(message);
        }
Exemplo n.º 11
0
        public static void Build(JSONObject response)
        {
            ResponseEvent responseEvent = Spil.MonoInstance.gameObject.AddComponent <ResponseEvent>();

            responseEvent.eventName = response.GetField("name").str;

            if (response.HasField("type"))
            {
                responseEvent.type = response.GetField("type").str;
            }

            if (response.HasField("action"))
            {
                responseEvent.action = response.GetField("action").str;
            }

            if (response.HasField("data"))
            {
                responseEvent.data = response.GetField("data");
            }

            if (responseEvent.type != null)
            {
                switch (responseEvent.type.ToLower().Trim())
                {
                case "advertisement":
                    AdvertisementResponse.ProcessAdvertisementResponse(responseEvent);
                    break;

                case "overlay":
                    OverlayResponse.ProcessOverlayResponse(responseEvent);
                    break;

                case "gameconfig":
                    ConfigResponse.ProcessConfigResponse(responseEvent);
                    break;

                case "packages":
                    PackagesResponse.ProcessPackagesResponse(responseEvent);
                    break;

                case "notification":
                    break;

                case "gamedata":
                    GameDataResponse.ProcessGameDataResponse(responseEvent);
                    break;

                case "promotions":
                    PromotionsResponse.ProcessPromotionResponse(responseEvent);
                    break;

                case "userdata":
                    UserDataResponse.ProcessUserDataResponse(responseEvent);
                    break;

                case "playerdata":
                    PlayerDataResponse.ProcessPlayerDataResponse(responseEvent);
                    break;

                case "gamestate":
                    GameStateResponse.ProcessGameStateResponse(responseEvent);
                    break;

                case "reward":
                    RewardResponse.ProcessRewardResponse(responseEvent);
                    break;

                case "liveevent":
                    LiveEventResponse.ProcessLiveEventResponse(responseEvent);
                    break;

                case "authentication":
                    SocialLoginResponse.ProcessSocialLoginResponse(responseEvent);
                    break;
                }
            }
            GameObject.Destroy(responseEvent);
        }
 public ApiOkRewardResponse(object result, RewardResponse reward)
     : base(200)
 {
     Result = result;
     Reward = reward;
 }