Ejemplo n.º 1
0
        public async Task <IActionResult> SendEnquiryEmail(QuotesViewModel quoteModel)
        {
            if (Request.Form["SendEnquiryEmail"].Count > 0)
            {
                var facades = await _service.GetFacadesAsync();

                var promotions = await _service.GetPromotionsAsync();

                var packages = await _service.GetPackagesAsync();

                var inclusions = await _service.GetInclusionsAsync();

                var houseDesigns = await _service.GetHouseDesignsAsync();

                var inclusionDetails = await _service.GetInclusionDetailsAsync();

                quoteModel.SetMasterData(facades, promotions, houseDesigns, packages, inclusions, inclusionDetails);


                DesignViewModel    houseDesign = quoteModel.HouseDesignId.HasValue ? quoteModel.HouseDesigns.First(x => x.Id == quoteModel.HouseDesignId.Value) : quoteModel.HouseDesigns.First();
                FacadeViewModel    facade      = quoteModel.FacadeId.HasValue ? quoteModel.Facades.First(x => x.Id == quoteModel.FacadeId.Value) : quoteModel.Facades.First();
                InclusionViewModel inclusion   = quoteModel.InclusionId.HasValue ? quoteModel.Inclusions.First(x => x.Id == quoteModel.InclusionId.Value) : quoteModel.Inclusions.First();

                quoteModel.HouseDesignName = houseDesign.Name;
                quoteModel.InclusionName   = inclusion.Name;
                quoteModel.FacadeName      = facade.Name;
                quoteModel.BasePrice       = houseDesign.Cost;
                quoteModel.Documents       = await _service.GetDocuments(quoteModel.Id);

                if (quoteModel.Documents == null)
                {
                    quoteModel.Documents = new List <DocumentViewModel>();
                }
                await _emailSender.SendEmailAsync(quoteModel);

                TempData["SuccessMessage"] = "Your enquiry has been sent successfully.";

                return(View("CreateQuote", quoteModel));
            }
            else
            {
                var vmReturn = await GeneratePdfDocument(quoteModel);

                TempData["SuccessMessage"] = "Your quote has been generated successfully.";
                return(View("CreateQuote", vmReturn));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PartialEnquiryEmail(QuotesViewModel quoteModel)
        {
            var facades = await _service.GetFacadesAsync();

            var promotions = await _service.GetPromotionsAsync();

            var packages = await _service.GetPackagesAsync();

            var inclusions = await _service.GetInclusionsAsync();

            var houseDesigns = await _service.GetHouseDesignsAsync();

            var inclusionDetails = await _service.GetInclusionDetailsAsync();

            quoteModel.EmailCC = Request.Form["EmailCC"][0];
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Error .. Please check email format .."));
            }


            quoteModel.SetMasterData(facades, promotions, houseDesigns, packages, inclusions, inclusionDetails);
            DesignViewModel    houseDesign = quoteModel.HouseDesignId.HasValue ? quoteModel.HouseDesigns.First(x => x.Id == quoteModel.HouseDesignId.Value) : quoteModel.HouseDesigns.First();
            FacadeViewModel    facade      = quoteModel.FacadeId.HasValue ? quoteModel.Facades.First(x => x.Id == quoteModel.FacadeId.Value) : quoteModel.Facades.First();
            InclusionViewModel inclusion   = quoteModel.InclusionId.HasValue ? quoteModel.Inclusions.First(x => x.Id == quoteModel.InclusionId.Value) : quoteModel.Inclusions.First();

            quoteModel.HouseDesignName = houseDesign.Name;
            quoteModel.InclusionName   = inclusion.Name;
            quoteModel.FacadeName      = facade.Name;
            quoteModel.BasePrice       = houseDesign.Cost;
            quoteModel.Documents       = await _service.GetDocuments(quoteModel.Id);

            if (quoteModel.Documents == null)
            {
                quoteModel.Documents = new List <DocumentViewModel>();
            }
            await _emailSender.SendEmailAsync(quoteModel);

            TempData["SuccessMessage"] = "Your enquiry has been sent successfully.";
            return(PartialView("_quoteEmailPartial", quoteModel));
        }
Ejemplo n.º 3
0
        private async Task <QuotesViewModel> GeneratePdfDocument(QuotesViewModel vm)
        {
            //var doc = @"https://docs.google.com/document/d/1Lm4WZMynzfOwjsFTFF7SLDvKYfb2AG6YRfpc9tFcepc";
            // Response.Redirect($"{doc}");
            //if (!ModelState.IsValid)
            //{
            //    return PartialView("_quoteEmailPartial", quoteModel);
            //}



            var facades = await _service.GetFacadesAsync();

            var promotions = await _service.GetPromotionsAsync();

            var packages = await _service.GetPackagesAsync();

            var inclusions = await _service.GetInclusionsAsync();

            var houseDesigns = await _service.GetHouseDesignsAsync();

            var inclusionDetails = await _service.GetInclusionDetailsAsync();

            var additionalInclusionDetails = await _service.GetAdditionalInclusionDetailsAsync(vm.Id);

            vm.SetMasterData(facades, promotions, houseDesigns, packages, inclusions, inclusionDetails, additionalInclusionDetails);


            DesignViewModel    houseDesign = vm.HouseDesignId.HasValue ? vm.HouseDesigns.First(x => x.Id == vm.HouseDesignId.Value) : vm.HouseDesigns.First();
            FacadeViewModel    facade      = vm.FacadeId.HasValue ? vm.Facades.First(x => x.Id == vm.FacadeId.Value) : vm.Facades.First();
            InclusionViewModel inclusion   = vm.InclusionId.HasValue ? vm.Inclusions.First(x => x.Id == vm.InclusionId.Value) : vm.Inclusions.First();

            vm.HouseDesignName = houseDesign.Name;
            vm.InclusionName   = inclusion.Name;
            vm.FacadeName      = facade.Name;
            vm.BasePrice       = houseDesign.Cost;
            vm.FacadeCost      = facade.Cost == 0 ? "Included" : facade.Cost.ToString("C0");
            var fileName = vm.JobNumber + "-" + Guid.NewGuid().ToString() + ".pdf";

            var masterdata = inclusionDetails.ToTableData(vm.BasePrice, facade.Cost, vm.AdditionalInclusions); // await _service.GetContractDetails();

            vm.TableData = masterdata;


            var htmmlString = RenderPartialViewToString("QuotePdfTemplate", vm);

            IronPdf.License.LicenseKey = _appSettings.IronPdfKey;
            var Renderer = new IronPdf.HtmlToPdf();

            // Build a footer using html to style the text
            // mergable fields are:
            // {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}

            Renderer.PrintOptions.Footer = new HtmlHeaderFooter()
            {
                Height       = 30,
                HtmlFragment = "<center><div class=\"stl_01\" style=\"top: 64.9321em;white-space:nowrap;left:25.3123em;\"><span class=\"stl_20\">{page}</span></div></center>" +
                               "<center><div class=\"stl_01\" style=\"top: 66.1712em; left: 13.3647em; \"><span class=\"stl_21 stl_10\" style=\"word - spacing:0.02em; \">(Test Company Pty Ltd) T/A   Pty Ltd | ABN 12 345 678 900|</span><span class=\"stl_21 stl_10\" style=\"word-spacing:0.03em;\">company address</span>" +
                               "<span class=\"stl_21 stl_10\" style=\"word-spacing:0.05em;\"></span></div></center>" +
                               "<center><div class=\"stl_01\" style=\"top: 67.0469em; left:18.9945em;z-index:801;\"><span class=\"stl_21 stl_10\" style=\"word-spacing:0.27em;\">Ph: (02)</span>" +
                               "<span class=\"stl_21 stl_10\" style=\"word-spacing:0.02em;\">&nbsp;8630</span><span class=\"stl_21 stl_10\" style=\"word-spacing:0.02em;\">&nbsp;8996 |</span>" +
                               "<span class=\"stl_21 stl_10\" style=\"word-spacing:0em;\">&nbsp;</span><a href = \"company url\" target=\"_blank\"><span class=\"stl_22\" style=\"word-spacing:0em;\">​</span></a>" +
                               "<a href = \"company url\" target=\"_blank\"><span class=\"stl_23 stl_10\" style=\"word-spacing:0em;\">www.testcompany<span class=\"stl_14\">.com.au &nbsp;</span></span></a></div></center>" +
                               "<div class=\"stl_01\" style=\"top: 67.7975em; margin-left:3.7308em;\"><span class=\"stl_21 stl_14\" style=\"word-spacing:0em;\">Client Initial........../<span class=\"stl_10\">.......... &nbsp;</span></span></div>" +
                               "<div class=\"stl_01\" style=\"top: 68.6107em; margin-left:3.7308em;\"><span class=\"stl_21 stl_10\" style=\"word-spacing:0.03em;\">Test Company - © 2020 &nbsp;</span></div>",
                DrawDividerLine = true
            };

            // Build a header using an image asset
            // Note the use of BaseUrl to set a relative path to the assets
            //if cover page un comment below line
            Renderer.PrintOptions.FirstPageNumber = 2;

            Renderer.PrintOptions.Header = new HtmlHeaderFooter()
            {
                Height          = 30,
                HtmlFragment    = System.IO.File.ReadAllText($"{_env.WebRootPath}/templates/header.html"),
                BaseUrl         = $"{_env.WebRootPath}/templates",
                Spacing         = 5,
                DrawDividerLine = true,
                LoadStylesAndCSSFromMainHtmlDocument = true
            };

            Renderer.PrintOptions.Zoom            = 100;
            Renderer.PrintOptions.FitToPaperWidth = true;
            Renderer.PrintOptions.MarginTop       = 0; //millimenters
            Renderer.PrintOptions.MarginLeft      = 0; //millimenters
            Renderer.PrintOptions.MarginRight     = 0; //millimenters
            Renderer.PrintOptions.MarginBottom    = 50;


            var coverPageRenderer = new IronPdf.HtmlToPdf();

            coverPageRenderer.PrintOptions.Zoom            = 100;
            coverPageRenderer.PrintOptions.FitToPaperWidth = true;
            coverPageRenderer.PrintOptions.MarginTop       = 0; //millimenters
            coverPageRenderer.PrintOptions.MarginLeft      = 0; //millimenters
            coverPageRenderer.PrintOptions.MarginRight     = 0; //millimenters
            Renderer.PrintOptions.MarginBottom             = 0;
            var coverpageHtml = System.IO.File.ReadAllText($"{_env.WebRootPath}/templates/coverpage1.html").Replace("{{Name}}", vm.Name).Replace("{{JobNumber}}", vm.JobNumber).Replace("{{RequestType}}", vm.RequestType);
            var coverpage     = coverPageRenderer.RenderHtmlAsPdf(coverpageHtml, $"{_env.WebRootPath}/templates");

            //Renderer.RenderHtmlAsPdf(htmmlString).PrependPdf(coverPage).SaveAs("html-string.pdf");

            //Renderer.RenderHtmlAsPdf(htmmlString).SaveAs("html-string.pdf");

            var quoteDoc = Renderer.RenderHtmlAsPdf(htmmlString).PrependPdf(coverpage);
            //.Stream;
            //var stream = coverpage.Stream;
            //  .SaveAs("html-string.pdf");
            //var inclusionDoc = PdfDocument.FromFile($"{_env.WebRootPath}{inclusion.FileUrl}");

            //quoteDoc = quoteDoc.AppendPdf(inclusionDoc);
            var quoteFromDb = await _service.GetQuoteByIdAsync(vm.Id);

            if (quoteFromDb.IsTender.HasValue &&
                quoteFromDb.IsTender.Value &&
                !string.IsNullOrEmpty(quoteFromDb.PdfUrl))
            {
                // read file from Azure Syore
                using (MemoryStream mem = new MemoryStream())
                {
                    ConvertToStream(quoteFromDb.CustomPdfUrl, mem);
                    var customPdfDoc = new PdfDocument(mem);
                    quoteDoc = quoteDoc.AppendPdf(customPdfDoc);
                }
            }
            var stream = quoteDoc.Stream;
            //.SaveAs("html-string.pdf");
            //await _azureStorageService.UploadDocAsync("html-string.pdf", vm.JobNumber +"-"+ Guid.NewGuid().ToString()+".pdf");
            await _azureStorageService.UploadDocAsync(stream, fileName);

            var docVM = new DocumentViewModel {
                Name = fileName, Title = $"{vm.JobNumber} {vm.RequestType}", QuoteId = vm.Id
            };

            await _service.SaveDocumentAsync(docVM, UserId);

            var docs = await _service.GetDocuments(vm.Id);

            vm.Documents = docs;
            //var context = new CustomAssemblyLoadContext();
            //context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "DinkToPdf.dll"));
            //var converter = new SynchronizedConverter(new PdfTools());


            //converter.Convert(pdf);

            //var basePath = $"https://docs.google.com/document/d/";
            //var id =_docGeneration.GenerateDoc(vm);
            //vm.DocUrl = $"{basePath}{id}";
            //TempData["SuccessMessage"] = "The document has been generated successfully!!";

            return(vm);
        }