Exemple #1
0
        private string GetView(Application application, string baseUri)
        {
            string path = "";

            switch (application.State)
            {
            case ApplicationState.Pending:
            {
                path = _templatePathProvider.Get("PendingApplication");
                var vm = GetPendingApplicationViewModel(application);
                return(_view_Generator.GenerateFromPath(string.Format("{0}{1}", baseUri, path), vm));
            }

            case ApplicationState.Activated:
            {
                path = _templatePathProvider.Get("ActivatedApplication");
                var vm = GetActivatedApplicationViewModel(application);
                return(_view_Generator.GenerateFromPath(string.Format("{0}{1}", baseUri, path), vm));
            }

            case ApplicationState.InReview:
            {
                path = _templatePathProvider.Get("InReviewApplication");
                var vm = GetInReviewApplicationViewModel(application);
                return(_view_Generator.GenerateFromPath(string.Format("{0}{1}", baseUri, path), vm));
            }

            default:
            {
                _logger.LogWarning(
                    $"The application is in state '{application.State}' and no valid document can be generated for it.");
                return(null);
            }
            }
        }
Exemple #2
0
        private static string GetPendingApplicationView(Application application, string baseUri)
        {
            var path = _templatePathProvider.Get("PendingApplication");

            PendingApplicationViewModel PendingApplicationViewModel = new PendingApplicationViewModel
            {
                ReferenceNumber = application.ReferenceNumber,
                State           = application.State.ToDescription(),
                //changed for consistency
                FullName     = string.Format("{0} {1}", application.Person.FirstName, application.Person.Surname),
                AppliedOn    = application.Date,
                SupportEmail = _configuration.SupportEmail,
                Signature    = _configuration.Signature
            };

            return(_viewGenerator.GenerateFromPath(string.Format("{0}{1}", baseUri, path), PendingApplicationViewModel));
        }
Exemple #3
0
        public static string AppPending(Application application, IPathProvider _templatePathProvider, IConfiguration _configuration, IViewGenerator View_Generator, string baseUri)
        {
            string view;
            string path = _templatePathProvider.Get("PendingApplication");
            PendingApplicationViewModel vm = new PendingApplicationViewModel
            {
                ReferenceNumber = application.ReferenceNumber,
                State           = application.State.ToDescription(),
                FullName        = application.Person.FirstName + " " + application.Person.Surname,
                AppliedOn       = application.Date,
                SupportEmail    = _configuration.SupportEmail,
                Signature       = _configuration.Signature
            };

            return(view = View_Generator.GenerateFromPath(string.Format("{0}{1}", baseUri, path), vm));
        }
Exemple #4
0
        public static string AppActivated(Application application, IPathProvider _templatePathProvider, IConfiguration _configuration, IViewGenerator View_Generator, string baseUri)
        {
            string view;
            string path = _templatePathProvider.Get("ActivatedApplication");
            ActivatedApplicationViewModel vm = new ActivatedApplicationViewModel
            {
                ReferenceNumber      = application.ReferenceNumber,
                State                = application.State.ToDescription(),
                FullName             = $"{application.Person.FirstName} {application.Person.Surname}",
                LegalEntity          = application.IsLegalEntity ? application.LegalEntity : null,
                PortfolioFunds       = application.Products.SelectMany(p => p.Funds),
                PortfolioTotalAmount = application.Products.SelectMany(p => p.Funds)
                                       .Select(f => (f.Amount - f.Fees) * _configuration.TaxRate)
                                       .Sum(),
                AppliedOn    = application.Date,
                SupportEmail = _configuration.SupportEmail,
                Signature    = _configuration.Signature
            };

            return(view = View_Generator.GenerateFromPath(baseUri + path, vm));
        }
Exemple #5
0
        public static string AppInReview(Application application, IPathProvider _templatePathProvider, IConfiguration _configuration, IViewGenerator View_Generator, string baseUri)
        {
            string view;
            var    templatePath    = _templatePathProvider.Get("InReviewApplication");
            var    inReviewMessage = "Your application has been placed in review" +
                                     application.CurrentReview.Reason switch
            {
                { } reason when reason.Contains("address") =>
                " pending outstanding address verification for FICA purposes.",
                {
                }

                reason when reason.Contains("bank") =>
                " pending outstanding bank account verification.",
                _ =>
                " because of suspicious account behaviour. Please contact support ASAP."
            };
            var inReviewApplicationViewModel = new InReviewApplicationViewModel();

            inReviewApplicationViewModel.ReferenceNumber = application.ReferenceNumber;
            inReviewApplicationViewModel.State           = application.State.ToDescription();
            inReviewApplicationViewModel.FullName        = string.Format(
                "{0} {1}",
                application.Person.FirstName,
                application.Person.Surname);
            inReviewApplicationViewModel.LegalEntity =
                application.IsLegalEntity ? application.LegalEntity : null;
            inReviewApplicationViewModel.PortfolioFunds       = application.Products.SelectMany(p => p.Funds);
            inReviewApplicationViewModel.PortfolioTotalAmount = application.Products.SelectMany(p => p.Funds)
                                                                .Select(f => (f.Amount - f.Fees) * _configuration.TaxRate)
                                                                .Sum();
            inReviewApplicationViewModel.InReviewMessage     = inReviewMessage;
            inReviewApplicationViewModel.InReviewInformation = application.CurrentReview;
            inReviewApplicationViewModel.AppliedOn           = application.Date;
            inReviewApplicationViewModel.SupportEmail        = _configuration.SupportEmail;
            inReviewApplicationViewModel.Signature           = _configuration.Signature;

            return(view = View_Generator.GenerateFromPath($"{baseUri}{templatePath}", inReviewApplicationViewModel));
        }
    }
Exemple #6
0
        public byte[] Generate(Guid applicationId, string baseUri)
        {
            Application application = DataContext.Applications.Single(app => app.Id == applicationId);

            if (application != null)
            {
                if (baseUri.EndsWith("/"))
                {
                    baseUri = baseUri.Substring(baseUri.Length - 1);
                }

                string view;

                if (application.State == ApplicationState.Pending)
                {
                    string path = baseUri + _templatePathProvider.Get("PendingApplication");

                    var vm = MapPendingApplication(application);

                    view = View_Generator.GenerateFromPath(path, vm);
                }
                else if (application.State == ApplicationState.Activated)
                {
                    string path = baseUri + _templatePathProvider.Get("ActivatedApplication");

                    var vm = MapActivatedApplication(application);

                    view = View_Generator.GenerateFromPath(path, vm);
                }
                else if (application.State == ApplicationState.InReview)
                {
                    var path = baseUri + _templatePathProvider.Get("InReviewApplication");

                    var inReviewMessage = "Your application has been placed in review" +
                                          application.CurrentReview.Reason switch
                    {
                        { } reason when reason.Contains("address") =>
                        " pending outstanding address verification for FICA purposes.",
                        {
                        }

                        reason when reason.Contains("bank") =>
                        " pending outstanding bank account verification.",
                        _ =>
                        " because of suspicious account behaviour. Please contact support ASAP."
                    };

                    var vm = MapInReviewApplication(application, inReviewMessage);

                    view = View_Generator.GenerateFromPath(path, vm);
                }
                else
                {
                    _logger.LogWarning(
                        $"The application is in state '{application.State}' and no valid document can be generated for it.");
                    return(null);
                }

                var pdfOptions = new PdfOptions
                {
                    PageNumbers   = PageNumbers.Numeric,
                    HeaderOptions = new HeaderOptions
                    {
                        HeaderRepeat = HeaderRepeat.FirstPageOnly,
                        HeaderHtml   = PdfConstants.Header
                    }
                };
                var pdf = _pdfGenerator.GenerateFromHtml(view, pdfOptions);
                return(pdf.ToBytes());
            }
            else
            {
                _logger.LogWarning(
                    $"No application found for id '{applicationId}'");
                return(null);
            }
        }
		//Implementing the interface method
		//Add exception handling
		public byte[] Generate(Guid applicationId, string baseUri)
		{
			var application = _dataContext.Applications.Single(app => app.Id == applicationId);

			if (application != null)
			{
                //The substring method here may not be the correct method to use
                //Normally a good base Uri ends with a trailing slash
                //Currently all this would do is return the "/" character as a substring

                /*********************************************************************************
                if (baseUri.EndsWith("/"))
					baseUri = baseUri.Substring(baseUri.Length - 1);
                **********************************************************************************/

                //Check for a bad baseUri
                if (!baseUri.EndsWith("/"))
                {
                    //append the trailing slash character
                    baseUri += "/";

                    //NB That this would work assuming that _templatePathProvider.Get() would return a file string path 
                    //which DOES NOT start with a "/" character
                }

                //Initialize string variable
                var view = "";

				switch (application.State)
                {
                    case ApplicationState.Pending:
                    {
                        var path = _templatePathProvider.Get("PendingApplication");

                        //Due to the convention used above for the base Uri, we cannot allow any paths to start with a "/" character
                        //Ideally this check should be done in the class which implements IPathProvider's Get() method but is added here as an extra check.
                        if (path.StartsWith("/") && path.Length > 1)
                        {
                            path = path.Substring(1);
                        }

                        var vm = new PendingApplicationViewModel
                        {
                            ReferenceNumber = application.ReferenceNumber,
                            State = application.State.ToDescription(),
                            FullName = application.Person.FirstName + " " + application.Person.Surname,
                            AppliedOn = application.Date,
                            SupportEmail = _configuration.SupportEmail,
                            Signature = _configuration.Signature
                        };

                        //Add some exception handling before generating the view as an extra measure
                        try
                        {
                            view = _viewGenerator.GenerateFromPath($"{baseUri}{path}", vm);
                        }
                        catch (Exception e)
                        {
                            _logger.LogWarning("Error generating view: " + e.Message);
                            throw;
                        }

                        break;
                    }
                    case ApplicationState.Activated:
                    {
                        var path = _templatePathProvider.Get("ActivatedApplication");

                        //Due to the convention used above for the base Uri, we cannot allow any paths to start with a "/" character
                        //Ideally this check should be done in the class which implements IPathProvider's Get() method but is added here as an extra check.
                        if (path.StartsWith("/") && path.Length > 1)
                        {
                            path = path.Substring(1);
                        }

                        var vm = new ActivatedApplicationViewModel
                        {
                            ReferenceNumber = application.ReferenceNumber,
                            State = application.State.ToDescription(),
                            FullName = $"{application.Person.FirstName} {application.Person.Surname}", 
                            LegalEntity = application.IsLegalEntity ? application.LegalEntity : null,

                            PortfolioFunds = application.Products.SelectMany(p => p.Funds),

                            PortfolioTotalAmount = application.Products.SelectMany(p => p.Funds)
                                .Select(f => (f.Amount - f.Fees) * _configuration.TaxRate)
                                .Sum(),

                            AppliedOn = application.Date,
                            SupportEmail = _configuration.SupportEmail,
                            Signature = _configuration.Signature
                        };

                        //Add some exception handling before generating the view as an extra measure
                        try
                        {
                            view = _viewGenerator.GenerateFromPath(baseUri + path, vm);
                        }
                        catch (Exception e)
                        {
                            _logger.LogWarning("Error generating view: " + e.Message);
                            throw;
                        }

                        break;
                    }
                    case ApplicationState.InReview:
                    {
                        var templatePath = _templatePathProvider.Get("InReviewApplication");

                        //Due to the convention used above for the base Uri, we cannot allow any paths to start with a "/" character
                        //Ideally this check should be done in the class which implements IPathProvider's Get() method but is added here as an extra check.
                        if (templatePath.StartsWith("/") && templatePath.Length > 1)
                        {
                            templatePath = templatePath.Substring(1);
                        }

                        var inReviewMessage = "Your application has been placed in review" +
                                              application.CurrentReview.Reason switch
                                              {
                                                  { } reason when reason.Contains("address") =>
                                                      " pending outstanding address verification for FICA purposes.",
                                                  { } reason when reason.Contains("bank") =>
                                                      " pending outstanding bank account verification.",
                                                  _ =>
                                                      " because of suspicious account behaviour. Please contact support ASAP."
					
                                              };

                        var inReviewApplicationViewModel = new InReviewApplicationViewModel
                        {
                            ReferenceNumber = application.ReferenceNumber,
                            State = application.State.ToDescription(),
                            FullName = $"{application.Person.FirstName} {application.Person.Surname}",
                            LegalEntity = application.IsLegalEntity ? application.LegalEntity : null,

                            PortfolioFunds = application.Products.SelectMany(p => p.Funds),

                            PortfolioTotalAmount = application.Products.SelectMany(p => p.Funds)
                                .Select(f => (f.Amount - f.Fees) * _configuration.TaxRate)
                                .Sum(),

                            InReviewMessage = inReviewMessage,
                            InReviewInformation = application.CurrentReview,
                            AppliedOn = application.Date,
                            SupportEmail = _configuration.SupportEmail,
                            Signature = _configuration.Signature
                        };

                        //Add some exception handling before generating the view as an extra measure
                        try
                        {
                            view = _viewGenerator.GenerateFromPath($"{baseUri}{templatePath}", inReviewApplicationViewModel);
                        }
                        catch (Exception e)
                        {
                            _logger.LogWarning("Error generating view: " + e.Message);
                            throw;
                        }

                        break;
                    }
                    default:
                        _logger.LogWarning(
                            $"The application is in state '{application.State}' and no valid document can be generated for it.");
                        return null;
                }

				var pdfOptions = new PdfOptions
				{
					PageNumbers = PageNumbers.Numeric,
					HeaderOptions = new HeaderOptions
					{
						HeaderRepeat = HeaderRepeat.FirstPageOnly,
						HeaderHtml = PdfConstants.Header
					}
				};

				//Add exception handling before generating the pdf
                try
                {
                    var pdf = _pdfGenerator.GenerateFromHtml(view, pdfOptions);
                    return pdf.ToBytes();
                }
                catch (Exception e)
                {
                    _logger.LogWarning("Error generating pdf: " + e.Message);
                    throw;
                }
				
			}

            _logger.LogWarning(
                $"No application found for id '{applicationId}' or an unexpected error was encountered");
            return null;
        }
        public UserSettings Get(Guid id)
        {
            CreateProvider();

            return(JsonConvert.DeserializeObject <UserSettings>(File.ReadAllText(_provider.Get($"{id}:settings"))));
        }