public NotificationLogDTO SendPush(NotificationPushDTO notification) { try { using (WebClient client = GetClient()) { string response = client.DownloadString(NotificationPushURL + "sendpush" + "?token=" + notification.Token + "&msg=" + notification.Message + "&title=" + notification.Title + "&playerId=" + notification.PlayerId); return(JsonDeserialize <NotificationLogDTO>(response)); } } catch (Exception e) { throw e; } }
public ActionResult SendNotificationPush(List <string> checkedIds, string teamId, string message, string title) { if (checkedIds == null) { return(Json(new { text = "Selecione os destinatarios.", error = true }, JsonRequestBehavior.DenyGet)); } else if (message == "" || title == "") { return(Json(new { text = "Escreva uma mensagem e um titulo.", error = true }, JsonRequestBehavior.DenyGet)); } List <NotificationPushDTO> notifications = new List <NotificationPushDTO>(); if (teamId != "empty") { foreach (string checkedId in checkedIds) { List <AccountDevicesEntity> devices = AccountDevicesRepository.Instance.FindByPlayerId(checkedId); foreach (AccountDevicesEntity device in devices) { NotificationPushDTO notification = new NotificationPushDTO { Token = device.Notification_Token, PlayerId = device.External_User_Id, Message = message, Title = title }; notifications.Add(notification); } } } else { foreach (string checkedId in checkedIds) { GetAllDTO runs = RunEngineService.Instance.GetRunsByTeamId(checkedId); foreach (RunEngineDTO run in runs.List.run) { List <AccountDevicesEntity> devices = AccountDevicesRepository.Instance.FindByPlayerId(run.PlayerId); foreach (AccountDevicesEntity device in devices) { NotificationPushDTO notification = new NotificationPushDTO { Token = device.Notification_Token, PlayerId = device.External_User_Id, Message = message, Title = title }; notifications.Add(notification); } } } } int countErrors = 0; int countSuccess = 0; foreach (NotificationPushDTO notification in notifications) { NotificationLogDTO notificationLog = NotificationPushService.Instance.SendPush(notification); if (notificationLog.Success == "0") { countErrors++; } else { countSuccess++; } } return(Json(new { text = countSuccess + " notificações foram enviadas com sucesso! " + countErrors + " falharam ao serem enviadas!", error = false })); }
public ActionResult Save(List <RunMetricEngineDTO> resultList, string runId, string date, string itemId) { DateTime dateTime = Convert.ToDateTime(date); long time = dateTime.Ticks; ItemEngineDTO itemEngine = null; try { itemEngine = ItemEngineService.Instance.GetById(itemId); } catch (Exception e) { itemEngine = null; } float valorVendas = 0f; string gameId = CurrentFirm.ExternalId; if (gameId == "5880a1743a87783b4f0ba709") //pelegrini { valorVendas = resultList.Where(x => x.Name == "VENDAS").Select(y => y.Points).FirstOrDefault(); } bool flag = false; foreach (RunMetricEngineDTO result in resultList) { if (result.Points > 0) { flag = true; result.Score = 0; result.RunId = runId; result.Date = time; if (itemEngine != null) { result.ItemId = itemEngine.Id; result.ItemName = itemEngine.Name; } result.ArithmeticMultiplier = valorVendas > 0 ? valorVendas : 1; RunMetricEngineService.Instance.CreateOrUpdate(result); } } if (gameId == "58e623fe3a877804f5b6bf22" && flag == true) //duplov { List <AccountDevicesDTO> devices = AccountDevicesRepository.Instance.FindAllByGameId(gameId); PlayerEngineDTO player = PlayerEngineService.Instance.GetById(resultList.First().PlayerId); string message = player.Nick + " está acelerando, veja seus novos resultados!"; foreach (AccountDevicesDTO device in devices) { NotificationPushDTO notification = new NotificationPushDTO { Token = device.Notification_Token, PlayerId = device.External_User_Id, Message = message, Title = "Gamific - Novos Resultados" }; NotificationPushService.Instance.SendPush(notification); } } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }