public string CreateQuoteSheet(CreateQuoteSheetDto dto, out Submission submission) { // TODO: use the correct quote sheet... var quoteSheetTemplateId = dto.QuoteSheetTemplateId; dto.QuoteSheetTemplateUrl = this.ConsoleRepository.Query<QuoteTemplate>() .FirstOrDefault(qt => qt.Id == dto.QuoteSheetTemplateId).RdlPath; dto.QuoteSheetTemplateName = this.ConsoleRepository.Query<QuoteTemplate>() .FirstOrDefault(qt => qt.Id == dto.QuoteSheetTemplateId).Name; submission = this.SubmissionModule.GetSubmissionById(dto.SubmissionId); //todo this is done to clear previous context. has to be fixed once softdelet is fixed. using (IConsoleRepository consoleRepository = new ConsoleRepository()) { if (submission == null) throw new KeyNotFoundException(string.Format(this.NotFoundMessage, dto.SubmissionId)); consoleRepository.Attach(submission); var currentUser = consoleRepository.Query<User>() .FirstOrDefault(u => u.DomainLogon == this.HttpContext.CurrentUser.Identity.Name); if (currentUser == null) throw new ApplicationException("Current user could not be found"); var quotesheet = new QuoteSheet { Title = string.Format(this.QuoteSheetTitle, submission.Title, submission.InsuredName, DateTime.Now), IssuedBy = currentUser, IssuedById = currentUser.Id, IssuedDate = DateTime.Now, ObjectStore = "Underwriting" }; var content = this.QuoteSheetData.CreateQuoteSheetPdf(dto); quotesheet.Guid = this.QuoteSheetData.SaveQuoteSheetToDMS(quotesheet, content, submission); var versions = (from version in submission.Options.SelectMany(o => o.OptionVersions) from option in dto.OptionList where version.OptionId == option.OptionId from versionNumber in option.OptionVersionNumberList where version.VersionNumber == versionNumber select version).ToList(); quotesheet.OptionVersions = versions; foreach (var quote in versions.SelectMany(ov => ov.Quotes)) { quote.OptionVersion.IsLocked = true; quote.SubmissionStatus = "QUOTED"; } consoleRepository.Add(quotesheet); consoleRepository.SaveChanges(); return string.Format(this.QuoteSheetUrl, ConfigurationManager.AppSettings["UWDmsFileDownloadURL"], quotesheet.Guid); } }
public ActionResult CreateQuote(CreateQuoteSheetDto dto) { Submission submission = null; var url = this.QuoteSheetModule.CreateQuoteSheet(dto, out submission); if (submission == null) throw new HttpException((int)HttpStatusCode.NotFound, string.Format(this.NotFoundMessage, dto.SubmissionId)); this.Response.StatusCode = (int)HttpStatusCode.Created; this.Response.AddHeader("Location", url); return new JsonNetResult { Data = new { Submission = submission } }; }
public byte[] CreateQuoteSheetPdf(CreateQuoteSheetDto dto) { var parameters = new List<ParameterValue>(); //var reportPath = ConfigurationManager.AppSettings["QuoteSheetReportPath"] ?? //"/Underwriting/Console/QuoteSheet"; var reportPath = dto.QuoteSheetTemplateUrl ?? ConfigurationManager.AppSettings["QuoteSheetReportPath"]; using (var reportService = new ReportExecutionService()) { reportService.PreAuthenticate = true; reportService.Credentials = CredentialCache.DefaultCredentials; foreach (var option in dto.OptionList) { parameters.AddRange(option.OptionVersionNumberList.Select(versionNumber => new ParameterValue { Name = "OptionVersions", Value = option.OptionId + "," + versionNumber })); } parameters.Add(new ParameterValue { Name = "QuoteType", Value = dto.QuoteSheetTemplateName }); reportService.LoadReport(reportPath, null); reportService.SetExecutionParameters(parameters.ToArray(), "en-gb"); String extension, encoding, mimetype; String[] streamIds; Warning[] warnings; return reportService.Render("PDF", null, out extension, out encoding, out mimetype, out warnings, out streamIds); } }
public string CreateQuoteSheet(CreateQuoteSheetDto dto, out Submission submission) { // TODO: use the correct quote sheet... var quoteSheetTemplateId = dto.QuoteSheetTemplateId; dto.QuoteSheetTemplateUrl = this.ConsoleRepository.Query<QuoteTemplate>() .FirstOrDefault(qt => qt.Id == dto.QuoteSheetTemplateId).RdlPath; dto.QuoteSheetTemplateName = this.ConsoleRepository.Query<QuoteTemplate>() .FirstOrDefault(qt => qt.Id == dto.QuoteSheetTemplateId).Name; submission = this.SubmissionModule.GetSubmissionById(dto.SubmissionId); //todo this is done to clear previous context. has to be fixed once softdelet is fixed. using (IConsoleRepository consoleRepository = new ConsoleRepository()) { if (submission == null) throw new KeyNotFoundException(string.Format(this.NotFoundMessage, dto.SubmissionId)); consoleRepository.Attach(submission); var currentUser = consoleRepository.Query<User>() .FirstOrDefault(u => u.DomainLogon == this.HttpContext.CurrentUser.Identity.Name); if (currentUser == null) throw new ApplicationException("Current user could not be found"); var versions = (from version in submission.Options.SelectMany(o => o.OptionVersions) from option in dto.OptionList where version.OptionId == option.OptionId from versionNumber in option.OptionVersionNumberList where version.VersionNumber == versionNumber select version).ToList(); var isDeclinature = false; var submSt = submission.Options.Select(s => s) .SelectMany(o => o.OptionVersions) .SelectMany(ov => ov.Quotes) .Where(q => q.IsSubscribeMaster).Select(s => s.SubmissionStatus).Distinct().ToList(); if ((submSt.Count == 1) && (submSt.FirstOrDefault().Equals(Settings.Default["DeclinatureSubmissionStatus"].ToString()))) isDeclinature = true; var quotesheet = new QuoteSheet {//Todo: S2Q Title = string.Format(this.QuoteSheetTitle, submission.Title, versions.SelectMany(ov => ov.Quotes).First().InsuredName, DateTime.Now), IssuedBy = currentUser, IssuedById = currentUser.Id, IssuedDate = DateTime.Now, ObjectStore = Settings.Default["DMSObjectStore"].ToString(), DocumentClass = Settings.Default["DMSDocumentClass"].ToString(), DocumentType = isDeclinature ? Settings.Default["DeclinatureDocType"].ToString() : Settings.Default["QuoteDocType"].ToString() }; var content = this.QuoteSheetData.CreateQuoteSheetPdf(dto, isDeclinature); quotesheet.Guid = this.QuoteSheetData.SaveQuoteSheetToDMS(quotesheet, content, submission, isDeclinature); quotesheet.OptionVersions = versions; if (!isDeclinature) { foreach (var quote in versions.SelectMany(ov => ov.Quotes)) { if (!quote.SubmissionStatus.Equals(Settings.Default["DeclinatureSubmissionStatus"].ToString())) { quote.OptionVersion.IsLocked = true; quote.SubmissionStatus = "QUOTED"; } } } consoleRepository.Add(quotesheet); consoleRepository.SaveChanges(); return string.Format(this.QuoteSheetUrl, ConfigurationManager.AppSettings["UWDmsFileDownloadURL"], quotesheet.Guid); } }