public async Task <CommunicationResponse> Handle(SendEmailRequest Request, CancellationToken cancellationToken)
        {
            try
            {
                var Email = new EmailQueue()
                {
                    EmailType   = Request.EmailType,
                    Recepient   = Request.Recepient,
                    Attachment  = Request.Attachment,
                    BCC         = Request.BCC,
                    CC          = Request.CC,
                    Body        = Request.Body,
                    Status      = Convert.ToInt16(MessageStatusType.Initialize),
                    Subject     = Request.Subject,
                    CreatedDate = DateTime.UtcNow
                };
                _MessageRepository.Add(Email);
                Email.InQueueMessage();
                _MessageRepository.Update(Email);
                IQueryable Result = await _MessageConfiguration.GetAPIConfigurationAsync(1, 2);

                foreach (CommunicationProviderList Provider in Result)
                {
                    string Response = await _MessageService.SendEmailAsync(Email.Recepient, Email.Subject, Email.BCC, Email.CC, Email.Body, Provider.SendURL, Provider.UserID, Provider.Password, Convert.ToInt16(Provider.SenderID));

                    Email.BCC = Response;
                    CopyClass.CopyObject(Provider, ref _GetDataForParsingAPI);
                    _GenerateResponse = _WebApiParseResponse.ParseResponseViaRegex(Response, _GetDataForParsingAPI);
                    if (_GenerateResponse.Status == enTransactionStatus.Success)
                    {
                        Email.SentMessage();
                        _MessageRepository.Update(Email);
                        return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.EMailSuccessMessage }));
                    }
                    else
                    {
                        continue;
                    }
                }
                Email.FailMessage();
                _MessageRepository.Update(Email);
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.EmailFailMessage }));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.InternalError, ReturnMsg = EnResponseMessage.EmailExceptionMessage }));
            }
        }
Exemple #2
0
        public async Task <CommunicationResponse> Handle(SendSMSRequest Request, CancellationToken cancellationToken)
        {
            try
            {
                var Message = new MessagingQueue()
                {
                    MobileNo    = Request.MobileNo,
                    SMSText     = Request.Message,
                    SMSSendBy   = 0,
                    Status      = Convert.ToInt16(enMessageService.Init),
                    CreatedBy   = 1,
                    CreatedDate = DateTime.UtcNow
                };
                _MessageRepository.Add(Message);
                Message.InQueueMessage();
                _MessageRepository.Update(Message);
                IQueryable Result = await _MessageConfiguration.GetAPIConfigurationAsync(1, 1);

                foreach (CommunicationProviderList Provider in Result)
                {
                    string Response = await _MessageService.SendSMSAsync(Message.MobileNo, Message.SMSText, Provider.SendURL, Provider.SenderID, Provider.UserID, Provider.Password);

                    //string Response = " GUID:2387354506261631296 , responseTime:2018-10-05 16:00:46";
                    CopyClass.CopyObject(Provider, ref _GetDataForParsingAPI);
                    _GenerateResponse = _WebApiParseResponse.ParseResponseViaRegex(Response, _GetDataForParsingAPI);
                    if (_GenerateResponse.Status == enTransactionStatus.Success)
                    {
                        Message.SentMessage();
                        Message.RespText = Response;
                        _MessageRepository.Update(Message);
                        return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.SMSSuccessMessage }));
                    }
                    else
                    {
                        continue;
                    }
                }
                Message.FailMessage();
                _MessageRepository.Update(Message);
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.SMSFailMessage }));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.InternalError, ReturnMsg = EnResponseMessage.SMSExceptionMessage }));
            }
        }
        public async Task <CommunicationResponse> Handle(SendNotificationRequest Request, CancellationToken cancellationToken)
        {
            try
            {
                var Notification = new NotificationQueue()
                {
                    Message      = Request.Message,
                    Subject      = Request.Subject,
                    DeviceID     = Request.DeviceID,
                    TickerText   = Request.TickerText,
                    ContentTitle = Request.ContentTitle,
                    Status       = 0,
                    CreatedBy    = 1,
                    CreatedDate  = DateTime.UtcNow
                };
                _MessageRepository.Add(Notification);
                Notification.InQueueMessage();
                _MessageRepository.Update(Notification);
                IQueryable Result = await _MessageConfiguration.GetAPIConfigurationAsync(1, 2);

                foreach (CommunicationProviderList Provider in Result)
                {
                    string Response = await _MessageService.SendNotificationAsync(Notification.DeviceID, Notification.TickerText, Notification.ContentTitle, Notification.Message, Provider.SendURL, Provider.RequestFormat, Provider.SenderID, Provider.MethodType, Provider.ContentType);

                    CopyClass.CopyObject(Provider, ref _GetDataForParsingAPI);
                    _GenerateResponse = _WebApiParseResponse.ParseResponseViaRegex(Response, _GetDataForParsingAPI);
                    if (_GenerateResponse.Status == enTransactionStatus.Success)
                    {
                        Notification.SentMessage();
                        _MessageRepository.Update(Notification);
                        return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.NotificationSuccessMessage }));
                    }
                    else
                    {
                        continue;
                    }
                }
                Notification.FailMessage();
                _MessageRepository.Update(Notification);
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.NotificationFailMessage }));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.InternalError, ReturnMsg = EnResponseMessage.NotificationExceptionMessage }));
            }
        }