Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public string generateSubjectMessage(string TemplateText, NotificationType NotificationType, ParameterListToSend paramToSend)
        {
            var    ParamList = db.TemplateParameters.Where(p => p.NotificationType == NotificationType).ToList();
            string WholeText = TemplateText;

            foreach (var item in ParamList)
            {
                string theValue      = GetPropertyValues(paramToSend, item.TemplateParameterType);
                string textToReplace = "[#" + item.TemplateParameterType + "]";
                WholeText = WholeText.Replace(textToReplace, theValue);
            }

            return(WholeText);
        }
Exemplo n.º 4
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.º 5
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"));
            }
        }