Tuesday, October 31, 2017

Join Query Multiple Tables Order by descending Order

var year = (from ep in _adminContext.table1
                    join e in _adminContext.table2 on ep.idequals e.id
                    join t in _adminContext.table3 on e.idequals t.id
                    orderby t.Date descending
                    where t.status == "A"
                    select new
                    {
                        id= ep.id

                    }).FirstOrDefault();

asynchronous option to be false

the asynchronous choice to be false to induce a synchronous Ajax request. Then your asking will set some information before your Main perform return.
Here's what your code would seem like if modified as suggested:

beforecreate: function (node, targetNode, type, to) {
    jQuery.ajax({
            url: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value),
            success: function (result) {
            if (result.isOk == false
                 alert(result.message);
            },
            async: false
         });
}
<script>
    // ...
    $.ajax(... async: false ...); // Hey browser! first complete this request,
                                  // then go for other codes

    $.ajax(...); // Executed after the completion of the previous async:false request.

</script>

Difference between Managed and unmanaged code


Managed code - Executed by the CLR instead of being executed by the operating system.

Unmanaged code - Executed directly by the operating system(OS) and not by the CLR

Adding an existing project to GitHub using the command line

How to Add project to git hub
1) Create new repository Copy Repository Url

2) Open ur project in Visual Studio
3) type: git init
git add *
ls

And Execte git hub generated commands

Build Connection String Dynamically

Entities _context = (Entities)HttpContext.Current.Session[SessionNames.xContext];
using WebSession = System.Web.HttpContext;

#region Build Connection String Dynamically
        public string BuildConnectionString(string dataSource, string database, string userId, string password)
        {
           //  string connect = BuildConnectionString(dataSource, custDbName, dbUserId, dbUserPassword);
            EntityConnectionStringBuilder retval = new EntityConnectionStringBuilder();
            //// Build the connection string from the provided datasource and database
            try
            {

                SqlConnectionStringBuilder sqlBuilder =
                    new SqlConnectionStringBuilder
                    {
                        DataSource = "x.x.x.x",
                        InitialCatalog = "xTemplate",
                        UserID = "x",
                        Password = "x",
                        IntegratedSecurity = false,
                        MultipleActiveResultSets = true
                    };


                retval = new EntityConnectionStringBuilder
                {
                    Metadata = "res://*/x.Client.csdl|res://*/x.Client.ssdl|res://*/x.Client.msl",
                    Provider = "System.Data.SqlClient",
                    ProviderConnectionString = sqlBuilder.ToString()
                };
                BuildDatabaseContext(retval.ToString());

            }
            catch (Exception e)
            {
               
                    throw;
            }
            return retval.ToString();
        }
        public void BuildDatabaseContext(string connectionString)
        {
            try
            {
                StoreContext(connectionString);
            }
            catch (Exception e)
            {
                    throw;
            }
        }
        public void StoreContext(string connect)
        {
            try
            {
                Entities context = new Entities(connect);
                WebSession.Current.Session[SessionNames.xContext] = context;
            }
            catch (Exception e)
            {
               
                    throw;
             }
        }

        #endregion

Thursday, October 12, 2017

* operator has higher precedence than +

// The * operator has higher precedence than + so this expression evaluates to 7:

1 + 2 * 3

// (See book for operator precedence table)

// T4 code generation is enabled for model 'c:\users\scala\documents\visual studio 2013\Projects\entityFramework\entityFramework\EntityModel.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. // If no context and entity classes have been generated, it may be because you created an empty model but // have not yet chosen which version of Entity Framework to use. To generate a context class and entity // classes for your model, open the model in the designer, right-click on the designer surface, and // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation // Item...'

To generate a context class and entity classes for your model, open the model in the designer, right-click on the designer surface, and select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation Item...'.
'Add Code Generation Item...' will do the trick. You should basically choose and add one or more T4 templates to actually generate the entities. More info here. Also take a look at this answer. It might help to make things clear.

browser close event

Trying to detect browser close event
------------------------------------------
window.onbeforeunload = function (event) {
    var message = 'Important: Please click on \'Save\' button to leave this page.';
    if (typeof event == 'undefined') {
        event = window.event;
    }
    if (event) {
        event.returnValue = message;
    }
    return message;
};

$(function () {
    $("a").not('#lnkLogOut').click(function () {
        window.onbeforeunload = null;
    });
    $(".btn").click(function () {
        window.onbeforeunload = null;
});
});
================================================
How to capture the browser window close event?
----------------------------
var inFormOrLink;
$('a').on('click', function() { inFormOrLink = true; });
$('form').on('submit', function() { inFormOrLink = true; });

$(window).on("beforeunload", function() {
    return inFormOrLink ? "Do you really want to close?" : null;
})
For jQuery versions older than 1.7, try this:

var inFormOrLink;
$('a').live('click', function() { inFormOrLink = true; });
$('form').bind('submit', function() { inFormOrLink = true; });

$(window).bind("beforeunload", function() {
    return inFormOrLink ? "Do you really want to close?" : null;
})

Request.QueryString in view

 if ('@string.IsNullOrEmpty(Request.QueryString["sprtPlan"])'=='False') {
                $('#ChangePlan').toggle();//toggle based on request query string
        }