public async Task <ResultMessage <bool> > GenerateRegistrationEmail(RegisterFormDTO registerFormDTO)
        {
            RegistrationDTO regDTO = Mapping.Mapper.Map <RegistrationDTO>(registerFormDTO);

            regDTO.RegistrationCode = GenerateRegistrationCode();
            regDTO.Used             = false;
            regDTO.Timestamp        = DateTime.Now;

            ResultMessage <RegistrationDTO> registrationProcessResult = await _registrationService.Add(regDTO);

            if (!registrationProcessResult.IsSuccess)
            {
                return(new ResultMessage <bool>(registrationProcessResult.Status, registrationProcessResult.Message));
            }

            await _emailSender.SendTemplateEmailAsync(
                new TemplateEmail
            {
                From         = _fromEmailAddress,
                To           = registerFormDTO.Email,
                TemplateId   = _regEmailTemplateId,
                TemplateData = new
                {
                    reg_link     = GenerateRegistrationLink(regDTO.RegistrationCode),
                    first_name   = registerFormDTO.FirstName,
                    last_name    = registerFormDTO.LastName,
                    index_number = registerFormDTO.Index
                },
            });

            return(new ResultMessage <bool>(true));
        }
Beispiel #2
0
        public async Task GenerateRegistrationEmail()
        {
            _emailMock.Setup(emailService => emailService.SendTemplateEmailAsync(It.IsAny <TemplateEmail>()))
            .Returns(Task.CompletedTask);

            var regMock = new Mock <IRegistrationService>();

            regMock.Setup(regService => regService.Add(It.IsAny <RegistrationDTO>()))
            .ReturnsAsync(new ResultMessage <RegistrationDTO>());

            Mock <IStudentService> studService = new Mock <IStudentService>();
            Mock <IErrorHandler>   handlerMock = new Mock <IErrorHandler>();

            // Passing null here beacause GenerateRegistrationEmail does not use StudentService
            IStudentManagmentService studMng = new StudentManagmentService(
                _emailMock.Object,
                studService.Object,
                regMock.Object,
                _sharedConfigMock.Object,
                _imgMock.Object,
                handlerMock.Object,
                _context);

            RegisterFormDTO reg = new RegisterFormDTO
            {
                Email     = EMAIL_TO,
                FirstName = "FirstName",
                LastName  = "LastName",
                Index     = "1111/11",
                Privilege = StudentPrivilege.Normal
            };

            await studMng.GenerateRegistrationEmail(reg);

            _emailMock.Verify(emailService => emailService.SendTemplateEmailAsync
                              (
                                  It.Is <TemplateEmail>(emailData => emailData.To == EMAIL_TO)
                              ), Times.Once);

            regMock.Verify(regService => regService.Add(
                               It.Is <RegistrationDTO>(regDTO => regDTO.Compare(reg) && regDTO.Used == false)), Times.Once);
        }
Beispiel #3
0
        public async Task RegisterStudent()
        {
            string registrationCode = null;

            _regMock.Setup(regService => regService.Add(It.IsAny <RegistrationDTO>()))
            // Note callback here setting registrationCode variable
            .Callback((RegistrationDTO dto) => registrationCode = dto.RegistrationCode)
            .ReturnsAsync(new ResultMessage <RegistrationDTO>());

            _regMock.Setup(regService => regService.Update(It.IsAny <RegistrationDTO>()))
            .ReturnsAsync(new ResultMessage <RegistrationDTO>());

            var studServiceMock = new Mock <IStudentService>();

            studServiceMock.Setup(stud => stud.Add(It.IsAny <StudentDTO>()))
            .ReturnsAsync(new ResultMessage <StudentDTO>());

            IStudentManagmentService studMng = new StudentManagmentService
                                                   (new Mock <IEmailSenderService>().Object,
                                                   studServiceMock.Object,
                                                   _regMock.Object,
                                                   _sharedConfigMock.Object, null, _handlerMock.Object, _context);

            RegisterFormDTO reg = new RegisterFormDTO
            {
                Email     = EMAIL_TO,
                FirstName = "FirstName",
                LastName  = "LastName",
                Index     = "1111/11",
                Privilege = StudentPrivilege.Normal
            };

            await studMng.GenerateRegistrationEmail(reg);

            // At this point registrationCode != null
            RegistrationDTO regDTO = new RegistrationDTO
            {
                Email            = EMAIL_TO,
                RegistrationCode = registrationCode,
                RegistrationId   = 1,
                Timestamp        = DateTime.UtcNow,
                Used             = false
            };

            _regMock.Setup(regService => regService.GetSingleOrDefault(
                               It.IsAny <Predicate <RegistrationDTO> >())).ReturnsAsync(new ResultMessage <RegistrationDTO>(regDTO));

            RegisterUserDTO regData = new RegisterUserDTO
            {
                Password         = "******",
                Username         = "******",
                RegistrationCode = registrationCode
            };

            await studMng.FinishRegistrationProcess(regData);

            studServiceMock.Verify(service => service.Add(
                                       It.Is <StudentDTO>(dto => dto.Username == regData.Username)));

            _regMock.Verify(service => service.Update(
                                It.Is <RegistrationDTO>(dto => dto.Used == true)));
        }
Beispiel #4
0
 public static bool Compare(this RegistrationDTO regDTO, RegisterFormDTO regFormDTO)
 => regDTO.Email == regFormDTO.Email &&
 regDTO.Privilege == regFormDTO.Privilege &&
 regDTO.FirstName == regFormDTO.FirstName &&
 regDTO.LastName == regFormDTO.LastName &&
 regDTO.Index == regFormDTO.Index;
Beispiel #5
0
        public IHttpActionResult RegisterForm(RegisterFormDTO registerForm)
        {
            PaymentItems    MyPaymentItems      = null;
            int             NoOfUsers           = 0;
            int             PurchaseItemsId     = 0;
            ResultReponse   MyResultResponse    = new ResultReponse();
            UserDTO         UserDTOInfo         = new UserDTO();
            SetupProcessDTO SetupProcessDTOInfo = new SetupProcessDTO();

            CardPaymentDTO  CardPaymentDTOInfo = null;
            SubscriptionDTO m_subscriptionDTO;
            //string APIKey = "sk_test_MCGUn4fT1YzFQzGcRa9HiC3v";

            string APIKey = "sk_test_ffjSM0I2xFEg7I18xCdxb9EJ";

            RegisterFormResults MyRegisterFormResults = new RegisterFormResults();
            string MessageBody      = "Welcome to MyUEL..";
            string TemplateBody     = "";
            string Subject          = "Message";
            string SubscriptionName = "";

            string        ExpMonth        = "";
            string        ExpYear         = "";
            ResultReponse MyResultReponse = new ResultReponse();

            try
            {
                //Get Stripe API Key
                //APIKey = "sk_test_ffjSM0I2xFEg7I18xCdxb9EJ";
                //m_subscriptionDTO = m_IRegisterBusiness.GetSubscriptionId(registerForm.Subscriptionid);

                //if (m_subscriptionDTO != null)
                //{
                //    NoOfUsers = m_subscriptionDTO.noOfUser;



                //    MyUELHelpers.Info(typeof(RegisterController).ToString(), "SaveUserDetails", "Started " + DateTime.Now.ToString());
                //    UserDTOInfo = m_IRegisterBusiness.creatingUsers(registerForm.FirstName, registerForm.LastName, registerForm.UserEmail,
                //        registerForm.Password, registerForm.Company, registerForm.Subscriptionid, m_subscriptionDTO);
                //    MyUELHelpers.Info(typeof(RegisterController).ToString(), "SaveUserDetails", "Done " + DateTime.Now.ToString());

                //    SubscriptionName = string.Format("{0}  {1}   {2} ", m_subscriptionDTO.SubscriptionName, m_subscriptionDTO.SubscriptionDays, m_subscriptionDTO.SubscriptionType);

                //    if (UserDTOInfo != null)
                //    {
                //        MyUserInfo.TenantId = UserDTOInfo.TenantId;
                //        MyUserInfo.UserId = UserDTOInfo.Id;
                //        MyUserInfo.UserName = UserDTOInfo.UserName;
                //        MyUserInfo.SubscriptionId = registerForm.Subscriptionid;
                //        MyUserInfo.SubscriptionName = m_subscriptionDTO.SubscriptionName;
                //        MyUserInfo.SubscriptionType = m_subscriptionDTO.SubscriptionType;
                //        MyRegisterFormResults.StatusCode = "USERREGISTER";
                //        MyRegisterFormResults.Status = "User Registration Done";
                //        MyRegisterFormResults.Message = "User Registration Done";
                //        MyUELHelpers.Info(typeof(RegisterController).ToString(), "Creating Table", "Started " + DateTime.Now.ToString());
                //        SetupProcessDTOInfo = m_ISetupProcessBusiness.CreateTable("boundhound" + MyUserInfo.TenantId, MyUserInfo);
                //        if (SetupProcessDTOInfo.Status == "SUCCESS")
                //        {
                //            MyUELHelpers.Info(typeof(RegisterController).ToString(), "Table Created Successfully", "End " + DateTime.Now.ToString());
                //            MyUserInfo.databasename = "MyUELLoyalty" + MyUserInfo.TenantId;
                //        }
                //        else
                //        {
                //            MyUELHelpers.Info(typeof(RegisterController).ToString(), "Creating Table Error", string.Format("Error {0}\n ", SetupProcessDTOInfo.Message) + DateTime.Now.ToString());
                //        }

                //        if (m_subscriptionDTO.SubscriptionType == "Paid")
                //        {


                //            registerForm.TotalAmount = m_subscriptionDTO.Amount;
                //            //create a card
                //            ExpMonth = registerForm.ExpMonth.Split('/')[0];
                //            ExpYear = registerForm.ExpMonth.Split('/')[1];

                //            MyUELHelpers.Info(typeof(RegisterController).ToString(), "SaveCardDetails", "Started " + DateTime.Now.ToString());
                //            CardDetailsDTO cardDetailsDTOInfo = null;
                //            cardDetailsDTOInfo = m_ICardDetailsBusiness.savecardDetails(registerForm.ccNo, registerForm.SecurityCode, ExpMonth, ExpYear, registerForm.UserEmail, APIKey, MyUserInfo);
                //            MyUELHelpers.Info(typeof(RegisterController).ToString(), "SaveCardDetails", "Ended " + DateTime.Now.ToString());
                //            if (cardDetailsDTOInfo != null)
                //            {
                //                //payment
                //                MyUELHelpers.Info(typeof(RegisterController).ToString(), "SavePaymentDetails", "Started " + DateTime.Now.ToString());
                //                CardPaymentDTOInfo = m_paymentDetailsBusiness.PaymentDetails(Convert.ToString(cardDetailsDTOInfo.Id), registerForm.TotalAmount, APIKey, MyUserInfo);
                //                MyUELHelpers.Info(typeof(RegisterController).ToString(), "SavePaymentDetails", "Done " + DateTime.Now.ToString());
                //                MyResultResponse.Status = CardPaymentDTOInfo.transactionstatus;
                //                MyResultResponse.Message = "Paid Subscription";

                //                MyRegisterFormResults.StatusCode = "PAYMENTDONESUCCESS";
                //                MyRegisterFormResults.Status = "Payment done subscription created";
                //                MyRegisterFormResults.Message = "Payment done subscription created";

                //                MyRegisterFormResults.PaymentId = CardPaymentDTOInfo.PaymentId;
                //                MyRegisterFormResults.TransactionId = CardPaymentDTOInfo.transactionId;
                //                //****************************************************************************************************************************************************************
                //                // Save In Payment Items
                //                //****************************************************************************************************************************************************************
                //                MyPaymentItems = new PaymentItems();

                //                MyPaymentItems.PaymentId = CardPaymentDTOInfo.id;
                //                MyPaymentItems.ItemName = "Subscription Charges";
                //                MyPaymentItems.PurchaseAmount = registerForm.TotalAmount;
                //                MyPaymentItems.NoOfUsers = NoOfUsers;
                //                PurchaseItemsId = m_IPurchaseUsersBusiness.CreatePaymentItems(MyPaymentItems, MyUserInfo);

                //                //****************************************************************************************************************************************************************

                //                //Send this Details to send the mail
                //                //MyRegisterFormResults.Subscription = m_subscriptionDTO;
                //                //MyRegisterFormResults.CardPayment = CardPaymentDTOInfo;
                //                //MyRegisterFormResults.User = UserDTOInfo;

                //                //TODO Send the email to user

                //            }
                //        }

                //        //Send Email After Register
                //        Subject = "User Registration Confirmation...";

                //        MyUserInfo.UserName = UserDTOInfo.UserName;
                //        MyUserInfo.Email = UserDTOInfo.UserEmail;
                //        MyUserInfo.Password = UserDTOInfo.UserPassword;

                //        MyUserInfo.SubscriptionName = SubscriptionName;

                //        //Template Parse
                //        TemplateParsers MyTemplateParser = new TemplateParsers(MyUserInfo);

                //        //Get After register html template from the Templates/AfterRegister.html
                //        var filePath = HttpContext.Current.Server.MapPath("~/Templates/AfterRegister.html");

                //        string html = File.ReadAllText(filePath);

                //        TemplateBody = MyTemplateParser.ParseAfterRegister(html, MyUserInfo);

                //        MessageBody = TemplateBody;

                //        //GET SMTP Settings
                //        SMTPSettings MyUELLoyaltySMTPSettings = new SMTPSettings();

                //        UtilityBusiness MyUtilityBusiness = new UtilityBusiness();
                //        BoundHoundSMTPSettings = MyUtilityBusiness.GetBoundHoundSMPTSettings(MyUserInfo);

                //        if (BoundHoundSMTPSettings != null)
                //        {
                //            if (BoundHoundSMTPSettings.Id > 0)
                //            {
                //                //string FromAddress = string.Format("{0} <{1}>", BoundHoundSMTPSettings.DisplayName, BoundHoundSMTPSettings.UserName);

                //                MyResultReponse = m_IEmailsBusiness.SendEmailAfterRegister(registerForm.UserEmail, BoundHoundSMTPSettings.HostName, BoundHoundSMTPSettings.Port, BoundHoundSMTPSettings.UserName,
                //                BoundHoundSMTPSettings.UserPassword,
                //                Subject, MessageBody, UserDTOInfo, m_subscriptionDTO, CardPaymentDTOInfo);

                //                //MyResultReponse = m_IEmailsBusiness.SendEmailAfterRegister(registerForm.UserEmail, MyUserInfo.FromUserEmail,
                //                //        MyUserInfo.FromPassword,
                //                //        Subject, MessageBody, UserDTOInfo, m_subscriptionDTO, CardPaymentDTOInfo);

                //                if (MyResultReponse.Status == "SUCCESS")
                //                {
                //                    MyRegisterFormResults.StatusCode = "USERREGISTER";
                //                    MyRegisterFormResults.Status = "User Registration Done";
                //                    MyRegisterFormResults.Message = "User Registration Done";
                //                    MyRegisterFormResults.User = UserDTOInfo;

                //                }
                //                else
                //                {
                //                    MyRegisterFormResults.StatusCode = "PAYMENTDONESUCCESS";
                //                    MyRegisterFormResults.Status = "Payment done subscription created";
                //                    MyRegisterFormResults.Message = "Payment done subscription created - Email error ";
                //                    MyRegisterFormResults.User = UserDTOInfo;
                //                }
                //            }
                //        }



                //        //SetupProcessDTOInfo = m_ISetupProcessBusiness.CreateTable("boundhound" + MyUserInfo.TenantId, MyUserInfo);

                //    }

                //}

                //else
                //{
                //    MyRegisterFormResults.Message = "InValid Subscription Id ";
                //    MyRegisterFormResults.User = UserDTOInfo;
                //}
                return(Json(MyRegisterFormResults));
            }
            catch (Exception Ex)
            {
                MyUELHelpers.ErrorLog(typeof(RegisterController).ToString(), "RegisterForm", Ex.ToString());
            }

            return(Json(MyRegisterFormResults));
        }