Click here to Skip to main content
15,886,689 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 2 – Southwind Logic

Rate me:
Please Sign up or sign in to vote.
4.45/5 (6 votes)
15 Nov 2012LGPL325 min read 31.3K   1K   22  
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using System.Web.Mvc;

namespace Signum.Web
{
    public class JsViewOptions : JsRenderer
    {
        public JsValue<string> Prefix { get; set; }
        public JsValue<string> ContainerDiv { get; set; }
        public JsValue<string> ControllerUrl { get; set; }
        public JsValidatorOptions ValidationOptions { get; set; }
        public JsFunction OnOk { get; set; }
        public JsFunction OnOkClosed { get; set; }
        public JsFunction OnCancelled { get; set; }
        public JsValue<string> Type { get; set; }
        public JsValue<int?> Id { get; set; }
        public JsValue<string> PartialViewName { get; set; }
        public JsInstruction RequestExtraJsonData { get; set; }

        public JsViewOptions()
        {
            Renderer = () =>
            {
                return new JsOptionsBuilder(false)
                {
                    {"prefix", Prefix.TryCC(a=>a.ToJS())},
                    {"containerDiv", ContainerDiv.TryCC(a=>a.ToJS())},
                    {"controllerUrl", ControllerUrl.TryCC(a=>a.ToJS()) ?? RouteHelper.New().SignumAction("PopupView").SingleQuote()},
                    {"validationOptions", ValidationOptions.TryCC(a => a.ToJS()) },
                    {"onOk", OnOk.TryCC(a=>a.ToJS())},
                    {"onOkClosed", OnOkClosed.TryCC(a=>a.ToJS())},
                    {"onCancelled", OnCancelled.TryCC(a=>a.ToJS())},
                    {"type", Type.TryCC(a=>a.ToJS())},
                    {"partialViewName", PartialViewName.TryCC(a=>a.ToJS())},
                    {"requestExtraJsonData", RequestExtraJsonData.TryCC(a=>a.ToJS())},
                }.ToJS();
            };
        }
    }

    public class JsViewNavigator : JsInstruction
    {
        JsViewOptions Options { get; set; }

        public JsViewNavigator(JsViewOptions options)
            : base(() => "new SF.ViewNavigator(" + options.ToJS() + ")")
        {
            this.Options = options;
        }

        public JsInstruction viewOk()
        {
            return new JsInstruction(() => "{0}.viewOk()".Formato(this.ToJS()));
        }

        public JsInstruction createOk()
        {
            return new JsInstruction(() => "{0}.createOk()".Formato(this.ToJS()));
        }

        public JsInstruction viewSave(JsValue<string> html)
        {
            return new JsInstruction(() => "{0}.viewSave({1})".Formato(this.ToJS(), html.ToJS()));
        }

        public JsInstruction createSave(string saveUrl)
        {
            return new JsInstruction(() => "{0}.createSave('{1}')".Formato(this.ToJS(), saveUrl));
        }

        public static JsInstruction closePopup(string prefix)
        {
            return new JsInstruction(() => "SF.closePopup('{0}')".Formato(prefix));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions