Example #1
0
        public async Task <IActionResult> CreatePDF(ExportDatesViewModel model)
        {
            var user        = this.User.Claims.ToList();
            var getUserById = await _jitService.GetUserById(Convert.ToInt32(user[1].Value));

            var getAllProjectsByUser = await _jitService.GetAllProjectsBetweenDates(Convert.ToInt32(user[1].Value), model.StartDate, model.EndDate);

            var projectsForPDFCreation = _mapper.Map <ICollection <ProjectDto>, ICollection <ProjectViewModel> >(getAllProjectsByUser);

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
            };

            //if we want to save it on our hard disk
            //Out = @"E:\Employee_Report.pdf"

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(projectsForPDFCreation, getUserById.Username),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Helpers", "pdf-generator.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Tech Resources d.o.o." }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            try
            {
                return(File(file, "application/pdf"));
            }
            catch (Exception)
            {
                return(RedirectToAction("NotFound", "Home"));
            }
        }
Example #2
0
        public async Task <bool> SendEmail(string secretKey, int?id, UserDto user = null)
        {
            if (user == null)
            {
                user = await _jitService.GetUserById(id.Value);
            }
            var apiKey = secretKey;
            var client = new SendGridClient(apiKey);

            var from             = new EmailAddress("*****@*****.**", "Admin user");
            var subject          = "Welcome to Just in Time";
            var to               = new EmailAddress(user.Email, user.Name);
            var plainTextContent = "Please click the link to activate your account";
            var htmlContent      = $"Please click the <a href='https://localhost:44312/auth/{user.Id}'>link</a> below to activate your account";
            var msg              = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
            var response         = await client.SendEmailAsync(msg);

            if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                return(true);
            }

            return(false);
        }