Exemplo n.º 1
0
        // POST: api/SLAReminder
        public IHttpActionResult StartNotification(CreateSLAReminderStatusModel request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var model = StartNotificationFunc(request);

            return(Ok(model));
        }
Exemplo n.º 2
0
        public SLAReminderStatus StartNotificationFunc(CreateSLAReminderStatusModel request)
        {
            SLAReminderStatus model = new SLAReminderStatus
            {
                NotificationType = request.NotificationType,
                NotificationReminderStatusType = request.NotificationReminderStatusType,
                StartDate = request.StartDate
            };

            db.SLAReminderStatus.Add(model);
            db.SaveChanges();

            return(model);
        }
Exemplo n.º 3
0
        public async void GenerateAutoNotificationReminder(NotificationType NotificationType,
                                                           ParameterListToSend paramToSend, DateTime NotificationStartDate)
        {
            List <DateTime> ScheduleMessage = GetSLAReminder(NotificationType, NotificationStartDate);
            var             template        = db.NotificationTemplates.Where(t => t.NotificationType == NotificationType).FirstOrDefault();

            // --> CALL StartNotification API (register SLAReminder) -> return [SLAReminderStatusId]
            CreateSLAReminderStatusModel objReminder = new CreateSLAReminderStatusModel
            {
                NotificationType = NotificationType,
                NotificationReminderStatusType = NotificationReminderStatusType.Open,
                StartDate = NotificationStartDate
            };
            var responseStartNotification = await WepApiMethod.SendApiAsync <CreateSLAReminderStatusModel>
                                                (HttpVerbs.Post, $"Reminder/SLA/StartNotification/", objReminder);

            if (responseStartNotification.isSuccess)
            {
                var SLAReminderId = responseStartNotification.Data.Id;

                if (template.enableEmail)
                {
                    string emailSubject = generateBodyMessage(template.TemplateSubject, NotificationType, paramToSend);
                    string emailBody    = generateBodyMessage(template.TemplateMessage, NotificationType, paramToSend);

                    //send notification mengikut jadual
                    foreach (var notifyDate in ScheduleMessage)
                    {
                        // --> CALL EMAIL API HERE---
                        //                          |   send received notificationId here
                        //                         \|/
                        int EmailNotificationId = 100; //assumed returned Id
                                                       // --> CALL insert BulkNotificationGroup API (NotificationMedium : Email, int [SLAReminderStatusId])
                        BulkNotificationModel objEmailNotification = new BulkNotificationModel
                        {
                            SLAReminderStatusId = SLAReminderId,
                            NotificationMedium  = NotificationMedium.Email,
                            NotificationId      = EmailNotificationId
                        };

                        var responseEmailNotificationGroup = await WepApiMethod.SendApiAsync <BulkNotificationModel>
                                                                 (HttpVerbs.Post, $"Reminder/SLA/RegisterBulkNotificationGroup/", objEmailNotification);
                    }
                }

                if (template.enableSMSMessage)
                {
                    foreach (var notifyDate in ScheduleMessage)
                    {
                        string SMSToSend = generateSMSMessage(template.SMSMessage, template.NotificationType, paramToSend);
                        // --> CALL SMS API HERE-----
                        //                          |   send received notificationId here
                        //                         \|/
                        int SMSNotificationId = 101; //assumed returned Id
                                                     // --> CALL insert BulkNotificationGroup API (NotificationMedium : SMS, [SLAReminderStatusId])
                        BulkNotificationModel objSMSNotification = new BulkNotificationModel
                        {
                            SLAReminderStatusId = SLAReminderId,
                            NotificationMedium  = NotificationMedium.SMS,
                            NotificationId      = SMSNotificationId
                        };
                        var responseSMSNotificationGroup = await WepApiMethod.SendApiAsync <BulkNotificationModel>
                                                               (HttpVerbs.Post, $"Reminder/SLA/RegisterBulkNotificationGroup/", objSMSNotification);
                    }
                }

                if (template.enableWebMessage)
                {
                    foreach (var notifyDate in ScheduleMessage)
                    {
                        string WebTextToSend = generateWEBMessage(template.WebMessage, template.NotificationType, paramToSend);
                        // --> CALL WEB API HERE-----
                        //                          |   send received notificationId here
                        //                         \|/
                        int WEBNotificationId = 102; //assumed returned Id
                                                     // --> CALL insert BulkNotificationGroup API (NotificationMedium : Web, [SLAReminderStatusId])
                        BulkNotificationModel objWEBNotification = new BulkNotificationModel
                        {
                            SLAReminderStatusId = SLAReminderId,
                            NotificationMedium  = NotificationMedium.Web,
                            NotificationId      = WEBNotificationId
                        };
                        var responseWEBNotificationGroup = await WepApiMethod.SendApiAsync <BulkNotificationModel>
                                                               (HttpVerbs.Post, $"Reminder/SLA/RegisterBulkNotificationGroup/", objWEBNotification);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> GenerateAutoNotificationReminder(CreateAutoReminder reminder)
        {
            List <DateTime> ScheduleMessage = GetSLAReminder(reminder.NotificationType, reminder.StartNotificationDate);
            var             template        = db.NotificationTemplates.Where(t => t.NotificationType == reminder.NotificationType).FirstOrDefault();
            int             SLAReminderId   = 0;

            // --> CALL StartNotification API (register SLAReminder) -> return [SLAReminderStatusId]
            CreateSLAReminderStatusModel objReminder = new CreateSLAReminderStatusModel
            {
                NotificationType = reminder.NotificationType,
                NotificationReminderStatusType = NotificationReminderStatusType.Open,
                StartDate = reminder.StartNotificationDate
            };
            var responseStartNotification = StartNotificationFunc(objReminder);

            /*var responseStartNotification = await WepApiMethod.SendApiAsync<CreateSLAReminderStatusModel>
             *  (HttpVerbs.Post, $"Reminder/SLA/StartNotification/", objReminder);*/

            if (responseStartNotification != null)
            {
                SLAReminderId = responseStartNotification.Id;

                if (template.enableEmail)
                {
                    string emailSubject = generateBodyMessage(template.TemplateSubject, reminder.NotificationType, reminder.ParameterListToSend);

                    //send email ke setiap reciever
                    foreach (var receiver in reminder.ReceiverId)
                    {
                        string receiverEmailAddress = db.User.Find(receiver).Email;

                        reminder.ParameterListToSend.ReceiverFullName = GetReceiverFullName(receiverEmailAddress);

                        string emailBody = generateBodyMessage(template.TemplateMessage, reminder.NotificationType, reminder.ParameterListToSend);

                        int counter = 1;
                        //send notification mengikut jadual
                        foreach (var notifyDate in ScheduleMessage)
                        {
                            // --> CALL EMAIL API HERE---
                            //                          |   send received notificationId here
                            //                         \|/
                            var response = await sendEmailUsingAPIAsync(notifyDate, (int)reminder.NotificationCategory, (int)reminder.NotificationType, receiverEmailAddress, emailSubject, emailBody, counter);

                            if (response != null)
                            {
                                string EmailNotificationId = response.datID; //assumed returned Id
                                // --> CALL insert BulkNotificationGroup API (NotificationMedium : Email, int [SLAReminderStatusId])
                                BulkNotificationModel objEmailNotification = new BulkNotificationModel
                                {
                                    SLAReminderStatusId = SLAReminderId,
                                    NotificationMedium  = NotificationMedium.Email,
                                    NotificationId      = EmailNotificationId
                                };

                                var responseEmailNotificationGroup = RegisterBulkNotificationGroupFunc(objEmailNotification);
                            }
                            counter++;
                        }
                    }
                }

                if (template.enableSMSMessage)
                {
                    //send sms ke setiap reciever
                    foreach (var receiver in reminder.ReceiverId)
                    {
                        string receiverPhoneNo = db.User.Find(receiver).MobileNo;
                        int    counter         = 1;
                        foreach (var notifyDate in ScheduleMessage)
                        {
                            string SMSToSend = generateSMSMessage(template.SMSMessage, template.NotificationType, reminder.ParameterListToSend);
                            // --> CALL SMS API HERE-----
                            //                          |   send received notificationId here
                            //                         \|/
                            var response = await sendSMSUsingAPIAsync(notifyDate, (int)reminder.NotificationCategory, (int)reminder.NotificationType, receiverPhoneNo, null, SMSToSend, counter);

                            if (response != null)
                            {
                                string SMSNotificationId = response.datID; //assumed returned Id
                                // --> CALL insert BulkNotificationGroup API (NotificationMedium : SMS, [SLAReminderStatusId])
                                BulkNotificationModel objSMSNotification = new BulkNotificationModel
                                {
                                    SLAReminderStatusId = SLAReminderId,
                                    NotificationMedium  = NotificationMedium.SMS,
                                    NotificationId      = SMSNotificationId
                                };

                                var responseSMSNotificationGroup = RegisterBulkNotificationGroupFunc(objSMSNotification);
                            }
                            counter++;
                        }
                    }
                }

                if (template.enableWebMessage)
                {
                    foreach (var receiver in reminder.ReceiverId)
                    {
                        int counter = 1;

                        foreach (var notifyDate in ScheduleMessage)
                        {
                            string WebTextToSend     = generateWEBMessage(template.WebMessage, template.NotificationType, reminder.ParameterListToSend);
                            string WebLinkTextToSend = generateWEBLinkMessage(template.WebNotifyLink, template.NotificationType, reminder.ParameterListToSend);
                            // --> CALL WEB API HERE-----
                            //                          |   send received notificationId here
                            //                         \|/
                            CreateNotificationModel model = new CreateNotificationModel
                            {
                                UserId           = receiver,
                                NotificationType = reminder.NotificationType,
                                Category         = reminder.NotificationCategory,
                                Message          = WebTextToSend,
                                Link             = WebLinkTextToSend,
                                SendDate         = notifyDate
                            };
                            var response = await sendWebNotifyAPI(model);

                            if (response != -1)
                            {
                                string WEBNotificationId = response.ToString(); //assumed returned Id
                                // --> CALL insert BulkNotificationGroup API (NotificationMedium : Web, [SLAReminderStatusId])
                                BulkNotificationModel objWEBNotification = new BulkNotificationModel
                                {
                                    SLAReminderStatusId = SLAReminderId,
                                    NotificationMedium  = NotificationMedium.Web,
                                    NotificationId      = WEBNotificationId
                                };
                                var responseWEBNotificationGroup = RegisterBulkNotificationGroup(objWEBNotification);
                            }

                            counter++;
                        }
                    }
                }

                ReminderResponse result = new ReminderResponse
                {
                    Status = "Success",
                    SLAReminderStatusId = SLAReminderId
                };
                return(Ok(result));
            }
            else
            {
                ReminderResponse result = new ReminderResponse
                {
                    Status = "Failed",
                    SLAReminderStatusId = SLAReminderId
                };
                return(Ok(result));
            }
        }