示例#1
0
        public IHttpActionResult SendMessage([FromBody] SendTextViewModel textInfo)
        {
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

            var user_id = _accountService.GetAccountByUsername(username).GordonID;

            var result = _DirectMessageService.SendMessage(textInfo, user_id.ToString());

            var data = new NotificationDataViewModel();

            data.messageID = textInfo.id;
            data.roomID    = textInfo.room_id;

            var connectionIDs = _DirectMessageService.GetUserConnectionIds(textInfo.users_ids);

            if (result == false || connectionIDs == null)
            {
                return(NotFound());
            }

            foreach (IEnumerable <ConnectionIdViewModel> connections in connectionIDs)
            {
                foreach (ConnectionIdViewModel model in connections)
                {
                    var pushNotification = new PushNotificationViewModel();
                    pushNotification.body  = textInfo.groupText;
                    pushNotification.to    = model.connection_id;
                    pushNotification.data  = data;
                    pushNotification.title = textInfo.groupName;

                    var myJsonObject = Newtonsoft.Json.JsonConvert.SerializeObject(pushNotification);

                    HttpClient httpClient = new HttpClient();

                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    var content = new StringContent(myJsonObject.ToString(), Encoding.UTF8, "application/json");
                    var post    = httpClient.PostAsync("https://exp.host/--/api/v2/push/send", content).Result;
                }
            }

            return(Ok(result));
        }
示例#2
0
        public async Task <string> SendPushNotification(PushNotificationViewModel notification)
        {
            var msg = new Message()
            {
                Topic        = ROOT_PATH_FOR_TOPICS + (notification.Topic ?? "all"),
                Notification = new Notification()
                {
                    Title    = notification.Title ?? "Photo gallery notification",
                    Body     = notification.Body ?? "Sorry, notification losted",
                    ImageUrl = notification.ImageUrl ?? DEFAULT_NOTIFICATION_IMAGE_URL
                },
                Android = new AndroidConfig()
                {
                    Priority = Priority.High
                }
            };

            return(await messagingFB.SendAsync(msg));
        }
示例#3
0
        public IActionResult SendNotification(PushNotificationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var pushNotification = _pushNotification.Send(model.Title, model.Content, _configuration.GetValue <string>("PushNotification:AppId"), _configuration.GetValue <string>("PushNotification:RestApiKey"));

            if (pushNotification)
            {
                ViewData["SuccessMessage"] = Model.Resources.Common.PushNotificationSuccess;
            }
            else
            {
                ViewData["ErrorMessage"] = Model.Resources.Common.PushNotificationError;
            }
            return(View(model));
        }
示例#4
0
        public async Task <ActionResult> CreatePushNotification(PushNotificationViewModel notification)
        {
            await pushNotifService.SendPushNotification(notification);

            return(RedirectToAction(nameof(CreatePushNotification)));
        }
        public IActionResult CreateOrEdit([FromBody] JsonData jsonData)
        {
            JsonResultHelper          result = new JsonResultHelper();
            PushNotificationViewModel model  = jsonData.model;

            PushNotification data = new PushNotification();

            result.Access  = true;
            result.success = true;
            if (model.Id > 0)
            {
                //no Action in Edit Mode
            }
            else
            {
                //Add Mode
                data            = _mapper.Map <PushNotificationViewModel, PushNotification>(model);
                data.SendDate   = DateTime.Now;
                data.UsersCount = model.strUser.Split(",").ToList().Count() - 1;

                _pushNotificationRepositry.Create(data);
                if (!string.IsNullOrEmpty(model.strUser))
                {
                    if (model.strUser.Contains("1"))
                    {
                        var users = _userRepository.GetAllRegisterUser().Where(x => x.FCMToken != null).ToList();
                        users.ForEach(x =>
                        {
                            UsersNotification entity  = new UsersNotification();
                            entity.UsersId            = x.Id;
                            entity.PushNotificationId = data.Id;

                            PublicFunctions.SendNotification(model.NotificationMessage, x.FCMToken, true);

                            _usersNotificationRepositry.Create(entity);
                        });
                        data.UsersCount = users.Count();
                    }
                    else
                    {
                        model.strUser.Split(",").ToList().ForEach(e =>
                        {
                            if (!string.IsNullOrEmpty(e))
                            {
                                UsersNotification entity  = new UsersNotification();
                                entity.UsersId            = int.Parse(e);
                                entity.PushNotificationId = data.Id;

                                var user = _userRepository.GetById((int)entity.UsersId);
                                if (user != null)
                                {
                                    PublicFunctions.SendNotification(model.NotificationMessage, user.FCMToken, false);

                                    _usersNotificationRepositry.Create(entity);
                                }
                                //send Notificatin Function
                            }
                        });
                    }
                }
            }
            result.Msg.Add("Succces");
            result.url = jsonData.continueEditing ? Url.Action("PreparePushNotification", "PushNotification", new { id = data.Id }) : Url.Action("Index", "PushNotification");
            return(Json(result));
        }