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
        }

A network-related or instance-specific error occurred whereas establishing an association with SQL Server. The server wasn't found or wasn't accessible. Verify that the instance name is correct which SQL Server is organized to permit remote connections. (provider: SQL Network Interfaces, error: twenty-six — Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

TITLE: Connect to Server
------------------------------
Cannot connect to \SQLEXPRESS.
------------------------------
ADDITIONAL INFORMATION:

A network-related or instance-specific error occurred whereas establishing a affiliation to SQL Server.
The server wasn't found or wasn't accessible.
Verify that the instance name is correct which SQL Server is organized to permit remote connections.
(provider: SQL Network Interfaces, error: twenty six - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft SQL Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
Solution : Type Start-- Sql Server Configuration Manager run as Admin...(Sql Configuration Manager)
under Sql services -- Start Sql Server

fonts/opensans-light-webfont.woff2 errors in console

fonts/opensans-light-webfont.woff2 errors in console
<system.webServer>

         <staticContent>
      <remove fileExtension=".woff" />
         <!-- In case IIS already has this mime type -->
         <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
         <remove fileExtension=".woff2" />
         <!-- In case IIS already has this mime type -->
         <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
       </staticContent>
   

  </system.webServer>

Failed to load resource: the server responded with a status of 404 (Not Found) Uncaught ReferenceError: jQuery is not defined

Failed to load resource: the server responded with a standing of 404 (Not Found) /socket.io/socket.io.js

Uncaught ReferenceError: jQuery is not defined
Solution:
replace
jQuery(function($){
with
$(document).ready(function($)


The configuration section 'log4net' cannot be read because it is missing a section declaration

 The configuration section 'log4net' cannot be read because it is missing a section declaration
Solution: inside <configSections>---Add

 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

increase the json size limit

Add In Web.config..

<add key="aspnet:MaxJsonDeserializerMembers" value="200000"/> 

Use Object initializer

The second contains less characters and then is a lot of compact to browseyou do not have to be compelled torepeat myClass two a lot of times, and therefore the formatting logic is in one block.

It is extremely a syntactical sugar that does not modification a factor within the generated code. If you does not love ityou'll be able to forever disable the warning on ReSharper.

A longer post on the benefits of exploitation Object Initializers here:

Helper.! How to use Helpers?

Creating and Using a Helper in an ASP.NET Web Pages (Razor) Site
This article describes how to create a helper in an ASP.NET Web Pages (Razor) website. A helper is a reusable component that includes code and markup to perform a task that might be tedious or complex.
What you'll learn:
·         How to create and use a simple helper.
These are the ASP.NET features introduced in the article:
·         The @helper syntax.
Software versions used in the tutorial
·         ASP.NET Web Pages (Razor) 3
This tutorial also works with ASP.NET Web Pages 2.
Overview of Helpers
If you need to perform the same tasks on different pages in your site, you can use a helper. ASP.NET Web Pages includes a number of helpers, and there are many more that you can download and install. (A list of the built-in helpers in ASP.NET Web Pages is listed in the) If none of the existing helpers meet your needs, you can create your own helper.
A helper lets you use a common block of code across multiple pages. Suppose that in your page you often want to create a note item that's set apart from normal paragraphs. Perhaps the note is created as a <div> element that's styled as a box with a border. Rather than add this same markup to a page every time you want to display a note, you can package the markup as a helper. You can then insert the note with a single line of code anywhere you need it.
Using a helper like this makes the code in each of your pages simpler and easier to read. It also makes it easier to maintain your site, because if you need to change how the notes look, you can change the markup in one place.
Creating a Helper
This procedure shows you how to create the helper that creates the note, as just described. This is a simple example, but the custom helper can include any markup and ASP.NET code that you need.
1.      In the root folder of the website, create a folder named App_Code. This is a reserved folder name in ASP.NET where you can put code for components like helpers.
2.      In the App_Code folder create a new .cshtml file and name it MyHelpers.cshtml.
3.      Replace the existing content with the following:
cshtmlCopy
@helper MakeNote(string content) {
  <div class="note"
       style="border: 1px solid black; width: 90%; padding: 5px; margin-left: 15px;">
    <p>
      <strong>Note</strong>&nbsp;&nbsp; @content
    </p>
  </div>
}
The code uses the @helper syntax to declare a new helper named MakeNote. This particular helper lets you pass a parameter named content that can contain a combination of text and markup. The helper inserts the string into the note body using the @content variable.
Notice that the file is named MyHelpers.cshtml, but the helper is named MakeNote. You can put multiple custom helpers into a single file.
4.      Save and close the file.
Using the Helper in a Page
1.      In the root folder, create a new blank file called TestHelper.cshtml.
2.      Add the following code to the file:
htmlCopy
<!DOCTYPE html>
  <head>
    <title>Test Helpers Page</title>
  </head>
  <body>
    <p>This is some opening paragraph text.</p>

    <!-- Insert the call to your note helper here. -->
    @MyHelpers.MakeNote("My test note content.")

    <p>This is some following text.</p>
  </body>
</html>
To call the helper you created, use @ followed by the file name where the helper is, a dot, and then the helper name. (If you had multiple folders in the App_Code folder, you could use the syntax @FolderName.FileName.HelperName to call your helper within any nested folder level). The text that you add in quotation marks within the parentheses is the text that the helper will display as part of the note in the web page.