Exemplo n.º 1
0
        private string GetTemplateForMail()
        {
            var    model = new MailViewModel();
            Reader data  = new Reader {
                Id = 1, EmailAddress = "*****@*****.**", UserName = "******"
            };
            //model.Data.Add(data);

            // model.Data = ReaderStore.Readers;

            var response = _templateHelper.GetTemplateHtmlAsStringAsync <MailViewModel>("Templates/ForgetPassword", model);

            _mail.SendMail("*****@*****.**", "*****@*****.**", "Reader Test Data", response);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <string> GetTemplate()
        {
            var model = new MailViewModel();

            var response = await _templateHelper.GetTemplateHtmlAsStringAsync <List <Reader> >("Templates/Content", ReaderStore.Readers);

            model.Content = response;

            var headerImagePath = string.Format("{0}/{1}", _environment.ContentRootPath, "Images/banner-image.png");

            // var base64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(headerImage));

            model.HeaderImage = new LinkedResource()
            {
                ContentId   = "header",
                ContentPath = headerImagePath,
                ContentType = "image/png"
            }; //string.Format("data:image/png;base64,{0}", base64);

            _mail.SendMail("*****@*****.**", "Reader Test Data", model);

            return(response);
        }
Exemplo n.º 3
0
 public async Task <string> GetHtmlFromView <T>(
     string viewName,
     T model)
 {
     return(await _templateHelper.GetTemplateHtmlAsStringAsync(viewName, model));
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Index()
        {
            var response = await _templateHelper.GetTemplateHtmlAsStringAsync <List <Reader> >("Templates/Content", ReaderStore.Readers);

            return(View("Index", response));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> SendMessage(Order order, IEnumerable <OrderLine> ordersForMessage)
        {
            long numberOrder = ordersRepository.Orders.Last <Order>().Id;

            //var headerImagePath = "";
            foreach (var currentOrder in order.Lines)
            {
                if (currentOrder.Product != null)
                {
                    Product item = productRepository.Products.FirstOrDefault(p => p.Id == currentOrder.Product.Id);
                    if (item.Images != null && item.Images.Count > 0)
                    {
                        currentOrder.Product.Images[0].Name = item.Images[0].Name;
                        //headerImagePath = string.Format("{0}/{1}", _appEnvironment.ContentRootPath, "wwwroot/Files/Sm2/tiloLogo.png");
                    }
                }
            }
            //var textMessage = infoAboutOrder(order, ordersForMessage);
            EmailService emailService = new EmailService();
            string       subject      = "Order №" + numberOrder + " is processed. With love your Tiloshowroom";

            try
            {
                var model = new MailViewModel();

                model.HeaderImage = new List <Models.ViewModels.LinkedResource>();
                //headerImagePath = string.Format("{0}/{1}", _appEnvironment.ContentRootPath, "wwwroot/Files/Sm2/tiloLogo.png");

                //model.HeaderImage.Add(new Models.ViewModels.LinkedResource
                //{
                //    ContentId = "BraLayla4.jpg",
                //    ContentPath = headerImagePath,
                //    ContentType = "image/png"
                //});
                foreach (var currentOrder in order.Lines)
                {
                    if (currentOrder.Product != null)
                    {
                        Product item = productRepository.Products.FirstOrDefault(p => p.Id == currentOrder.Product.Id);
                        if (item.Images != null && item.Images.Count > 0)
                        {
                            currentOrder.Product.Images[0].Name = item.Images[0].Name;
                            var    path = string.Format("{0}/{1}", _appEnvironment.ContentRootPath, Url.Content("wwwroot/files/Sm2/" + item.Images[0].Name));
                            string name = currentOrder.Product.Images[0].Name.Trim();
                            model.HeaderImage.Add(new Models.ViewModels.LinkedResource
                            {
                                ContentId   = currentOrder.Product.Id.ToString(),
                                ContentPath = path,
                                ContentType = "image/jpeg"
                            });
                        }
                    }
                }
                order.Lines = ordersForMessage;
                var response = await _templateHelper.GetTemplateHtmlAsStringAsync <Order>("Orders/Content", order);

                model.Content = response;

                await emailService.SendEmailAsync(order.Email, subject, model);

                return(RedirectToAction("Completed"));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }