Wednesday, August 5, 2020

CROSS APPLY + SPLIT STRING

create table #temp (ID int, Brands varchar(500))

insert into #temp (ID, Brands) values  (1,'FORD,CHEVROLET')
insert into #temp (ID, Brands) values  (2,'FIAT, VW,PEUGEOT')
insert into #temp (ID, Brands) values  (3,'FERRARI')

select ID, LTRIM(rtrim(value)) as Brand 
from #temp
CROSS APPLY STRING_SPLIT(Brands, ',');  

Friday, May 29, 2020

Recibir array por POST

var info = { "EvaluationTypeID": $scope.record.EvaluationTypeID, Users: [] };
            angular.forEach($scope.selectedUsers, function (r) {
                info.Users.push(r.UserID);
            });

            $http({ method: "POST", url: "Act/Evaluation/GenerateEvaluation", data: info }).then(function (detail) {


public HttpResponseMessage GenerateEvaluation(dynamic data)
        {
         string EvaluationTypeID = data.EvaluationTypeID;
            string[] users = data.Users.ToObject<string[]>();

Friday, April 10, 2020

AngularJS PUT

$resource('/Api/Parameter/:id', null, { 'update': { method: 'PUT' } }).update({ 'id': $scope.record.ParameterID }, $scope.record,
            function () {
                $scope.status = "Updated";
           
            }, function () { alert("Error") });

Tuesday, March 3, 2020

Cast JSON a un objeto de una clase

Process process = Newtonsoft.Json.JsonConvert.DeserializeObject<Process>(json);


var json = JsonConvert.SerializeObject(maintenanceTask.OriginalValues, Formatting.Indented);
var currentMaintenanceTask = Newtonsoft.Json.JsonConvert.DeserializeObject<MaintenanceTask>(json);

Friday, February 20, 2015

AngularJS Reusing by overriding and extending.

I always try to write reusable code and I found in Angular JS how to do it
Maybe this is not elegant or recommend but it works .. !

This is my simple example:

The controller calls a factory that receives the $scope as parameter.
The factory adds to the $scope values and functions that can be used directly in the view or by the controller:
sets: value1 and value2 default value.
defines; action1, action3 and action4 functions
action4  checks if exists onAction4 that extends its default behavior.

Then in the controller:
action2 is defined
action3 is redefined (overridden)
onAction4 is defined to extend action4 defaults behavior.


Note in this implementation is not necessary to define
 $scope.action2 = function(){commonBehavior.action2();} because action2 was added to the current scope by addToScope


You can see it working here in Plunker


var app = angular.module('app', ['commonBehavior']);

angular.module('commonBehavior', [])
.factory('commonBehavior', function () {
    var ext = {};
    ext.addToScope = function ($scope) {
        $scope.value1 = "Common Behavior Value 1";
        $scope.value2 = "Common Behavior Value 2";

        $scope.action1 = function () {
            $scope.value1 = "action1";
        }
        $scope.action3 = function () {
            $scope.value1 = "action3 commonBehavior";
        }

        $scope.action4 = function () {
            $scope.value1 = "action4 commonBehavior";

            if ($scope.onAction4 != undefined) //  if it is defined in the controller execute it.
                $scope.onAction4();
        }

    }
    return ext;
});

app.controller("myCtrl", ['$scope', 'commonBehavior', function ($scope, commonBehavior) {
    commonBehavior.addToScope($scope); // sets the scope
    $scope.value2 = "overridden Value 2"; //override default value

    $scope.action2 = function () {
        $scope.value1 = "action2";
    }

    $scope.action3 = function () { //function overriden
        $scope.value1 = "action3 overridden";
    }
    $scope.onAction4 = function () { //susbcribed to the event
        $scope.value2 = "onAction4";
    }
}
]);

Tuesday, July 16, 2013

Clausula in de SQL en LINQ

Podemos hacer: var paises ="Argentina, Uruguay, Colombia"; var listaFiltrada = from l in lista where paises.Split(',').contains(l.pais) select l;