public async Task <ResultObject> SendNotificationResponsibleUser(int requestId)

        {
            var request = _requestRepository.GetBy(r => r.id == requestId, includeProperties: "request_workflow_steps");

            if (_enviroment.IsDevelopment())
            {
                var viewString = await _viewRenderServicerenderService.RenderViewToStringAsync("Mail/SampleRequestNotification", request);

                SendMail(_mailsettings.test_email,
                         viewString,
                         "", _mailsettings.name_to, "you have a pending request");
            }
            else
            {
                var steps = request.request_workflow_steps;
                foreach (RequestWorkflowStep step in steps)
                {
                    var viewString = await _viewRenderServicerenderService.RenderViewToStringAsync("Mail/SampleRequestNotification", request);

                    var user = _userRepository.GetBy(u => u.uname == step.primary_responsible_id);
                    SendMail(user.email,
                             viewString,
                             "", user.name, "you have a peeding request");
                }
            }


            return(resultobject);
        }
        public async Task <IActionResult> Search(string searchTerm)
        {
            var normalisedSearchTerm = searchTerm.ToLowerInvariant().Replace(" ", "");

            var employees = _context.Employees.Where(x => x.NormalisedName.Contains(normalisedSearchTerm)).ToList();

            var results = new List <SearchResult>();

            foreach (var employee in employees)
            {
                var result = new SearchResult
                {
                    FirstName   = employee.FirstName,
                    LastName    = employee.LastName,
                    PhoneNumber = employee.PhoneNumber,
                    Country     = employee.Country,
                    Id          = employee.Id
                };
                results.Add(result);
            }

            if (results.Count == 1)
            {
                return(await GetEmployeeDetails(results.First().Id));
            }

            var view = await _viewRenderService.RenderViewToStringAsync("Home/SearchResultsTable", new SearchResultsModel { Results = results });

            return(Content(view));
        }
Beispiel #3
0
        public async Task <IDictionary <string, string> > GetAsync(int stepnumber, string sessionId)
        {
            var result = new ConcurrentDictionary <string, string>();

            var model = new StepViewModel();

            await PageSetup(model, stepnumber, sessionId);


            var viewString = await viewRenderService.RenderViewToStringAsync("/Views/Step/Index.cshtml", model);

            result.TryAdd($"StepNumber-{stepnumber}", viewString);

            return(result);
        }
        public async Task SendEmailWithTemplateAsync(
            string viewName,
            string address,
            string subject,
            object viewModel = null,
            params Attachment[] attachments)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                throw new ArgumentException($"{nameof(viewName)} must not be empty");
            }

            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentException($"{nameof(address)} must not be empty");
            }

            if (string.IsNullOrEmpty(subject))
            {
                throw new ArgumentException($"{nameof(subject)} must not be empty");
            }

            var htmlBody = await _viewRenderService
                           .RenderViewToStringAsync(viewName, viewModel ?? new object());

            await _emailSender.SendEmailAsync(new EmailModel
            {
                Subject     = subject,
                Recipients  = new[] { new Address(address) },
                HtmlBody    = htmlBody,
                Attachments = attachments.ToList()
            });
        }
Beispiel #5
0
        public async Task <IActionResult> GetPosts([FromForm] int pageIndex = 1)
        {
            var(posts, loadmore) = await _postService.GetPagedPostsAsync(pageIndex);

            var model = new PostTemplateModel
            {
                Posts    = posts,
                LoadMore = loadmore
            };
            var postTemplate = await _renderService.RenderViewToStringAsync("Templates/_Post", model);

            return(Json(new
            {
                posts = postTemplate,
                loadMore = model.LoadMore
            }));
        }
Beispiel #6
0
        public async Task PushNotification(string recipientId, int notificationId)
        {
            var model = await GetNotificationByIdAsync(notificationId);

            var totalNotifications = await GetTotalUnReadNotificationsAsync(recipientId);

            var notification = await _renderService.RenderViewToStringAsync("Templates/_MiniNotification", model);
        }
Beispiel #7
0
        public async Task <IActionResult> LoadNotifications(int pageIndex, int pageSize, NotificationTemplateType type)
        {
            var(notifications, loadMore) = await _notificationService.GetPagedNotificationsAsync(
                await _userService.GetCurrentUserIdAsync(),
                pageIndex, pageSize);

            var model = new NotificationTemplateModel
            {
                LoadMore      = loadMore,
                Notifications = notifications
            };

            string template;

            switch (type)
            {
            case NotificationTemplateType.Main:
                template = await _renderService.RenderViewToStringAsync("Templates/_MainNotification", model);

                break;

            case NotificationTemplateType.Mini:

                var liCollection = new List <string>();

                foreach (var notification in notifications)
                {
                    liCollection.Add(
                        await _renderService.RenderViewToStringAsync("Templates/_MiniNotification", notification));
                }

                template = string.Join("", liCollection);
                break;

            default:
                throw new InvalidOperationException(nameof(type));
            }

            return(Json(new
            {
                notifications = template,
                loadMore,
                type
            }));
        }
Beispiel #8
0
        public async Task <string> RenderToHtmlAsStringAsync(CertificateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            return(await _viewRenderService.RenderViewToStringAsync(ViewName, viewModel));
        }
Beispiel #9
0
        private async Task <MimeMessage> CreateMailInternalAsync(string templateName, object model, ExpandoObject viewBag, bool allowDefault, Func <string, string, string> htmlModifier)
        {
            if (!(viewBag is IDictionary <string, object> viewBagDictionary))
            {
                throw new ArgumentException($"Parameter {nameof(viewBag)} must implement IDictionary<string, object>");
            }
            if (!viewBagDictionary.ContainsKey("Layout"))
            {
                viewBagDictionary["Layout"] = "/Views/_LayoutMail.cshtml";
            }
            if (!viewBagDictionary.ContainsKey("BaseUrl"))
            {
                throw new ArgumentException($"Parameter {nameof(viewBag)} must provide a BaseUrl property, i.e. http://yourwebsite.com");
            }
            string html = await templateEngine.RenderViewToStringAsync(templateName, model, viewBag);

            if (html != null)
            {
                // find email subject
                Match match = subjectMatch.Match(html);
                if (match.Success)
                {
                    string subjectText = match.Groups["subject"].Value.Trim();

                    // two or more spaces to one space in subject
                    subjectText = subjectReplacer.Replace(subjectText, " ");

                    html = (htmlModifier == null ? html : htmlModifier.Invoke(html, subjectText));
                    html = PreMailer.Net.PreMailer.MoveCssInline(html, true, IgnoreElements).Html;

                    BodyBuilder builder = new BodyBuilder
                    {
                        HtmlBody = html
                    };
                    return(new MimeMessage
                    {
                        Body = builder.ToMessageBody(),
                        Subject = subjectText
                    });
                }
                else
                {
                    throw new InvalidOperationException(Resources.MissingSubjectInTemplate);
                }
            }
            else if (allowDefault)
            {
                templateName = MailTemplate.GetTemplateName(templateName);
                return(await CreateMailInternalAsync(templateName + "Default", model, viewBag, false, null));
            }

            throw new ArgumentException("No view found for name " + templateName);
        }
        private async Task <bool> SendQuoteRequest(OrderQuote quote)
        {
            try
            {
                var emailBody = await RenderService.RenderViewToStringAsync("/EmailTemplates/QuoteRequest.cshtml", quote);

                var mailResquest = new MailRequest()
                {
                    Body    = emailBody,
                    Subject = $"Order Quote from {quote.Email}",
                    ToEmail = MailSettings.Mail
                };
                await MailService.SendEmailAsync(mailResquest);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #11
0
        public async Task <IDictionary <string, string> > Get(string urlName)
        {
            var result = new ConcurrentDictionary <string, string>();

            var model = new SkillsModel
            {
                Skills        = repository.GetSkills(SocCodeMapping(urlName))?.Select(x => x.skillname),
                JobProfileUrl = urlName
            };

            var viewString = await viewRenderService.RenderViewToStringAsync("SkillsList", model);

            result.TryAdd("Skills", viewString);

            return(result);
        }
Beispiel #12
0
        public async Task <IActionResult> GetUserPosts(string username, [FromForm] int pageIndex = 1)
        {
            var user = await _userService.GetUserByUserNameAsync(username);

            if (user == null)
            {
                return(NotFound());
            }

            var result = await _postService.GetUserPostsAsync(pageIndex, user.Id);

            var model = new PostTemplateModel
            {
                Posts    = result.data,
                LoadMore = result.loadMore
            };
            var postTemplate = await _renderService.RenderViewToStringAsync("Templates/_Post", model);

            return(Json(new
            {
                posts = postTemplate,
                loadMore = model.LoadMore
            }));
        }
        private async Task <byte[]> PdfConverter(string fileName)
        {
            //html = "<div class='col-sm-12'><img src='" + Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") +
            //        "/Images/Barcode-ObservationConsultation.jpg' height='70' width='126' style='float:right'/><div style='clear:both'></div></div>" + html;

            string viewHtml = string.Empty;

            viewHtml = await _viewRenderService.RenderViewToStringAsync(this.ControllerContext, "LoanApplication", new LoanViewModel(), TempData);


            string applicationFormFilePath       = _applicationFormDirectorypath + "/" + fileName;
            string applicationFormOutputFilePath = _applicationFormDirectorypath + "/Generated_" + fileName;

            if (!Directory.Exists(_applicationFormDirectorypath))
            {
                Directory.CreateDirectory(_applicationFormDirectorypath);
            }

            System.IO.File.WriteAllText(applicationFormFilePath, viewHtml, Encoding.UTF8);



            //var headerText = "<br/><b>" + patient.SName + ", " + patient.FName + "</b>&nbsp;&nbsp;&nbsp;&nbsp;PAS No: " + patient.PasNo + "&nbsp;&nbsp;&nbsp;&nbsp;DOB: " + (string.IsNullOrEmpty(patient.DOB) ? "N/A" : dob.ToString("dd/MM/yyyy")) + (string.IsNullOrEmpty(patient.NHS_No) ? "" : " NHS No :" + patient.NHS_No);

            byte[] convertedPdfBytes;

            try
            {
                var pdfConverter = new HtmlToPdfConverter
                {
                    //PageHeaderHtml = "",
                    Orientation = PageOrientation.Portrait,
                    LowQuality  = false,
                    Margins     = new PageMargins {
                        Bottom = 20, Left = 10, Right = 10, Top = 20
                    },
                    //PageFooterHtml =
                    //    "<center><small>Generated by Our Clinic Report Generator on " + DateTime.Now.ToString("dd MMMM yyyy HH:mm:ss") + "<span class='page'></span>" +
                    //"</center></small>"
                };

                //pdfConverter.PageHeaderHtml = headerText + "<div style='vertical-align: middle; font-size: 12px;font-weight:bold; color: #fff;background-color:#007fff;margin: 20px 0px 10px 0px; padding: 5px 5px;float:right'>Page <b class='page'></b> of <b class='topage'></b></div><div style='clear:both;'></div>";


                convertedPdfBytes = pdfConverter.GeneratePdfFromFile(applicationFormFilePath, null);//Creates pdf very quickly from html file than content itself

                System.IO.File.WriteAllBytes(_applicationFormDirectorypath + "/ " + Path.GetFileNameWithoutExtension(fileName) + ".pdf", convertedPdfBytes);

                //if (!ignoreDownload)
                //{
                //    Response.Clear();
                //    var ms = new MemoryStream(convertedPdfBytes);
                //    Response.ContentType = "application/pdf";
                //    Response.AddHeader("Refresh", "3;URL=/Clinic/ClinicPatientManager.aspx");
                //    Response.AddHeader("content-disposition", "attachment;filename=PatientClinicalInfo_" + Path.GetFileNameWithoutExtension(fileName) + ".pdf");
                //    Response.Buffer = true;
                //    ms.WriteTo(Response.OutputStream);
                //    Response.End();
                //}
            }
            catch (Exception ex)
            {
                convertedPdfBytes = null;
            }
            return(convertedPdfBytes);
        }
Beispiel #14
0
 private async Task <string> PrepareMessageTemplate(ChatModel model)
 {
     return(await _renderService.RenderViewToStringAsync("Templates/_Chat", model));
 }