// GET: Roles by Id public async Task <IActionResult> RoleIndex(int?Id) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var _opening = await _context.Openings.Where(m => m.Id == Id).FirstOrDefaultAsync(); PendingApplicationViewModel _pendingApplicationViewModel = new PendingApplicationViewModel(); _pendingApplicationViewModel.Opening = _opening; return(View(_pendingApplicationViewModel)); }
// ================================================ Mapping Methods ============================================================ public PendingApplicationViewModel MapPendingApplication(Application application) { var newModel = 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(newModel); }
public async Task <IActionResult> CreatePendingApplication(PendingApplicationViewModel pendingApplicationViewModel) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var developer = _context.Developers.FirstOrDefault(a => a.UserId == userId); var roleOpeningId = pendingApplicationViewModel.Opening.Id; PendingApplication pendingApplication = new PendingApplication(); pendingApplication.OpeningId = roleOpeningId; pendingApplication.DeveloperId = developer.Id; pendingApplication.Email = pendingApplicationViewModel.PendingApplication.Email; _context.PendingApplications.Add(pendingApplication); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
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)); }
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)); }
private PendingApplicationViewModel GetPendingApplicationViewModel(Application application) { //Validate the Application Model State if (application.Person == null) { _logger.LogWarning($"The application model is invalid.Person Entity Is Null"); throw new ArgumentNullException(nameof(application.Person)); } PendingApplicationViewModel vm = new PendingApplicationViewModel { ReferenceNumber = application.ReferenceNumber, State = application.State.ToDescription(), FullName = string.Format("{0} {1}", application.Person.FirstName, application.Person.Surname), AppliedOn = application.Date, SupportEmail = _configuration.SupportEmail, Signature = _configuration.Signature }; return(vm); }
//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; }