从后面的代码调用业务逻辑层

时间:2015-04-21 08:55:21

标签: javascript c# asp.net ajax

我有一个页面,我想将值传递给服务(已经设置)并检索 jobid 。作为asp.net/javascript/ajax等的新手,以及我曾经问过的以前的新手问题,我只是想检查一下我的方式是否正确。以下代码有效,但它是最好的做事方式吗? (这只是一个显示逻辑的测试页面)

非常感谢任何建议

Test.aspx文件

<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">

        function submitJob() {
            var propID = $get("textBox1").value;
            var dateReceived = $get("textBox2").value;
            var csJobTypeID = $get("textBox3").value;
            var notes = $get("textBox4").value;

            PageMethods.SubmitForm(propID, dateReceived, csJobTypeID, notes, fnsuccesscallback, fnerrorcallback);

        }

        function fnsuccesscallback(data) {
            $get("textBox5").value = data;

        }
        function fnerrorcallback(result) {
            alert(result.statusText);
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
    <div>
        <asp:TextBox id="textBox1" runat="server">D2BAC8B9-DB94-E411-AE6D-00505696BEC2</asp:TextBox>
        <asp:TextBox id="textBox2" runat="server">2015-04-20T12:00:00</asp:TextBox>
        <asp:TextBox id="textBox3" runat="server">{4F1B4C1C-7179-E411-A36F-005056966B32}</asp:TextBox>
        <asp:TextBox id="textBox4" runat="server">These are the notes</asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="textBox5" runat="server" name="textBox5" ></asp:TextBox>
        <br />
        <br />
        <button id="btnTest" type="button" onclick="submitJob();">Test</button>
    </div>
    </form>
</body>

test.aspx.cs

    public partial class test : System.Web.UI.Page
    {

        [WebMethod]
        public static string SubmitForm(Guid propID, DateTime dateReceived, string csJobType, string notes)
        {

            Guid newJobID = NewJobBLL.NewJobID(propID, dateReceived, csJobType, notes);

            return newJobID.ToString();
        }

    }
}

NewJobBLL.cs

   public class NewJobBLL
    {

        public static Guid NewJobID(Guid propID, DateTime dateReceived, string csJobTypeID, string notes)
        {

            Job job = new Job() {
            LocationId = propID,
            DateReceived = dateReceived,
            ContractSpecificJobtypeID = csJobTypeID,
            Description = notes
        };

            CrmServiceHelper.SetUp(Utility.Enums.System.SystemEnvironment.Staging);

            ServiceResponseData<Job> response = CrmServiceHelper.JobService.InsertJob(job);


            if (response.CallSuccess)
            { 
                JobID = response.Data.JobCrmID;
            }

            return JobID;

        }

        public static Guid JobID
        {
            get;
            set;
        }


    }

0 个答案:

没有答案