예제 #1
0
        public async static Task UserWithdrawFromCourse(int id, int senderId,
                                                        string receiverEmails = "", string userName = "", string link = "")
        {
            var notifyModel = new NotificationModel
            {
                Id                    = id,
                Type                  = typeof(Course),
                NotificationType      = NotificationType.Notify_Admin_Participant_Withdraw,
                NotificationCategory  = NotificationCategory.Learning,
                StartNotificationDate = DateTime.Now,
                ParameterListToSend   = new ParameterListToSend
                {
                    CourseTitle = "",
                    LearnerName = userName,
                    Link        = link,
                },
                ReceiverType    = ReceiverType.UserIds,
                IsNeedRemainder = false,
                Emails          = receiverEmails,
                SenderId        = senderId,
            };
            await EmaiHelper.SendNotification(notifyModel);

            notifyModel.NotificationType         = NotificationType.Notify_Self_Withdraw_From_Course;
            notifyModel.SenderId                 = senderId;
            notifyModel.IsNeedRemainder          = false;
            notifyModel.ParameterListToSend.Link = FEPHelperMethod.GetBaseURL() + $"/eLearning/Courses/{id}";

            await EmaiHelper.SendNotification(notifyModel);
        }
예제 #2
0
        public async static Task SubmitCourseForVerication(int id, int senderId,
                                                           string receiverEmails = "", string author = "", string title = "", string link = "")
        {
            var notifyModel = new NotificationModel
            {
                Id                    = id,
                Type                  = typeof(Course),
                NotificationType      = NotificationType.Verify_Courses_Creation,
                NotificationCategory  = NotificationCategory.Learning,
                StartNotificationDate = DateTime.Now,
                ParameterListToSend   = new ParameterListToSend
                {
                    CourseAuthor   = author,
                    CourseTitle    = title,
                    CourseApproval = "Course Verification",
                    Link           = link,
                },
                ReceiverType    = ReceiverType.UserIds,
                SenderId        = senderId,
                Emails          = receiverEmails,
                IsNeedRemainder = true,
            };

            await EmaiHelper.SendNotification(notifyModel);

            notifyModel.NotificationType         = NotificationType.Verify_Courses_Creation_Self;
            notifyModel.SenderId                 = senderId;
            notifyModel.IsNeedRemainder          = false;
            notifyModel.ParameterListToSend.Link = FEPHelperMethod.GetBaseURL() + $"/eLearning/Courses/{id}";

            await EmaiHelper.SendNotification(notifyModel);
        }
예제 #3
0
        // Notification type determine the object
        public static async Task <ReminderResponse> SendNotification(NotificationModel model)
        {
            try
            {
                var response = await WepApiMethod.SendApiAsync <ReminderResponse>(HttpVerbs.Post, EmailHelperApiUrl.SendNotification, model);

                if (response.isSuccess)
                {
                    return(response.Data);
                }

                await FEPHelperMethod.LogError(Modules.Learning, model.SenderId, "", "", "eLearning", "",
                                               "Sending Email", $"Error sending Email For {model.NotificationType.ToString()} " +
                                               $"Title : " + $"{model.ParameterListToSend.CourseTitle}");

                return(response.Data);
            }
            catch (Exception e)
            {
                await FEPHelperMethod.LogError(Modules.Learning, model.SenderId, "", "", "eLearning", "",
                                               "Sending Email", $"Error sending Email For {model.NotificationType.ToString()} " +
                                               $"Title : " + $"{model.ParameterListToSend.CourseTitle} {e.Message} {e.InnerException}");

                return(new ReminderResponse
                {
                    Status = "Failed"
                });
            }
        }
예제 #4
0
        private void Application_Error(object sender, EventArgs e)
        {
            var httpContext       = ((MvcApplication)sender).Context;
            var currentController = "";
            var currentAction     = "";
            var currentArea       = "";
            var currentRouteData  = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));

            if (currentRouteData != null)
            {
                if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
                {
                    currentController = currentRouteData.Values["controller"].ToString();
                }

                if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
                {
                    currentAction = currentRouteData.Values["action"].ToString();
                }

                if (currentRouteData.DataTokens["area"] != null && !String.IsNullOrEmpty(currentRouteData.DataTokens["area"].ToString()))
                {
                    currentArea = currentRouteData.DataTokens["area"].ToString();
                }
            }

            string ipAddress = httpContext.Request.UserHostAddress;

            var exception = Server.GetLastError();

            string details     = exception.StackTrace;
            string description = exception.Message;

            FEPHelperMethod.LogError(Model.Modules.Setting, null, currentAction, currentController, currentArea, ipAddress, description, details);

            var routeData = new RouteData();

            routeData.Values["controller"] = "Home";
            routeData.Values["action"]     = "Error";

            httpContext.ClearError();
            httpContext.Response.Clear();

            using (Controller controller = new Controllers.HomeController())
            {
                ((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
            }
        }
예제 #5
0
        public IHttpActionResult Post([FromBody] CreateCompanyModel model)
        {
            if (model.Type == CompanyType.Government)
            {
                ModelState.Remove("model.PassportNo");
                ModelState.Remove("model.PostCodeNonMalaysian");
                ModelState.Remove("model.State");
                ModelState.Remove("model.CountryId");
                ModelState.Remove("model.CompanyName");
                ModelState.Remove("model.CompanyRegNo");
                ModelState.Remove("model.SectorId");
            }
            else if (model.Type == CompanyType.MalaysianCompany)
            {
                ModelState.Remove("model.PassportNo");
                ModelState.Remove("model.PostCodeNonMalaysian");
                ModelState.Remove("model.State");
                ModelState.Remove("model.CountryId");
                ModelState.Remove("model.AgencyName");
                ModelState.Remove("model.MinistryId");
            }
            else
            {
                ModelState.Remove("model.ICNo");
                ModelState.Remove("model.PostCodeMalaysian");
                ModelState.Remove("model.StateId");
                ModelState.Remove("model.AgencyName");
                ModelState.Remove("model.MinistryId");
                ModelState.Remove("model.CompanyRegNo");
            }

            if (ModelState.IsValid)
            {
                var countryCode = db.Country.Where(c => c.Id == model.CountryId && c.Display).FirstOrDefault();

                if (countryCode == null)
                {
                    return(InternalServerError());
                }

                var password = "******";

                if (FEPHelperMethod.CurrentSystemMode() != SystemMode.Development)
                {
                    password = Authentication.RandomString(10, true);
                }

                Authentication.GeneratePassword(password);

                var account = new UserAccount
                {
                    LoginId      = model.Email,
                    IsEnable     = false,
                    HashPassword = Authentication.HashPassword,
                    Salt         = Authentication.Salt,
                    LoginAttempt = 0
                };

                var company = new CompanyProfile
                {
                    Type           = model.Type,
                    CompanyName    = model.Type == CompanyType.Government ? model.AgencyName : model.CompanyName,
                    MinistryId     = model.MinistryId,
                    CompanyRegNo   = model.CompanyRegNo,
                    SectorId       = model.SectorId,
                    Address1       = model.Address1,
                    Address2       = model.Address2,
                    City           = model.City,
                    PostCode       = model.Type == CompanyType.NonMalaysianCompany ? model.PostCodeNonMalaysian : model.PostCodeMalaysian,
                    StateId        = model.StateId,
                    StateName      = model.State,
                    CountryId      = model.CountryId,
                    CompanyPhoneNo = model.CompanyPhoneNo,
                    CountryCode    = countryCode.CountryCode1
                };

                var user = new User
                {
                    UserType       = UserType.Company,
                    Name           = model.Name,
                    Email          = model.Email,
                    ICNo           = model.Type == CompanyType.NonMalaysianCompany ? model.PassportNo : model.ICNo,
                    MobileNo       = model.MobileNo,
                    CountryCode    = countryCode.CountryCode1,
                    Display        = true,
                    CreatedBy      = null,
                    CreatedDate    = DateTime.Now,
                    UserAccount    = account,
                    CompanyProfile = company
                };

                foreach (var roleid in model.RoleIds)
                {
                    var userrole = new UserRole
                    {
                        RoleId      = roleid,
                        UserAccount = account,
                    };

                    db.UserRole.Add(userrole);
                }

                db.User.Add(user);

                ActivateAccount activateaccount = new ActivateAccount
                {
                    UID         = Authentication.RandomString(50, true),//random alphanumeric
                    UserId      = user.Id,
                    CreatedDate = DateTime.Now,
                    IsActivate  = false
                };

                db.ActivateAccount.Add(activateaccount);

                db.SaveChanges();

                return(Ok(new { UserId = user.Id, Password = password, UID = activateaccount.UID }));
            }

            return(BadRequest(ModelState));
        }