Thursday, 22 January 2015

Check whether one list contain another list value in LINQ


var CheckExist = List1.Any(l1 => List2.Any(l2 => l1.Name == l2.Name));


Here CheckExist  object will return true if any record of List1 contain in List2

Sunday, 28 December 2014

Formatting date in Linq-to-Entities query causes exception

invoices.Select(i => new 
{
    FormattedDate = (     EntityFunctions.Right(String.Concat(" ", SqlFunctions.StringConvert((double?) SqlFunctions.DatePart("dd", i.DocumentDate))), 2)
                        + "/"
                        + EntityFunctions.Right(String.Concat(" ",SqlFunctions.StringConvert((double?) SqlFunctions.DatePart("mm", i.DocumentDate))), 2)
                        + "/"
                        + EntityFunctions.Right(SqlFunctions.StringConvert((double?) SqlFunctions.DatePart("yyyy", i.DocumentDate)), 4)
                       ).Replace(" ", "0")
}

Friday, 27 June 2014

Convert returned JSON Object Properties to (lower first) camelCase

I have JSON returned from an API like so:
Contacts: [{ GivenName: "Matt", FamilyName:"Berry" }]
To keep this consitent with my code style (camelCase - lower case first letter) I want to transform the array to produce the following:
 contacts: [{ givenName: "Matt", familyName:"Berry" }]
Whats the easiest/best way to do this? create a new Contact object and iterate over all the conatacts in the returned array?


I needed a generic method that accepted an array or object. This is what I'm using (I borrowed KyorCode's firstToLower() implementation):


function convertKeysToCamelCase(obj) {
    if (!obj || typeof obj !== "object") return null;

    if (obj instanceof Array) {
        return $.map(obj, function(value) {
            return convertKeysToCamelCase(value);
        });
    }

    var newObj = {};
    $.each(obj, function(key, value) {
        key = key.charAt(0).toLowerCase() + key.slice(1);
        newObj[key] = value;
    });

    return newObj;
};
Example calls:
var contact = { GivenName: "Matt", FamilyName:"Berry" };

console.log(convertKeysToCamelCase(contact));
// logs: Object { givenName="Matt", familyName="Berry"}

console.log(convertKeysToCamelCase([contact]));
// logs: [Object { givenName="Matt", familyName="Berry"}]

console.log(convertKeysToCamelCase("string"));
// logs: null

console.log(contact);
// logs: Object { GivenName="Matt", FamilyName="Berry"}
 

Thursday, 22 May 2014

Give custom validation message in HTML5

Custom Message in HTML5

Generally if you are just giving required in input it will give its own validation message in html5. But if you want to give your custom message then do this.

<input id="UserID" type="text" required="required" oninvalid="this.setCustomValidity('Witinnovation')">

Thursday, 17 April 2014

Get added and deleted items from array

This one is only for int array Here i am going to show how to get value of add and deleted items from defined array.


        var oldbrd = $scope.selectedDiagnosis.sort();
        var newbrd = $scope.RefferalView.Diagnosis.sort();

        var additem = [];
        var deleteitem = [];
        //var index;

        angular.forEach(oldbrd, function (value) {
            if (newbrd.indexOf(value) == -1) {
                deleteitem.push(value);
            }
        });

        angular.forEach(newbrd, function (value) {
            if (oldbrd.indexOf(value) == -1) {
                additem.push(value);
            }
        });

        $scope.AddedDiagnosisCode = additem;
        $scope.DeletedDiagnosisCode = deleteitem;
        alert('added =>: ' + additem + "_________" + 'deleted =>: ' + deleteitem);

Tuesday, 19 November 2013

Custom Column Filter only with a single textbox on each column without any operators and buttons.







Here i find custom search functionality for KendoUI grid. Hope you really find helpfull.

HTML
<link href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.rtl.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.dataviz.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.dataviz.default.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.3.1114/js/kendo.all.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div id="grid"></div>
</body>
</html>
 

JavaScript
  dataSource:[ {
      foo: "Foo 1",
      bar: "Bar 1"
    } , {
      foo: "Foo 2",
      bar: "Bar 2"
    }
  ]
});

var grid = $("#grid").data("kendoGrid");

$("<tr><th class='k-header' data-field='foo'><input /></th><th data-field='bar' class='k-header' ><input /></th></tr>").appendTo($("#grid thead")).find("input").keyup(function() {
 
  grid.dataSource.filter({
    operator: "contains",
    value: $(this).val(),
    field: $(this).parent("th").data("field")
  });
 
});


http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/grid/custom-column-filter-only-with-a-single-textbox-on-each-column-without-any-operators-and-buttons.aspx


Another link is

http://jsbin.com/ihanun/1/edit

Wednesday, 13 November 2013