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); }
/// <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); }
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); }
private async Task GetCreateRewardCategoryByCategorySaveAsync(RewardCategoryEnum category) { var rewardCategory = await _uow.RewardCategoryRepository.GetAll().Where(d => d.Category == category) .FirstOrDefaultAsync(); if (rewardCategory == null) { rewardCategory = new RewardCategory { Category = category, Description = "", MaxPointsAllowed = -1, PointsToDecrement = 0, PointsToIncrement = 5, }; switch (category) { case RewardCategoryEnum.POLL_ANSWERED: rewardCategory.PointsToIncrement = 10; rewardCategory.MaxPointsAllowed = 30; break; case RewardCategoryEnum.EAT_CREATED: break; case RewardCategoryEnum.EAT_BALANCED_CREATED: rewardCategory.PointsToIncrement = 10; break; case RewardCategoryEnum.EAT_CREATED_STREAK: rewardCategory.PointsToIncrement = 30; rewardCategory.PointsToDecrement = 30; break; case RewardCategoryEnum.EAT_BALANCED_CREATED_STREAK: rewardCategory.PointsToIncrement = 40; rewardCategory.PointsToDecrement = 40; break; case RewardCategoryEnum.DISH_BUILT: rewardCategory.PointsToIncrement = 10; break; case RewardCategoryEnum.NEW_REFERAL: rewardCategory.PointsToIncrement = 25; break; case RewardCategoryEnum.CUT_POINT_REACHED: rewardCategory.PointsToIncrement = 20; break; case RewardCategoryEnum.SOLO_QUESTION_ANSWERED: rewardCategory.PointsToIncrement = 0; rewardCategory.PointsToDecrement = 0; break; default: break; } await _uow.RewardCategoryRepository.AddAsync(rewardCategory); } }