Пример #1
0
        public async Task <ActionResult> ResetPassword(ResetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Post, $"Auth/ResetPassword", model);

                if (response.Data != null)
                {
                    ParameterListToSend notificationParameter = new ParameterListToSend();
                    notificationParameter.UserFullName = response.Data.Name;
                    notificationParameter.Link         = $"<a href = '" + BaseURL + "/Auth/SetPassword/" + response.Data.UID + "' > here </a>";

                    CreateAutoReminder notification = new CreateAutoReminder
                    {
                        NotificationType      = NotificationType.ResetPassword,
                        NotificationCategory  = NotificationCategory.Learning,
                        ParameterListToSend   = notificationParameter,
                        StartNotificationDate = DateTime.Now,
                        ReceiverId            = new List <int> {
                            (int)response.Data.UserId
                        }
                    };

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

                TempData["Message"] = Language.Auth.AlertResetPasswordSuccess;
                return(RedirectToAction("Login"));
            }

            return(View());
        }
Пример #2
0
        public async Task <ActionResult> ResetPasswordConfirm(int?id, string Email)
        {
            if (id == null || string.IsNullOrEmpty(Email))
            {
                return(HttpNotFound());
            }

            var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Post, $"Auth/ResetPassword", new { Email = Email });

            if (response.isSuccess)
            {
                //StringBuilder body = new StringBuilder();
                //body.Append("Dear " + response.Data.Name + ",");
                //body.Append("<br />");
                //body.Append("You can reset your password <a href = '" + BaseURL + Url.Action("SetPassword", "Auth", new { id = response.Data }) + "' > here </a>");

                //await EmailMethod.SendEmail("FE Portal Password Reset By Admin", body.ToString(), new EmailAddress { DisplayName = response.Data.Name, Address = Email });

                ParameterListToSend notificationParameter = new ParameterListToSend();
                notificationParameter.UserFullName = response.Data.Name;
                notificationParameter.Link         = $"<a href = '" + BaseURL + Url.Action("SetPassword", "Auth", new { id = response.Data.UID }) + "' > here </a>";

                CreateAutoReminder notification = new CreateAutoReminder
                {
                    NotificationType      = NotificationType.ResetPassword,
                    NotificationCategory  = NotificationCategory.Event,
                    ParameterListToSend   = notificationParameter,
                    StartNotificationDate = DateTime.Now,
                    ReceiverId            = new List <int> {
                        (int)response.Data.UserId
                    }
                };

                await LogActivity(Modules.Setting, "Reset Agency User Account Password", new { id = id });

                TempData["SuccessMessage"] = Language.Administrator.Company.AlertResetSuccess;

                return(RedirectToAction("Details", "Company", new { area = "Administrator", @id = id }));
            }
            else
            {
                TempData["ErrorMessage"] = Language.Administrator.Company.AlertResetFail;

                return(RedirectToAction("Details", "Company", new { area = "Administrator", @id = id }));
            }
        }
Пример #3
0
        public async Task <ActionResult> ChangeEmail(ChangeEmailModel model)
        {
            var emailResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/User/IsEmailExist?id={CurrentUser.UserId}&email={model.Email}");

            if (emailResponse.Data)
            {
                ModelState.AddModelError("Email", Language.Profile.ValidIsExistEmail);
            }

            if (ModelState.IsValid)
            {
                var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Put, $"Home/Profile/ChangeEmail?id={CurrentUser.UserId}", model);

                if (response.isSuccess)
                {
                    ParameterListToSend notificationParameter = new ParameterListToSend();
                    notificationParameter.UserFullName = CurrentUser.Name;
                    notificationParameter.Link         = $"<a href = '" + BaseURL + "/Auth/ActivateAccount/" + response.Data.UID + "' > here </a>";
                    notificationParameter.LoginDetail  = $"Email: { model.Email }";

                    CreateAutoReminder notification = new CreateAutoReminder
                    {
                        NotificationType      = NotificationType.ActivateAccount,
                        NotificationCategory  = NotificationCategory.Event,
                        ParameterListToSend   = notificationParameter,
                        StartNotificationDate = DateTime.Now,
                        ReceiverId            = new List <int> {
                            (int)CurrentUser.UserId
                        }
                    };

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

                    await LogActivity(Modules.Setting, "Change Email");

                    TempData["SuccessMessage"] = Language.Profile.AlertSuccessChangeEmail;

                    return(RedirectToAction("MyProfile", "Home", new { area = "" }));
                }
            }

            TempData["ErrorMessage"] = Language.Profile.AlertFailChangeEmail;

            return(View());
        }
Пример #4
0
        public async Task <ActionResult> ResetPasswordConfirm(int?id, string Email)
        {
            if (id == null || string.IsNullOrEmpty(Email))
            {
                return(HttpNotFound());
            }

            var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Post, $"Auth/ResetPassword", new { Email = Email });

            if (response.isSuccess)
            {
                ParameterListToSend notificationParameter = new ParameterListToSend();
                notificationParameter.UserFullName = response.Data.Name;
                notificationParameter.Link         = $"<a href = '" + BaseURL + Url.Action("SetPassword", "Auth", new { id = response.Data.UID }) + "' > here </a>";

                CreateAutoReminder notification = new CreateAutoReminder
                {
                    NotificationType      = NotificationType.ResetPassword,
                    NotificationCategory  = NotificationCategory.Event,
                    ParameterListToSend   = notificationParameter,
                    StartNotificationDate = DateTime.Now,
                    ReceiverId            = new List <int> {
                        (int)response.Data.UserId
                    }
                };

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

                await LogActivity(Modules.Setting, "Reset Individual User Account Password", new { id = id });

                TempData["SuccessMessage"] = Language.Administrator.Individual.AlertResetSuccess;

                return(RedirectToAction("Details", "Individual", new { area = "Administrator", @id = id }));
            }
            else
            {
                TempData["ErrorMessage"] = Language.Administrator.Individual.AlertResetFail;

                return(RedirectToAction("Details", "Individual", new { area = "Administrator", @id = id }));
            }
        }
Пример #5
0
        public async Task <ActionResult> Create(CreateCompanyModel model)
        {
            if (model.Type == CompanyType.Government)
            {
                ModelState.Remove("PassportNo");
                ModelState.Remove("PostCodeNonMalaysian");
                ModelState.Remove("State");
                ModelState.Remove("CountryId");
                ModelState.Remove("CompanyName");
                ModelState.Remove("CompanyRegNo");
                ModelState.Remove("SectorId");

                model.CountryId = model.MalaysiaCountryId;
            }
            else if (model.Type == CompanyType.MalaysianCompany)
            {
                ModelState.Remove("PassportNo");
                ModelState.Remove("PostCodeNonMalaysian");
                ModelState.Remove("State");
                ModelState.Remove("CountryId");
                ModelState.Remove("AgencyName");
                ModelState.Remove("MinistryId");

                model.CountryId = model.MalaysiaCountryId;
            }
            else
            {
                ModelState.Remove("ICNo");
                ModelState.Remove("PostCodeMalaysian");
                ModelState.Remove("StateId");
                ModelState.Remove("AgencyName");
                ModelState.Remove("MinistryId");
                ModelState.Remove("CompanyRegNo");
            }

            var emailResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/User/IsEmailExist?id={null}&email={model.Email}");

            if (emailResponse.isSuccess)
            {
                ModelState.AddModelError("Email", Language.Administrator.Company.ValidIsExistEmail);
            }

            var icno = model.ICNo;

            if (model.Type == CompanyType.NonMalaysianCompany)
            {
                icno = model.PassportNo;
            }

            var icnoResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/User/IsICNoExist?id={null}&icno={icno}");

            if (icnoResponse.isSuccess)
            {
                if (model.Type == CompanyType.NonMalaysianCompany)
                {
                    ModelState.AddModelError("PassportNo", Language.Administrator.Company.ValidIsExistPassportNo);
                }
                else
                {
                    ModelState.AddModelError("ICNo", Language.Administrator.Company.ValidIsExistICNo);
                }
            }

            if (ModelState.IsValid)
            {
                var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Post, $"Administration/Company", model);

                if (response.isSuccess)
                {
                    ParameterListToSend notificationParameter = new ParameterListToSend();
                    notificationParameter.UserFullName = model.Name;
                    notificationParameter.Link         = $"<a href = '" + BaseURL + "/Auth/ActivateAccount/" + response.Data.UID + "' > here </a>";
                    notificationParameter.LoginDetail  = $"Email: { model.Email }\nPassword: { response.Data.Password }";

                    CreateAutoReminder notification = new CreateAutoReminder
                    {
                        NotificationType      = NotificationType.ActivateAccount,
                        NotificationCategory  = NotificationCategory.Learning,
                        ParameterListToSend   = notificationParameter,
                        StartNotificationDate = DateTime.Now,
                        ReceiverId            = new List <int> {
                            (int)response.Data.UserId
                        }
                    };

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

                    await LogActivity(Modules.Setting, "Create Agency User", model);

                    TempData["SuccessMessage"] = Language.Administrator.Company.AlertCreateSuccess;

                    return(RedirectToAction("List", "Company", new { area = "Administrator" }));
                }
                else
                {
                    TempData["SuccessMessage"] = Language.Administrator.Company.AlertCreateFail;

                    return(RedirectToAction("List", "Company", new { area = "Administrator" }));
                }
            }

            var countries = await GetCountries();

            model.MalaysiaCountryId = countries.Where(c => c.Name == "Malaysia").Select(s => s.Id).FirstOrDefault();
            model.CountryCode       = countries.Where(c => c.Name == "Malaysia").Select(s => s.CountryCode).FirstOrDefault();

            model.Sectors    = new SelectList(await GetSectors(), "Id", "Name", 0);
            model.States     = new SelectList(await GetStates(), "Id", "Name", 0);
            model.Ministries = new SelectList(await GetMinistry(), "Id", "Name", 0);
            model.Countries  = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0);
            model.Roles      = new SelectList(await GetRoles(), "Id", "Name", 0);

            return(View(model));
        }
Пример #6
0
        public async Task <ActionResult> RegisterAgency(RegisterAgencyModel model)
        {
            if (model.Type == CompanyType.Government)
            {
                ModelState.Remove("PassportNo");
                ModelState.Remove("PostCodeNonMalaysian");
                ModelState.Remove("State");
                ModelState.Remove("CountryId");
                ModelState.Remove("CompanyName");
                ModelState.Remove("CompanyRegNo");
                ModelState.Remove("SectorId");

                model.CountryId = model.MalaysiaCountryId;
            }
            else if (model.Type == CompanyType.MalaysianCompany)
            {
                ModelState.Remove("PassportNo");
                ModelState.Remove("PostCodeNonMalaysian");
                ModelState.Remove("State");
                ModelState.Remove("CountryId");
                ModelState.Remove("AgencyName");
                ModelState.Remove("MinistryId");

                model.CountryId = model.MalaysiaCountryId;
            }
            else
            {
                ModelState.Remove("ICNo");
                ModelState.Remove("PostCodeMalaysian");
                ModelState.Remove("StateId");
                ModelState.Remove("AgencyName");
                ModelState.Remove("MinistryId");
                ModelState.Remove("CompanyRegNo");
            }

            var emailResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/User/IsEmailExist?id={null}&email={model.Email}");

            if (emailResponse.Data)
            {
                ModelState.AddModelError("Email", Language.Auth.ValidIsExistEmail);
            }

            var icno = model.ICNo;

            if (model.Type == CompanyType.NonMalaysianCompany)
            {
                icno = model.PassportNo;
            }

            var icnoResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/User/IsICNoExist?id={null}&icno={icno}");

            if (icnoResponse.Data)
            {
                if (model.Type == CompanyType.NonMalaysianCompany)
                {
                    ModelState.AddModelError("PassportNo", Language.Auth.ValidIsExistPassportNo);
                }
                else
                {
                    ModelState.AddModelError("ICNo", Language.Auth.ValidIsExistICNo);
                }
            }

            var passwordResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Auth/ValidatePassword?password={model.Password}");

            if (!passwordResponse.isSuccess)
            {
                var error = JsonConvert.DeserializeObject <Dictionary <string, string> >(passwordResponse.ErrorMessage);

                if (error.ContainsKey("Message"))
                {
                    ModelState.AddModelError("Password", error["Message"]);
                }
            }

            if (ModelState.IsValid)
            {
                var response = await WepApiMethod.SendApiAsync <dynamic>(HttpVerbs.Post, $"Auth/RegisterAgency", model);

                if (response.isSuccess)
                {
                    ParameterListToSend notificationParameter = new ParameterListToSend();
                    notificationParameter.UserFullName = model.Name;
                    notificationParameter.Link         = $"<a href = '" + BaseURL + "/Auth/ActivateAccount/" + response.Data.UID + "' > here </a>";
                    notificationParameter.LoginDetail  = $"Email: { model.Email }\nPassword: { model.Password }";

                    CreateAutoReminder notification = new CreateAutoReminder
                    {
                        NotificationType      = NotificationType.ActivateAccount,
                        NotificationCategory  = NotificationCategory.Learning,
                        ParameterListToSend   = notificationParameter,
                        StartNotificationDate = DateTime.Now,
                        ReceiverId            = new List <int> {
                            (int)response.Data.UserId
                        }
                    };

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

                    TempData["SuccessMessage"] = Language.Auth.AlertRegisterSuccess;

                    return(RedirectToAction("Login", "Auth", new { area = "" }));
                }
            }

            model = await InitRegisterCompany(model);

            return(View(model));
        }
Пример #7
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));
            }
        }
Пример #8
0
        public async Task <IHttpActionResult> SendNotification(NotificationModel model)
        {
            var receivers = new List <int>();

            if (model.ReceiverType == ReceiverType.UserIds || model.ReceiverType == ReceiverType.Both)
            {
                switch (model.NotificationType)
                {
                case NotificationType.Verify_Courses_Creation:
                    receivers = await GetUserIds(UserAccess.CourseVerify);

                    break;

                case NotificationType.Approve_Courses_Creation_Approver1:
                    receivers = await GetUserIds(UserAccess.CourseApproval1);

                    break;

                case NotificationType.Approve_Courses_Creation_Approver2:
                    receivers = await GetUserIds(UserAccess.CourseApproval2);

                    break;

                case NotificationType.Approve_Courses_Creation_Approver3:
                    receivers = await GetUserIds(UserAccess.CourseApproval3);

                    break;

                case NotificationType.Course_Amendment:
                    receivers = await GetUserIds(UserAccess.CourseCreate);

                    break;

                case NotificationType.Course_Approved:
                    receivers = await GetUserIds(UserAccess.CourseCreate);

                    break;

                case NotificationType.Course_Assigned_To_Facilitator:
                    //get trainer assigned to the course
                    receivers = model.Receivers;
                    break;

                case NotificationType.Course_Student_Enrolled:
                    receivers = await GetCourseTrainers(model.Id);

                    // get student name
                    var user = await db.User.FindAsync(model.SenderId);

                    model.ParameterListToSend.LearnerName = user != null ? user.Name : "";

                    break;

                case NotificationType.Notify_Admin_Participant_Withdraw:
                    var admin = await db.Courses.FindAsync(model.Id);

                    if (admin != null)
                    {
                        receivers.Add(admin.CreatedBy);
                    }

                    break;

                case NotificationType.Notify_Self_Withdraw_From_Course:
                case NotificationType.Verify_Courses_Creation_Self:
                case NotificationType.Approve_Courses_Creation_Approver_Self:
                case NotificationType.Course_Amendment_Self:

                    receivers.Add(model.SenderId);

                    break;

                case NotificationType.Course_Approved_Others:

                    receivers.AddRange(await GetUserIds(UserAccess.CourseVerify));

                    break;

                case NotificationType.Course_Approved_Self:

                    receivers.Add(model.SenderId);
                    break;

                case NotificationType.Course_Publish:

                    receivers.Add(model.SenderId);
                    receivers.AddRange(await GetUserIds(UserAccess.CourseVerify));
                    receivers.AddRange(await GetUserIds(UserAccess.CourseApproval1));
                    receivers.AddRange(await GetUserIds(UserAccess.CourseApproval2));
                    receivers.AddRange(await GetUserIds(UserAccess.CourseApproval3));
                    break;

                case NotificationType.Course_Cancelled:

                    receivers.Add(model.SenderId);

                    var approval = db.CourseApprovals.Where(x => x.CourseId == model.Id).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

                    if (approval != null)
                    {
                        if (approval.ApprovalLevel == ApprovalLevel.Verifier)
                        {
                            receivers.AddRange(await GetUserIds(UserAccess.CourseVerify));
                        }

                        if (approval.ApprovalLevel == ApprovalLevel.Approver1)
                        {
                            receivers.AddRange(await GetUserIds(UserAccess.CourseApproval1));
                        }

                        if (approval.ApprovalLevel == ApprovalLevel.Approver2)
                        {
                            receivers.AddRange(await GetUserIds(UserAccess.CourseApproval2));
                        }

                        if (approval.ApprovalLevel == ApprovalLevel.Approver3)
                        {
                            receivers.AddRange(await GetUserIds(UserAccess.CourseApproval3));
                        }
                    }

                    break;

                default:
                    break;
                }

                if (model.ReceiverId == null)
                {
                    model.ReceiverId = new List <int>();
                }

                model.ReceiverId.AddRange(receivers);
            }

            if (model.Type == typeof(Course))
            {
                var course = await db.Courses.FindAsync(model.Id);

                if (course != null)
                {
                    model.ParameterListToSend.CourseTitle = course.Title;
                }
            }

            await db.SaveChangesAsync();

            var controller = new SLAReminderController();

            try
            {
                if (model.IsNeedRemainder)
                {
                    CreateAutoReminder createdAutoReminder = new CreateAutoReminder
                    {
                        NotificationCategory  = model.NotificationCategory,
                        NotificationType      = model.NotificationType,
                        ParameterListToSend   = model.ParameterListToSend,
                        ReceiverId            = model.ReceiverId,
                        StartNotificationDate = DateTime.Now
                    };

                    var result = await controller.GenerateAutoNotificationReminder(createdAutoReminder);

                    var response = result as OkNegotiatedContentResult <ReminderResponse>;

                    if (response != null)
                    {
                        if (model.Type == typeof(Course))
                        {
                            var course = await db.Courses.FindAsync(model.Id);

                            if (course != null)
                            {
                                course.SLAReminderId = response.Content.SLAReminderStatusId;

                                db.SetModified(course);
                                await db.SaveChangesAsync();

                                return(Ok());
                            }
                        }
                    }
                    else
                    {
                        var log = new ErrorLog
                        {
                            CreatedDate      = DateTime.Now,
                            UserId           = null,
                            Module           = null,
                            Source           = " Controller: eLearning/NotificationApi Action: SendNotification",
                            ErrorDescription = "Error sending email",
                            ErrorDetails     = "Null response",
                            IPAddress        = "",
                        };

                        db.ErrorLog.Add(log);
                        db.SaveChanges();
                    }
                }
                else
                {
                    var result = await controller.GenerateAndSendEmails(model);

                    var response = result as OkNegotiatedContentResult <ReminderResponse>;

                    if (response == null)
                    {
                        var log = new ErrorLog
                        {
                            CreatedDate      = DateTime.Now,
                            UserId           = null,
                            Module           = null,
                            Source           = " Controller: eLearning/NotificationApi Action: SendNotification",
                            ErrorDescription = "Error sending email",
                            ErrorDetails     = "Null response",
                            IPAddress        = "",
                        };

                        db.ErrorLog.Add(log);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                var log = new ErrorLog
                {
                    CreatedDate      = DateTime.Now,
                    UserId           = null,
                    Module           = null,
                    Source           = " Controller: eLearning/NotificationApi Action: SendNotification",
                    ErrorDescription = e.Message,
                    ErrorDetails     = e.InnerException + " | " + e.StackTrace,
                    IPAddress        = "",
                };

                db.ErrorLog.Add(log);
                db.SaveChanges();
            }

            return(Ok());
        }
Пример #9
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));
        }
        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"));
            }
        }