예제 #1
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);
                    }
                }
            }
        }
예제 #2
0
        public async Task <ActionResult> List(FilterUserLogModel filter)
        {
            var response = await WepApiMethod.SendApiAsync <DataTableResponse>(HttpVerbs.Post, $"Logs/UserLog/GetAll", filter);

            return(Content(JsonConvert.SerializeObject(response.Data), "application/json"));
        }
        public async Task <ActionResult> List(FilterEventExternalExhibitorModel filter)
        {
            var response = await WepApiMethod.SendApiAsync <DataTableResponse>(HttpVerbs.Post, $"eEvent/EventExternalExhibitor/GetExternalExhibitorList", filter);

            return(Content(JsonConvert.SerializeObject(response.Data), "application/json"));
        }
예제 #4
0
        public async Task <ActionResult> Edit(Models.EditKMCModel model)
        {
            if (model.IsPublic)
            {
                ModelState.Remove("RoleIds");
            }

            if (model.IsEditor)
            {
                ModelState.Remove("File");
                ModelState.Remove("Type");
            }
            else
            {
                ModelState.Remove("EditorCode");

                //validation of file type
                if (model.File != null)
                {
                    var isValid = true;

                    switch (model.Type)
                    {
                    case KMCType.Image:
                        isValid = FileMethod.IsValidType(model.File, filter_imgs);
                        break;

                    case KMCType.Video:
                        isValid = FileMethod.IsValidType(model.File, filter_videos);
                        break;

                    case KMCType.Audio:
                        isValid = FileMethod.IsValidType(model.File, filter_audios);
                        break;

                    case KMCType.Document:
                        isValid = FileMethod.IsValidType(model.File, filter_docs);
                        break;

                    case KMCType.Others:

                        break;

                    default:
                        break;
                    }

                    if (!isValid)
                    {
                        ModelState.AddModelError("File", Language.KMC.ValidIsValidTypeFile);
                    }
                }
                else
                {
                    if (model.FileId != null)
                    {
                        ModelState.Remove("File");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var modelapi = new EditKMCModel
                {
                    KMCCategoryId = model.CategoryId,
                    Title         = model.Title,
                    Description   = model.Description,
                    Type          = model.Type,
                    IsPublic      = model.IsPublic,
                    IsShow        = model.IsShow,
                    IsEditor      = model.IsEditor,
                    RoleIds       = model.RoleIds,
                    EditorCode    = model.EditorCode,
                    FileId        = model.IsEditor ? null : model.FileId,
                    ThumbnailUrl  = model.ThumbnailUrl
                };

                if (model.ThumbnailFile != null)
                {
                    var filename = FileMethod.SaveFile(model.ThumbnailFile, Server.MapPath("~/img/kmc-thumbnail"), model.ThumbnailUrl);
                    modelapi.ThumbnailUrl = filename;
                }

                if (model.File != null)
                {
                    var responseFile = await FileMethod.UploadFile(new List <HttpPostedFileBase> {
                        model.File
                    }, CurrentUser.UserId, "KMC/", model.File.ContentType);

                    if (responseFile != null)
                    {
                        modelapi.FileId   = responseFile.Select(f => f.Id).FirstOrDefault();
                        modelapi.FileType = model.File.ContentType;
                    }
                }

                var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"KMC/Manage?id={model.Id}", modelapi);

                if (response.isSuccess)
                {
                    if (!model.IsPublic && model.IsShow)//send notification
                    {
                        var userIds = new List <int>();

                        foreach (var roleId in model.RoleIds)
                        {
                            var responseUsers = await WepApiMethod.SendApiAsync <List <UserModel> >(HttpVerbs.Get, $"Administration/Role/GetAllUser?roleId={roleId}");

                            if (responseUsers.isSuccess)
                            {
                                userIds = userIds.Union(responseUsers.Data.Select(r => r.Id).ToList()).ToList();
                            }
                        }

                        if (userIds.Count > 0)
                        {
                            ParameterListToSend notificationParameter = new ParameterListToSend();
                            notificationParameter.Link = $"<a href = '" + BaseURL + "/KMC/Home/Browse/" + model.Id.ToString() + "' > here </a>";

                            CreateAutoReminder notification = new CreateAutoReminder
                            {
                                NotificationType      = NotificationType.KMCCreated,
                                NotificationCategory  = NotificationCategory.Learning,
                                ParameterListToSend   = notificationParameter,
                                StartNotificationDate = DateTime.Now,
                                ReceiverId            = userIds
                            };

                            var responseNotification = await WepApiMethod.SendApiAsync <ReminderResponse>(HttpVerbs.Post, $"Reminder/SLA/GenerateAutoNotificationReminder/", notification);
                        }
                    }

                    await LogActivity(Modules.KMC, "Edit KMC", model);

                    TempData["SuccessMessage"] = Language.KMC.AlertSuccessUpdate;

                    return(RedirectToAction("Details", "Manage", new { area = "KMC", @id = model.Id }));
                }
                else
                {
                    TempData["ErrorMessage"] = Language.KMC.AlertFailDelete;
                }
            }

            model.filter_imgs   = filter_imgs;
            model.filter_videos = filter_videos;
            model.filter_audios = filter_audios;
            model.filter_docs   = filter_docs;

            model.Roles = new SelectList(await GetRoles(), "Id", "Name", 0);

            return(View(model));
        }
예제 #5
0
        public async Task <ActionResult> SubmitForApproval(CourseApprovalLogModel model)
        {
            if (!CurrentUser.HasAccess(UserAccess.CourseVerify) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval1) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval2) &&
                !CurrentUser.HasAccess(UserAccess.CourseApproval3))
            {
                return(new HttpUnauthorizedResult());
            }

            model.CreatedBy     = CurrentUser.UserId.Value;
            model.CreatedByName = CurrentUser.Name;

            if (model.CreatedBy < 1)
            {
                TempData["ErrorMessage"] = $"Error submitting the course {model.CourseTitle} for verification";
                return(RedirectToAction("Index", "Courses", new { area = "eLearning" }));
            }

            var response = await WepApiMethod.SendApiAsync <CourseApprovalLogModel>(HttpVerbs.Post, CourseApprovalApiUrl.SubmitForApproval, model);

            if (response.isSuccess)
            {
                // Approval level is updated on the response Data
                model = response.Data;

                if (!model.IsApproved)
                {
                    await LogActivity(Modules.Learning, "Course Require AMENDMENT. Course : " + model.CourseTitle, model.CreatedBy);

                    TempData["SuccessMessage"] = $"Course titled {model.CourseTitle} updated as Pending Amendment.";

                    await Notifier.SubmitCourseForAmendment(NotificationType.Course_Amendment,
                                                            model.CourseId, CurrentUser.UserId.Value, "", model.CreatedByName,
                                                            model.CourseTitle, Url.AbsoluteAction("Content", "Courses", new { id = model.CourseId }));

                    return(RedirectToAction("Index", "Courses", new { area = "eLearning" }));
                }

                // Approved
                if (model.Status == CourseStatus.Verified)
                {
                    await LogActivity(Modules.Learning, "Successfully VERIFIED. Further approval to the next level. Course : " + model.CourseTitle, model.CreatedBy);

                    TempData["SuccessMessage"] = $"Course titled {model.CourseTitle} successfully updated as Verified.";

                    await Notifier.SubmitCourseForApproval(NotificationType.Approve_Courses_Creation_Approver1,
                                                           model.CourseId, CurrentUser.UserId.Value, "", model.CreatedByName,
                                                           model.CourseTitle, Url.AbsoluteAction("Approve", "CourseApprovals", new { id = model.CourseId }));

                    return(RedirectToAction("Index", "Courses", new { area = "eLearning" }));
                }

                if ((model.Status == CourseStatus.FirstApproval || model.Status == CourseStatus.SecondApproval) && model.IsNextLevelRequired)
                {
                    await LogActivity(Modules.Learning, "Successfully APPROVED. Further approval to the next level. Course : " + model.CourseTitle);

                    TempData["SuccessMessage"] = $"Course {model.CourseTitle} successfully submitted for next approver.";

                    // notify next level
                    NotificationType notifyType = NotificationType.Approve_Courses_Creation_Approver1;
                    if (model.Status == CourseStatus.FirstApproval)
                    {
                        notifyType = NotificationType.Approve_Courses_Creation_Approver2;
                    }
                    else
                    if (model.Status == CourseStatus.SecondApproval)
                    {
                        notifyType = NotificationType.Approve_Courses_Creation_Approver3;
                    }

                    await Notifier.SubmitCourseForApproval(notifyType,
                                                           model.CourseId, CurrentUser.UserId.Value, "", model.CreatedByName,
                                                           model.CourseTitle, Url.AbsoluteAction("Approve", "CourseApprovals", new { id = model.CourseId }));
                }
                else
                {
                    await LogActivity(Modules.Learning, "Successfully APPROVED. Course - " + model.CourseTitle);

                    await Notifier.SubmitCourseForApproval(NotificationType.Course_Approved,
                                                           model.CourseId, CurrentUser.UserId.Value, "", model.CreatedByName,
                                                           model.CourseTitle, Url.AbsoluteAction("Approve", "CourseApprovals", new { id = model.CourseId }));

                    TempData["SuccessMessage"] = $"Course titled {model.CourseTitle} is Approved.";
                }
            }
            else
            {
                TempData["ErrorMessage"] = $"Error submitting the course {model.CourseTitle} for Verification";
            }
            return(RedirectToAction("Index", "Courses", new { area = "eLearning" }));
        }
        public async Task <ActionResult> Create(CreateNotificationTemplateModel model)//([Bind(Include = "Id,TemplateName,TemplateMessage,CreatedDate,CreatedBy,Display")] EmailTemplate emailTemplate)

        {
            if (ModelState.IsValid)
            {
                CreateNotificationTemplateModel obj = new CreateNotificationTemplateModel
                {
                    NotificationType = model.NotificationType,
                    TemplateName     = model.TemplateName,
                    TemplateSubject  = model.TemplateSubject,
                    TemplateRefNo    = model.TemplateRefNo,
                    TemplateMessage  = Server.HtmlEncode(model.TemplateMessage),
                    enableEmail      = model.enableEmail,
                    CreatedBy        = CurrentUser.UserId.Value,
                    CreatedDate      = DateTime.Now,
                    //LastModified = DateTime.Now,
                    enableSMSMessage = model.enableSMSMessage,
                    SMSMessage       = model.SMSMessage,
                    enableWebMessage = model.enableWebMessage,
                    WebMessage       = model.WebMessage,
                    WebNotifyLink    = model.WebNotifyLink,
                    //Display = true
                };

                List <string> ListA, ParamList;// = new List<string>();
                ListA     = new List <string>();
                ParamList = new List <string>();
                if (obj.enableEmail)
                {
                    ParamList = ParamList.Union(ListA).ToList();
                    if (obj.TemplateSubject != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(obj.TemplateSubject)).ToList();
                    }
                    if (obj.TemplateMessage != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(obj.TemplateMessage)).ToList();
                    }
                }
                if (obj.enableSMSMessage)
                {
                    if (obj.SMSMessage != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(obj.SMSMessage)).ToList();
                    }
                }
                if (obj.enableWebMessage)
                {
                    if (obj.WebMessage != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(obj.WebMessage)).ToList();
                        ParamList = ParamList.Union(ParameterListing(obj.WebNotifyLink)).ToList();
                    }
                }

                obj.ParameterList = ParamList;

                //var response = await WepApiMethod.SendApiAsync<CreateNotificationTemplateModel>(HttpVerbs.Post, $"Template/Email/", obj);

                //test generate email
                //1 create ParamListToSend
                //2 generate body message
                //3 generate subject message
                //4 generate schedule to send email
                //5 call email API
                ParameterListToSend paramToSend = new ParameterListToSend();
                paramToSend.EventName     = "Hari Terbuka AKPK";
                paramToSend.EventCode     = "HTAKPK2019";
                paramToSend.EventLocation = "Dewan Terbuka AKPK";
                paramToSend.EventApproval = "APPROVED006";

                CreateAutoReminder reminder = new CreateAutoReminder
                {
                    NotificationType      = NotificationType.Submit_Public_Event_For_Verification,
                    NotificationCategory  = NotificationCategory.Event,
                    ParameterListToSend   = paramToSend,
                    StartNotificationDate = DateTime.Now,
                    ReceiverId            = new List <int> {
                        231
                    }
                };

                var response = await WepApiMethod.SendApiAsync <ReminderResponse>
                                   (HttpVerbs.Post, $"Reminder/SLA/GenerateAutoNotificationReminder/", reminder);

                /*int SLAReminderStatusId = 8;
                 * var response = await WepApiMethod.SendApiAsync<List<BulkNotificationModel>>
                 *  (HttpVerbs.Get, $"Reminder/SLA/StopNotification/?SLAReminderStatusId={SLAReminderStatusId}");*/

                if (response.isSuccess)
                {
                    await LogActivity(Modules.Setting, "Create Notification Template");

                    TempData["SuccessMessage"] = "Notification Template created successfully";


                    return(RedirectToAction("List"));
                }
                else
                {
                    TempData["ErrorMessage"] = "Failed to create Notification Template";
                    return(RedirectToAction("List"));
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Failed to create Notification Template";
                return(RedirectToAction("List"));
            }
        }
        // GET: Template/EmailTemplates/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var response = await WepApiMethod.SendApiAsync <DetailsNotificationTemplateModel>(HttpVerbs.Get, $"Template/Email?id={id}");

            if (!response.isSuccess)
            {
                return(HttpNotFound());
            }

            EditNotificationTemplateModel model = new EditNotificationTemplateModel
            {
                Id = response.Data.Id,
                NotificationType     = response.Data.NotificationType,
                NotificationCategory = response.Data.NotificationCategory,
                TemplateName         = response.Data.TemplateName,
                TemplateSubject      = response.Data.TemplateSubject,
                TemplateRefNo        = response.Data.TemplateRefNo,
                TemplateMessage      = HttpUtility.HtmlDecode(response.Data.TemplateMessage),
                enableEmail          = response.Data.enableEmail,
                enableSMSMessage     = response.Data.enableSMSMessage,
                SMSMessage           = response.Data.SMSMessage,
                enableWebMessage     = response.Data.enableWebMessage,
                WebMessage           = response.Data.WebMessage,
                WebNotifyLink        = response.Data.WebNotifyLink
            };

            model.NotificationTypeList = (Enum.GetValues(typeof(NotificationType)).Cast <int>()
                                          .Select(e => new SelectListItem()
            {
                Text = ((DisplayAttribute)
                        typeof(NotificationType)
                        .GetMember(Enum.GetName(typeof(NotificationType), e).ToString())
                        .First()
                        .GetCustomAttributes(typeof(DisplayAttribute), false)[0]).Name,
                //Enum.GetName(typeof(NotificationType), e),
                Value = e.ToString()
            })).ToList();

            /*
             * foreach (TemplateParameterType param in Enum.GetValues(typeof(TemplateParameterType)))
             * {
             *  ParameterList paramList = new ParameterList
             *  {
             *      TemplateParameterType = param,
             *      parameterDisplayName = param.GetDisplayName()
             *  };
             *  model.TemplateParameterTypeList.Add(paramList);
             * }*/
            model.TemplateParameterTypeList = new List <ParameterList>();
            var response2 = await WepApiMethod.SendApiAsync <List <TemplateParameterType> >
                                (HttpVerbs.Get, $"Reminder/SLA/GetParameterList?id={(int)model.NotificationType}");

            if (response2.isSuccess && response2.Data != null)
            {
                foreach (var item in response2.Data)
                {
                    ParameterList paramList = new ParameterList
                    {
                        TemplateParameterType = item,
                        parameterDisplayName  = item.GetDisplayName()
                    };
                    model.TemplateParameterTypeList.Add(paramList);
                }
            }
            return(View(model));
        }
예제 #8
0
        public async Task <ActionResult> Index(FilterTargetedGroup filter)
        {
            var response = await WepApiMethod.SendApiAsync <DataTableResponse>(HttpVerbs.Post, $"Setting/Group/GetAll", filter);

            return(Content(JsonConvert.SerializeObject(response.Data), "application/json"));
        }