Example #1
0
        public async Task <IActionResult> Register(RegisterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (await _db.UserRepository.UserExistsAsync(viewModel.Email))
                {
                    ViewBag.SuccessRegister = false;

                    ModelState.AddModelError("Email", "این ایمیل قبلا ثبت شده است");
                    return(View(viewModel));
                }
                else
                {
                    var result = await _accountService.Register(viewModel);

                    if (result.Status)
                    {
                        ViewBag.SuccessRegister = true;

                        // Send Email
                        var token = await _accountService.GetActivateEmailToken(result.User);

                        var activateModel = new EmailUrlViewModel()
                        {
                            Url = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}" + Url.Action(nameof(ActivateEmail), new { UserName = result.User.UserName, Token = token })
                        };
                        string emailBody = _viewRenderService.RenderToString("_ActivateEmail", activateModel);
                        _messageSender.SendEmail(result.User.Email, "فعالسازی حساب کاربری", emailBody);

                        return(View());
                    }
                    else
                    {
                        ViewBag.SuccessRegister = false;

                        foreach (var errorMessage in result.ErrorMessages)
                        {
                            ModelState.AddModelError("", errorMessage);
                        }
                        return(View(viewModel));
                    }
                }
            }
            else
            {
                ViewBag.SuccessRegister = false;

                return(View(viewModel));
            }
        }
        public void Send <T>(T model) where T : PageModel
        {
            EmailSender.IsBodyHtml = true;
            var templateName = typeof(T).Name;

            EmailSender.Body = renderService.RenderToString(templateName.Substring(templateName.Length - 5), model);
            EmailSender.Send();
        }
Example #3
0
        public override async Task <Email> Build()
        {
            var mailMessage = await base.Build();

            mailMessage.IsBodyHtml = true;
            mailMessage.Subject    = "Confirm Account"; //TODO ZMIEN NA LANGUAGE
            mailMessage.Body       = await _viewRenderService.RenderToString("~/Emails/EmailBuilders/ConfirmAccount/ConfirmAccountTemplate.cshtml", _templateModel);

            return(mailMessage);
        }
Example #4
0
        public async Task <IActionResult> Template([FromRoute] string name, [FromQuery] EmailTemplateModel model)
        {
            if (model.Preview)
            {
                return(View(name, model));
            }

            var renderedEmail = await _viewRenderService.RenderToString($"EmailTemplate/{name}", model);

            return(Ok(renderedEmail));
        }
Example #5
0
        public string Render(params object[] paramiters)
        {
            if (string.IsNullOrEmpty(_htmlContent) || (GlobalContext.WebSite.EnableCache == false && (_lastRenderTime - DateTime.Now >= new TimeSpan(0, 0, _minCacheDuration))))
            {
                _lastRenderTime = DateTime.Now;
                var model = PrepareViewModel(paramiters);
                _viewRenderService = GlobalContext.GetViewRenerService();
                _htmlContent       = _viewRenderService.RenderToString(ModuleController, ViewFileName, model);
            }

            return(_htmlContent);
        }
        public string Render(List <LogItem> logs, string title, IViewRenderService renderservice)
        {
            RazorModel model = new RazorModel
            {
                CaptureDate   = DateTime.UtcNow,
                TotalDuration = logs.Count == 0 ? TimeSpan.MinValue : logs.Last().ServerTime - logs.First().ServerTime,
                Title         = title,
                Logs          = logs,
                RequestsCount = logs.Count(l => l is HttpRequestLog)
            };

            //var engine = new RazorLight.RazorLightEngineBuilder()
            //    .UseMemoryCachingProvider()
            //    .Build();

            return(renderservice.RenderToString(Resources.HtmlLogTemplate, model.Title, model));
        }
        public async Task SendNotification(EmailTemplate template)
        {
            if (template.ViewModel != null)
            {
                template.ViewModel.BlogHost = "todo";
            }

            var body = await _viewRender.RenderToString(template.ViewName, template.ViewModel);

            var notification = new Notification
            {
                Body       = body,
                Recipients = template.Recipients,
                Subject    = template.Subject
            };

            await _sender.Send(notification);
        }
Example #8
0
        public IActionResult IframeTest()
        {
            var stream        = new MemoryStream();
            var request       = HttpContext.Request;
            var framedContent = UriHelper.BuildAbsolute(request.Scheme,
                                                        request.Host,
                                                        request.PathBase,
                                                        request.Path.Value.ToLowerInvariant().Replace(nameof(IframeTest).ToLowerInvariant(), nameof(Iframe)),
                                                        request.QueryString);

            var iframeTestMarkup = _viewRenderService.RenderToString("~/Views/Risk/IframeTest.cshtml", framedContent);

            var bytes = Encoding.UTF8.GetBytes(iframeTestMarkup);

            stream.Write(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);
            HttpContext.Response.Headers[HeaderNames.ContentDisposition] = "attachment;filename=\"iframetest.html\"";
            return(new FileStreamResult(stream, MediaTypeNames.Text.Html));
        }
        // GET: /Imprimir/AjaxList
        public IActionResult AjaxList(string cep, string id_upload)
        {
            var upload = db.Uploads.FindById(new ObjectId(id_upload));

            try
            {
                var end = SetCEP_End(cep);
                if (end == null)
                {
                    return(Json(new { ok = false, err = "CEP inválido" }));
                }

                var coord    = Utils.RetryPattern(() => Utils.BuscaCoordEnd(end), "ERROR");
                var empresas = db.Empresas.FindAll().ToList();
                if (coord != null)
                {
                    empresas.OrderBy(p => p, new GeoDistComparer(coord)).ToList();
                }

                List <PrinterUIModel> printers = new List <PrinterUIModel>();
                foreach (var e in empresas)
                {
                    var impr = db.Impressoras.Include(i => i.Empresa).Find(i => i.Empresa.Id == e.Id);
                    foreach (var i in impr)
                    {
                        var mats = db.Material.Include(m => m.Impressora).Include(m => m.Impressora.Empresa).Find(m => m.Impressora.Id == i.Id).ToList();
                        foreach (var m in mats)
                        {
                            double valor_peca = m.PrecoPeca(upload);
                            printers.Add(new PrinterUIModel(m, valor_peca));
                        }
                    }
                }

                string html = _viewRenderService.RenderToString("Imprimir/_PrinterList", printers);
                return(Json(new { ok = true, html }));
            }
            catch (Exception)
            {
                return(Json(new { ok = false, err = "Falha no servidor" }));
            }
        }
Example #10
0
        public void Init(long websiteWidgetId, bool renderConfig = false)
        {
            WebSiteWidgetId    = websiteWidgetId;
            _viewRenderService = GlobalContext.GetViewRenerService();

            var webSiteWidget = GlobalContext.WebSiteWidgets.Where(x => x.Id == websiteWidgetId).FirstOrDefault();

            if (webSiteWidget != null && !string.IsNullOrEmpty(webSiteWidget.WidgetConfigJson))
            {
                var configJson = webSiteWidget.WidgetConfigJson;
                var config     = JsonHelper.Deserilize <dynamic>(configJson);
                DisplayTitle = config.title;
                Footer       = config.footer;
                Language     = config.language;
                if (string.IsNullOrWhiteSpace(DisplayTitle))
                {
                    DisplayTitle = "";
                }
                if (string.IsNullOrWhiteSpace(Footer))
                {
                    Footer = "";
                }
                if (string.IsNullOrWhiteSpace(Language))
                {
                    Language = "";
                }
                InitConfig(config); //Calls for giving config object to user for getting their defined configuration.
            }
            else
            {
                DisplayTitle = Title;
            }

            if (renderConfig && string.IsNullOrEmpty(ConfigViewFileName) == false)
            {
                var model = PrepareConfigModel();
                ConfigHtml = _viewRenderService.RenderToString(ModuleController, ConfigViewFileName, model);
            }
        }
Example #11
0
 public async Task <string> Compile(T model)
 {
     return(await _viewRenderService.RenderToString(model));
 }