예제 #1
0
        public async Task <IActionResult> Create(PushModel model)
        {
            if (ModelState.IsValid)
            {
                var name       = User.Identity.Name;
                var loggedUser = await _adminRepository.GetByEmailAsync(name);


                await SendPushToAppCenter(model.Title, model.Content, model.SurveyId.ToString());

                await _pushRepository.AddAsync(
                    new DomainLayer.Entities.Push
                {
                    AdminId   = loggedUser.Id,
                    Content   = model.Content,
                    Title     = model.Title,
                    SurveyId  = model.SurveyId,
                    CreatedAt = DateTime.UtcNow
                }
                    );

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
예제 #2
0
        public async Task SendAsync(Guid messageId, string textMessage, string deviceToken, DateTime createdAt)
        {
            if (string.IsNullOrEmpty(textMessage) || string.IsNullOrEmpty(deviceToken))
            {
                throw new PureNotificationException("Text message or device token can not be null.");
            }

            var message = new PushMessage(messageId, textMessage, deviceToken, createdAt);
            await _repository.AddAsync(message);


            var res = await SendToPushProvider(message);
        }