Ejemplo n.º 1
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            var shopifyContext = _themeAdaptor.WorkContext.ToShopifyModel(_themeAdaptor.UrlBuilder);

            //Set current template
            shopifyContext.Template = _viewName;

            var formErrors = new FormErrors(viewContext.ViewData.ModelState);

            if (shopifyContext.Form == null)
            {
                //Set single Form object with errors for shopify compilance
                shopifyContext.Form = new Form();
                shopifyContext.Form.PostedSuccessfully = !String.Equals(viewContext.HttpContext.Request.HttpMethod, "GET", StringComparison.InvariantCultureIgnoreCase);
                if (formErrors.Any())
                {
                    shopifyContext.Form.Errors             = formErrors;
                    shopifyContext.Form.PostedSuccessfully = false;
                }
            }

            // Copy data from the view context over to DotLiquid
            var parameters = shopifyContext.ToLiquid() as Dictionary <string, object>;

            //Add settings to context
            parameters.Add("settings", _themeAdaptor.GetSettings());

            foreach (var item in viewContext.ViewData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }
            foreach (var item in viewContext.TempData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }

            var    viewTemplate   = _themeAdaptor.RenderTemplateByName(_viewName, parameters);
            var    masterViewName = _masterViewName;
            object layoutFromTemplate;

            if (parameters.TryGetValue("layout", out layoutFromTemplate))
            {
                masterViewName = layoutFromTemplate.ToString();
            }
            //if layout specified need render with master page
            if (!String.IsNullOrEmpty(masterViewName))
            {
                //add special placeholder 'content_for_layout' to content it will be replaced in master page by main content
                parameters.Add("content_for_layout", viewTemplate);
                viewTemplate = _themeAdaptor.RenderTemplateByName(masterViewName, parameters);
            }
            writer.Write(viewTemplate);
        }
 public bool checkIfValidDuration()//returns true if duration is bigger than 0
 {
     if (Duration > 0)
     {
         return(true);
     }
     FormErrors.Add("Duration must be a positive integer bigger than 0!\n");
     return(false);
 }
 public bool checkIfValidPhoneNumber()//returns true if phone number is in correct format
 {
     if (Regex.IsMatch(PhoneNumber, @"[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]"))
     {
         return(true);
     }
     FormErrors.Add("Phone Number must be in vald Format! XXX-XXX-XXXX\n");
     return(false);
 }
 public bool checkIfValidEmail()//returns true if email entered is in correct format
 {
     if (Regex.IsMatch(Email, @".+@.+.com"))
     {
         return(true);
     }
     FormErrors.Add("Email must be in Valid Format! {...}@{...}.com\n");
     return(false);
 }
 public bool checkIfAllPropertiesEntered()                                  //returns true if all fields are non-empty
 {
     if (this.GetType().GetProperties().All(p => p.GetValue(this) != null)) //uses lambda expression to ensure all properties are not null
     {
         return(true);
     }
     FormErrors.Add("Please enter all required Fields!\n");
     return(false);
 }
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
                throw new ArgumentNullException("viewContext");

            var shopifyContext = _themeAdaptor.WorkContext.ToShopifyModel(_themeAdaptor.UrlBuilder);
            //Set current template
            shopifyContext.Template = _viewName;

            var formErrors = new FormErrors(viewContext.ViewData.ModelState);
            if (shopifyContext.Form == null)
            {
                //Set single Form object with errors for shopify compilance
                shopifyContext.Form = new Form();
                shopifyContext.Form.PostedSuccessfully = !String.Equals(viewContext.HttpContext.Request.HttpMethod, "GET", StringComparison.InvariantCultureIgnoreCase);
                if (formErrors.Any())
                {
                    shopifyContext.Form.Errors = formErrors;
                    shopifyContext.Form.PostedSuccessfully = false;
                }
            }

            // Copy data from the view context over to DotLiquid
            var parameters = shopifyContext.ToLiquid() as Dictionary<string, object>;

            //Add settings to context
            parameters.Add("settings", _themeAdaptor.GetSettings());

            foreach (var item in viewContext.ViewData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }
            foreach (var item in viewContext.TempData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }

            var viewTemplate = _themeAdaptor.RenderTemplateByName(_viewName, parameters);
            var masterViewName = _masterViewName;
            object layoutFromTemplate;
            if (parameters.TryGetValue("layout", out layoutFromTemplate))
            {
                masterViewName = layoutFromTemplate.ToString();
            }
            //if layout specified need render with master page
            if (!String.IsNullOrEmpty(masterViewName))
            {
                //add special placeholder 'content_for_layout' to content it will be replaced in master page by main content
                parameters.Add("content_for_layout", viewTemplate);
                viewTemplate = _themeAdaptor.RenderTemplateByName(masterViewName, parameters);
            }
            writer.Write(viewTemplate);

        }
Ejemplo n.º 7
0
        public FormMainUi()
        {
            InitializeComponent();

            _formOpenFile      = new FormOpenFile(this);
            _formConvolution   = new FormConvolution(this);
            _formAlgorithmCode = new FormAlgorithmCode(this);
            _formErrors        = new FormErrors(this);
            FormDialog         = new FormDialog(this);

            _zedGraphPainting = new ZedGraphPainting(ZedGraphResult, richTextBoxIncoming)
            {
                IsDeptActive = checkBoxHaveDept.Checked,
            };
        }
Ejemplo n.º 8
0
        public Task RenderAsync(ViewContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var shopifyContext = _workContextAccessor.WorkContext.ToShopifyModel(_urlBuilder);

            //Set current template
            shopifyContext.Template = _viewName;

            var formErrors = new FormErrors(context.ViewData.ModelState);

            if (shopifyContext.Form == null)
            {
                //Set single Form object with errors for shopify compilance
                shopifyContext.Form = new Form();
            }
            shopifyContext.Form.PostedSuccessfully = !string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.InvariantCultureIgnoreCase);
            if (formErrors.Any())
            {
                shopifyContext.Form.Errors             = formErrors;
                shopifyContext.Form.PostedSuccessfully = false;
            }

            //EU General Data Protection Regulation (GDPR) support
            var consentFeature = context.HttpContext.Features.Get <ITrackingConsentFeature>();

            if (consentFeature != null)
            {
                shopifyContext.CanTrack      = !consentFeature?.CanTrack ?? false;
                shopifyContext.ConsentCookie = consentFeature?.CreateConsentCookie();
            }

            // Copy data from the view context over to DotLiquid
            var parameters = shopifyContext.ToLiquid() as Dictionary <string, object>;

            //Add settings to context
            parameters.Add("settings", _liquidThemeEngine.GetSettings());

            foreach (var item in context.ViewData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }
            foreach (var item in context.TempData)
            {
                parameters.Add(Template.NamingConvention.GetMemberName(item.Key), item.Value);
            }

            if (!parameters.ContainsKey("error_message") && !string.IsNullOrEmpty(_workContextAccessor.WorkContext.ErrorMessage))
            {
                parameters.Add("error_message", _workContextAccessor.WorkContext.ErrorMessage);
            }

            var viewTemplate = _liquidThemeEngine.RenderTemplateByName(_viewName, parameters);

            // don't use layouts for partial views when masterViewName is not specified
            if (_isMainPage)
            {
                var masterViewName = "theme";
                if (parameters.TryGetValue("layout", out object layoutFromTemplate))
                {
                    if (layoutFromTemplate != null && !string.IsNullOrEmpty(layoutFromTemplate.ToString()))
                    {
                        masterViewName = layoutFromTemplate.ToString();
                    }
                }
                var headerTemplate = _liquidThemeEngine.RenderTemplateByName("content_header", parameters);

                //add special placeholder 'content_for_layout' to content it will be replaced in master page by main content
                parameters.Add("content_for_layout", viewTemplate);
                parameters.Add("content_for_header", headerTemplate);

                try
                {
                    viewTemplate = _liquidThemeEngine.RenderTemplateByName(masterViewName, parameters);
                }
                catch (FileSystemException ex)
                {
                    var message = ex.Message.Replace("<br/>", "\r\n");
                    throw new InvalidOperationException(message);
                }
            }
            context.Writer.Write(viewTemplate);
            return(Task.FromResult(0));
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            var errors = new FormErrors();

            foreach (string entry in Request.Form.Keys)
            {
                var value = Request.Form[entry];

                if (string.IsNullOrEmpty(value))
                {
                    errors.messages[entry] = "Value is missing";
                    errors.Add(entry);
                }
            }

            var form = new Form();

            if (errors.Count != 0)
            {
                form.posted_successfully = false;
                form.errors = errors;
            }
            else
            {
                form.posted_successfully = true;
            }

            TempData["form"] = form;

            var storeOwner = MASTERdomain.organisation.users.First();
            var formType   = Request.Form["form_type"];
            var email      = Request.Form["email"];

            if (!string.IsNullOrEmpty(formType) &&
                formType == "customer")
            {
                // add contact to contact list
                // check if email exists
                var usr = repository.GetUsersByEmail(email, subdomainid.Value).SingleOrDefault();
                if (usr == null)
                {
                    // create org
                    var org = new organisation
                    {
                        name      = email,
                        subdomain = subdomainid.Value
                    };

                    var orgid = repository.AddOrganisation(org);

                    // create user
                    usr = new user
                    {
                        role         = (int)UserRole.USER,
                        email        = email,
                        viewid       = Crypto.Utility.GetRandomString(),
                        permissions  = (int)UserPermission.USER,
                        organisation = orgid
                    };
                    repository.AddUser(usr);
                }

                // add to contact group
                if (!string.IsNullOrEmpty(Request.Form["group"]))
                {
                    var group = MASTERdomain.contactGroups.Where(x => x.title == Request.Form["group"]).SingleOrDefault();
                    if (group == null)
                    {
                        group = new contactGroup()
                        {
                            title = Request.Form["group"]
                        };
                        MASTERdomain.contactGroups.Add(group);
                    }

                    if (group.contactGroupMembers.AsQueryable().Where(x => x.userid == usr.id).SingleOrDefault() == null)
                    {
                        group.contactGroupMembers.Add(new contactGroupMember
                        {
                            userid = usr.id
                        });
                    }
                }
                repository.Save();
            }
            else
            {
                //  send notification email to store owner
                var viewdata = new NewMessage
                {
                    name    = Request.Form["name"],
                    email   = email,
                    message = Request.Form["body"].ToHtmlBreak()
                };

                this.SendEmail(EmailViewType.STORE_NEWMESSAGE, viewdata, "New Store Message", storeOwner.GetEmailAddress(), storeOwner.ToFullName(), null);
            }

            return(Redirect(Request.UrlReferrer.ToString()));
        }