Exemplo n.º 1
0
        public HttpResponseMessage GenerateQuotationPdf(EstimationModel model)
        {
            try
            {
                var viewData = new System.Web.Mvc.ViewDataDictionary {
                    { "Estimation", model }
                };
                var html = RenderViewToString("TaskQuotation", "~/Views/Template/TaskQuotation.cshtml", viewData);

                var res    = PdfSharpConvert(html);
                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StreamContent(new MemoryStream(res));
                result.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/pdf");
                result.Content.Headers.ContentLength               = res.Length;
                result.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                result.Content.Headers.ContentDisposition.FileName = $"Estimate_{DateTime.Now.ToShortDateString()}.pdf";
                return(result);


                //var buffer = HtmlToPdf(html, "");
                //var result = Request.CreateResponse(HttpStatusCode.OK);
                //result.Content = new StreamContent(new MemoryStream(buffer));
                //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                //result.Content.Headers.ContentLength = buffer.Length;
                //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                //result.Content.Headers.ContentDisposition.FileName = $"Estimate_{DateTime.Now.ToShortDateString()}.pdf";
                //return result;
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 2
0
 public virtual MailMessage CreateMail(Models.DataViewModel model, string view)
 {
     ViewData = new System.Web.Mvc.ViewDataDictionary(model);
     var mailMessage = new MailMessage();
     PopulateBody(mailMessage, viewName: view);
     return mailMessage;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Clones the existing ViewDataDictionary into a new object.
        /// </summary>
        /// <param name="viewData"></param>
        /// <returns></returns>
        public static System.Web.Mvc.ViewDataDictionary Clone(this System.Web.Mvc.ViewDataDictionary viewData)
        {
            if (viewData == null)
            {
                return(null);
            }

            return(new System.Web.Mvc.ViewDataDictionary(viewData));
        }
Exemplo n.º 4
0
 public virtual MvcMailMessage UserRegistered(ApplicationUser user, string email)
 {
     ViewData = new System.Web.Mvc.ViewDataDictionary(user);
     return(Populate(x =>
     {
         x.Subject = "User Registered";
         x.ViewName = "UserRegistered";
         x.To.Add(email);
     }));
 }
    public IMailMessage Welcome(WelcomeMailModel model)
    {
        var mailMessage = new MailMessage();

        mailMessage.SetRecipients(model.To);
        mailMessage.Subject = "Welcome";
        ViewData            = new System.Web.Mvc.ViewDataDictionary(model);
        PopulateBody(mailMessage, "Welcome");
        return(mailMessage);
    }
Exemplo n.º 6
0
 public MvcMailMessage InvitationRequest(InvitationRequest invitationRequest, string email)
 {
     ViewData = new System.Web.Mvc.ViewDataDictionary(invitationRequest);
     return(Populate(x =>
     {
         x.Subject = "Invitation Request for VaWorks";
         x.ViewName = "InvitationRequest";
         x.To.Add(email);
     }));
 }
Exemplo n.º 7
0
        public MvcMailMessage SubmitValveActuatorRequest(ValveActuatorRequestViewModel model, string email)
        {
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            return(Populate(x => {
                x.Subject = "VaWorks Component Request from " + model.UserName;
                x.ViewName = "SubmitValveActuatorRequest";
                x.To.Add(email);
            }));
        }
Exemplo n.º 8
0
        public virtual MvcMailMessage Quote(Quote quote, string email)
        {
            ViewData = new System.Web.Mvc.ViewDataDictionary(quote);

            return(Populate(x =>
            {
                x.Subject = "Quote " + quote.QuoteNumber + ":" + quote.Title;
                x.ViewName = "Quote";
                x.To.Add(email);
            }));
        }
Exemplo n.º 9
0
        public MvcMailMessage QuoteUpdated(Quote quote, string email)
        {
            ViewData = new System.Web.Mvc.ViewDataDictionary(quote);

            return(Populate(x =>
            {
                x.Subject = "VaWorks Quote Update " + quote.QuoteNumber;
                x.ViewName = "QuoteUpdated";
                x.To.Add(email);
            }));
        }
Exemplo n.º 10
0
        public virtual MvcMailMessage QuoteSubmit(Quote quote, string email)
        {
            ViewData = new System.Web.Mvc.ViewDataDictionary(quote);

            return(Populate(x =>
            {
                x.Subject = "VaWorks Quote Submit " + quote.QuoteNumber;
                x.ViewName = "QuoteSubmit";
                x.To.Add(email);
                x.CC.Add("*****@*****.**");
            }));
        }
Exemplo n.º 11
0
        public virtual MvcMailMessage Welcome(ApplicationUser user)
        {
            ViewData = new System.Web.Mvc.ViewDataDictionary(user);


            return(Populate(x =>
            {
                x.Subject = "Welcome To VaWorks";
                x.ViewName = "Welcome";
                x.To.Add(user.Email);
            }));
        }
Exemplo n.º 12
0
        public virtual MailMessage Welcome(UserModel newUser)
        {
            var mailMessage = new MailMessage {
                Subject = "Welcome to Rambla!"
            };

            mailMessage.To.Add(newUser.Email);
            ViewData = new System.Web.Mvc.ViewDataDictionary(newUser);
            PopulateBody(mailMessage, viewName: "Welcome");

            return(mailMessage);
        }
Exemplo n.º 13
0
        public virtual MailMessage OwnerOrderClosed(string toEmail, otr_project.Models.OrderDetailModel orderDeatil)
        {
            var mailMessage = new MailMessage {
                Subject = "Rambla - Rental Complete"
            };

            mailMessage.To.Add(toEmail);
            ViewData = new System.Web.Mvc.ViewDataDictionary(orderDeatil);
            PopulateBody(mailMessage, viewName: "OwnerOrderClosed");

            return(mailMessage);
        }
Exemplo n.º 14
0
        public virtual MailMessage SendRenterCode(string toEmail, otr_project.Models.OrderDetailModel orderDeatil)
        {
            var mailMessage = new MailMessage {
                Subject = "Rambla Rental Security Code"
            };

            mailMessage.To.Add(toEmail);
            ViewData = new System.Web.Mvc.ViewDataDictionary(orderDeatil);
            PopulateBody(mailMessage, viewName: "SendRenterCode");

            return(mailMessage);
        }
Exemplo n.º 15
0
        public virtual MailMessage RenterReturnReminder(string toEmail, otr_project.Models.OrderDetailModel orderDeatil)
        {
            var mailMessage = new MailMessage {
                Subject = "Rambla - Return Reminder"
            };

            mailMessage.To.Add(toEmail);
            ViewData = new System.Web.Mvc.ViewDataDictionary(orderDeatil);
            PopulateBody(mailMessage, viewName: "RenterReturnReminder");

            return(mailMessage);
        }
Exemplo n.º 16
0
        protected override void SetViewData(System.Web.Mvc.ViewDataDictionary viewData)
        {
            //Here we're going to check if the viewData's model is of IPublishedContent, this is basically just a helper for
            //syntax on the front-end so we can just pass in an IPublishedContent object to partial views that inherit from
            //UmbracoTemplatePage. Then we're going to manually contruct a RenderViewModel to pass back in to SetViewData
            if (viewData.Model is IPublishedContent)
            {
                //change the model to a RenderModel and auto set the culture
                viewData.Model = new RenderModel((IPublishedContent)viewData.Model, UmbracoContext.PublishedContentRequest.Culture);
            }

            base.SetViewData(viewData);
        }
Exemplo n.º 17
0
 public virtual MvcMailMessage Invitation(Invitation invite)
 {
     ViewData = new System.Web.Mvc.ViewDataDictionary(invite);
     return(Populate(x =>
     {
         x.Subject = "VaWorks Invitation from VanAire";
         x.ViewName = "Invitation";
         x.To.Add(invite.Email);
         try {
             x.To.Add(invite.SalesPersonEmail);
         } catch { }
     }));
 }
Exemplo n.º 18
0
        public Status<bool> RequestApplication(EmailRequestApplicationModel model)
        {
            //create message
            var message = new MailMessage { Subject = model.LandlordEmail };
            message.To.Add(model.LeadEmail);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "RequestApplication");

            //send it
            return this.SendMessage(message);
        }
Exemplo n.º 19
0
        public Status<bool> Receipt(EmailOrderReceiptModel model)
        {
            //create message
            var message = new MailMessage { Subject = "Your Receipt" };
            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Receipt");

            //send it
            return this.SendMessage(message);
        }
Exemplo n.º 20
0
        public Status<bool> Register(EmailAccountRegisterModel model)
        {
            //create message
            var message = new MailMessage { Subject = "Welcome to Rentler!" };
            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Register");

            //send it
            return this.SendMessage(message);
        }
Exemplo n.º 21
0
        public Status<bool> Interested(EmailListingInterestedModel model)
        {
            //create message
            var message = new MailMessage { Subject = model.LandlordEmail };
            message.To.Add(model.LandlordEmail);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Interested");

            //send it
            return this.SendMessage(message);
        }
Exemplo n.º 22
0
        public Status<bool> ForgotPassword(EmailForgotPasswordModel model)
        {
            //create message
            var message = new MailMessage { Subject = "Your password has been reset" };
            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "ForgotPassword");

            //send it
            return this.SendMessage(message);
        }
Exemplo n.º 23
0
        public Status <bool> ForgotPassword(EmailForgotPasswordModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = "Your password has been reset"
            };

            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "ForgotPassword");

            //send it
            return(this.SendMessage(message));
        }
Exemplo n.º 24
0
        public Status <bool> Interested(EmailListingInterestedModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = model.LandlordEmail
            };

            message.To.Add(model.LandlordEmail);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Interested");

            //send it
            return(this.SendMessage(message));
        }
Exemplo n.º 25
0
        public Status <bool> Receipt(EmailOrderReceiptModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = "Your Receipt"
            };

            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Receipt");

            //send it
            return(this.SendMessage(message));
        }
Exemplo n.º 26
0
        public Status <bool> Register(EmailAccountRegisterModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = "Welcome to Rentler!"
            };

            message.To.Add(model.To);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "Register");

            //send it
            return(this.SendMessage(message));
        }
Exemplo n.º 27
0
        public Status <bool> SendApplication(EmailSendApplicationModel model)
        {
            //create message
            var message = new MailMessage {
                Subject = "Application Submitted"
            };

            message.To.Add(model.LandlordEmail);

            //create model for it
            ViewData = new System.Web.Mvc.ViewDataDictionary(model);

            //render it
            PopulateBody(message, viewName: "SendApplication");

            //send it
            return(this.SendMessage(message));
        }
Exemplo n.º 28
0
        public HtmlResult Login(LoginModel LoginModel)
        {
            var viewData = new System.Web.Mvc.ViewDataDictionary();

            viewData.Model = LoginModel;
            var Errors = ModelState.Where(x => x.Value.Errors.Count() > 0).Select(x => new { Key = x.Key, Errors = x.Value.Errors }).ToList();

            foreach (var key in Errors)
            {
                foreach (var error in key.Errors)
                {
                    viewData.ModelState.AddModelError(key.Key, error.ErrorMessage);
                }
            }
            if (!viewData.ModelState.IsValid)
            {
                return(new HtmlResult("Login", viewData));
            }

            UserDomain user = _usersService.GetUserByName(LoginModel.LoginName);

            if (user == null)
            {
                viewData.ModelState.AddModelError("UserExist", "Пользователя с таким именем не существует. Введите другое имя или выполните регистрацию.");
                return(new HtmlResult("Login", viewData));
            }
            if (user.ConnectionId.Trim() != "")
            {
                viewData.ModelState.AddModelError("UserAlredyLogin", "Пользователь с таким именем уже выполнил вход. Введите другое имя.");
                return(new HtmlResult("Login", viewData));
            }

            var model = new UserModel()
            {
                Id   = user.Id,
                Name = user.Name
            };

            viewData.Model = model;

            return(new HtmlResult("Connected", viewData));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Extends the existing ViewDataDictionary with the specified items.
        /// Example:
        /// Pass a new ViewData object to a partial view and extend it with a custom value:
        /// @Html.Partial("MyPartial", Model, ViewData.Clone().Extend(new KeyValuePair&lt;string, object&gt;("IsMobileNav", true))
        /// </summary>
        /// <param name="viewData"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        public static System.Web.Mvc.ViewDataDictionary Extend(this System.Web.Mvc.ViewDataDictionary viewData, params KeyValuePair <string, object>[] items)
        {
            if (viewData == null || items == null || !items.Any())
            {
                return(viewData);
            }

            foreach (var item in items)
            {
                if (viewData.ContainsKey(item.Key))
                {
                    // replace the existing item
                    viewData[item.Key] = item.Value;
                }
                else
                {
                    // add the new item
                    viewData.Add(item);
                }
            }

            return(viewData);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Returns the html string
        /// </summary>
        /// <typeparam name="T">Type of the object</typeparam>
        /// <param name="controller">Controller object (Ex: new HomeController())</param>
        /// <param name="viewPath">razor view location (Ex: ~/Views/Home/Home.cshtml)</param>
        /// <param name="controllerName">Controller Name (Ex: HomeController)</param>
        /// <param name="viewName">View/Action Name (Ex: Index) </param>
        /// <param name="model">object</param>
        /// <returns>returns string</returns>
        public string GenerateViewToString <T>(System.Web.Mvc.ControllerBase controller, string viewPath, string controllerName, string viewName, T model)
        {
            HttpContextBase contextBase = new HttpContextWrapper(HttpContext.Current);

            System.Web.Mvc.ViewDataDictionary _viewDataDictionary = new System.Web.Mvc.ViewDataDictionary(model);
            System.Web.Mvc.TempDataDictionary _tempDataDictionary = new System.Web.Mvc.TempDataDictionary();

            RouteData _routeData = new RouteData();

            _routeData.Values.Add("controller", controllerName);
            _routeData.Values.Add("action", viewName);

            var controllerContext = new System.Web.Mvc.ControllerContext(contextBase, _routeData, controller);
            var razorViewEngine   = new System.Web.Mvc.RazorViewEngine();
            var razorViewResult   = razorViewEngine.FindView(controllerContext, viewPath, "", false);

            var writer      = new StringWriter();
            var viewContext = new System.Web.Mvc.ViewContext(controllerContext, razorViewResult.View, _viewDataDictionary,
                                                             _tempDataDictionary, writer);

            razorViewResult.View.Render(viewContext, writer);

            return(writer.ToString());
        }
Exemplo n.º 31
0
 public HttpResponseMessage GenerateQuotationPdf(EstimationModel model)
 {
     try
     {
         var viewData = new System.Web.Mvc.ViewDataDictionary {
             { "Estimation", model }
         };
         var html   = RenderViewToString("Estimation", "~/Views/Template/TranslationEstimation.cshtml", viewData);
         var buffer = HiWork.Utils.PdfHelper.HtmlToPdf(html, "");
         var result = Request.CreateResponse(HttpStatusCode.OK);
         result.Content = new StreamContent(new MemoryStream(buffer));
         result.Content.Headers.ContentType   = new MediaTypeHeaderValue("application/pdf");
         result.Content.Headers.ContentLength = buffer.Length;
         //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
         //result.Content.Headers.ContentDisposition.FileName = "TranslationEstimation_" + DateTime.Now.ToShortDateString() + ".pdf";
         result.Content.Headers.Add("FileName", "TranslationEstimation_" + DateTime.Now.ToShortDateString() + ".pdf");
         result.Content.Headers.Add("Access-Control-Expose-Headers", "FileName");
         return(result);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Exemplo n.º 32
0
 protected override void SetViewData(System.Web.Mvc.ViewDataDictionary viewData)
 {
     base.SetViewData(viewData);
     _tData = ViewData["TData"] as TData;
 }
Exemplo n.º 33
0
 public WrapperForHtmlHelper(NewModel value)
 {
     this.ViewData = new System.Web.Mvc.ViewDataDictionary <NewModel>(value);
 }
Exemplo n.º 34
0
        public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int elementIndex, Guid elementKey, int contentId)
        {
            var preview = true;

            var content = UmbracoContext.Content.GetById(true, contentId);

            if (content == null)
            {
                _logger.Debug <ContentBlocksApiController>($"Unable to retrieve content for ID '{contentId}', it is most likely a new unsaved page.");
            }

            var element = default(IPublishedElement);
            var block   = item.ToObject <ContentBlock>();

            if (block != null && block.ElementType.Equals(Guid.Empty) == false)
            {
                if (ContentTypeCacheHelper.TryGetAlias(block.ElementType, out var alias, Services.ContentTypeService) == true)
                {
                    var contentType = UmbracoContext.PublishedSnapshot.Content.GetContentType(alias);
                    if (contentType != null && contentType.IsElement == true)
                    {
                        var properties = new List <IPublishedProperty>();

                        foreach (var thing in block.Value)
                        {
                            var propType = contentType.GetPropertyType(thing.Key);
                            if (propType != null)
                            {
                                properties.Add(new DetachedPublishedProperty(propType, null, thing.Value, preview));
                            }
                        }

                        element = _publishedModelFactory.CreateModel(new DetachedPublishedElement(block.Key, contentType, properties));
                    }
                }
            }

            var viewData = new System.Web.Mvc.ViewDataDictionary(element)
            {
                { nameof(content), content },
                { nameof(element), element },
                { nameof(elementIndex), elementIndex },
            };

            if (ContentTypeCacheHelper.TryGetIcon(content.ContentType.Alias, out var contentIcon, Services.ContentTypeService) == true)
            {
                viewData.Add(nameof(contentIcon), contentIcon);
            }

            if (ContentTypeCacheHelper.TryGetIcon(element.ContentType.Alias, out var elementIcon, Services.ContentTypeService) == true)
            {
                viewData.Add(nameof(elementIcon), elementIcon);
            }

            var markup = default(string);

            try
            {
                markup = ContentBlocksViewHelper.RenderPartial(element.ContentType.Alias, viewData);
            }
            catch (InvalidCastException icex)
            {
                // NOTE: This type of exception happens on a new (unsaved) page, when the context becomes the parent page,
                // and the preview view is strongly typed to the current page's model type.
                markup = "<p class=\"text-center mt4\">Unable to render the preview until the page has been saved.</p>";

                _logger.Error <ContentBlocksApiController>(icex, "Error rendering preview view.");
            }
            catch (Exception ex)
            {
                markup = $"<pre class=\"error\"><code>{ex}</code></pre>";

                _logger.Error <ContentBlocksApiController>(ex, "Error rendering preview view.");
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new { elementKey, markup }));
        }