Monday, May 27, 2013

Javascript: Converting .NET DateTime to Javascript Date Object

User this:

var jsonDate = jqueryCall();  // returns "/Date(1245398693390)/"; 
var re = /-?\d+/; 
var m = re.exec(jsonDate); 
var d = new Date(parseInt(m[0]));

Resource:
http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json

MomentJS: convert from javasript date object to formated String

var myDateObject = new Date();
var myMomentJSFormat = "DD/MM/YYYY hh:mm";
        var myMomentObject = moment(myDateObject);
        // formated using moment.js
        var myMomentObjectFormated = myMomentObject.format(myMomentJSFormat);

Resources:
http://momentjs.com/docs/#/displaying/format/


JPA: handling date, time and timestamp

Here is a great article about handling date, time and timestamp

http://www.developerscrappad.com/228/java/java-ee/ejb3-jpa-dealing-with-date-time-and-timestamp/

Thursday, May 23, 2013

Entity Framework: ono to one relation


Example:

public class User
{
    public int UserId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }      
    public int BillingAddressId { get; set; }

    public Address BillingAddress { get; set; }

}

public class Address
{
    public int AddressId { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public string PostalCode { get; set; }
}

// one user one billing adress
modelBuilder.Entity<User>()
                .HasRequired(a => a.BillingAddress)
                .WithMany()
                .HasForeignKey(u => u.BillingAddressId);

Note: this is not going to generate the unique constraint in the db on  BillingAddressId field

Reference:
http://weblogs.asp.net/manavi/archive/2011/01/23/associations-in-ef-code-first-ctp5-part-3-one-to-one-foreign-key-associations.aspx

NetBeans: RestFul Web Services Tutorial

JPA: Many to one relation

Here is a simple example of a Many to one relation using JPA:

http://ayushsuman.blogspot.com/2010/06/jpa-one-to-many-and-many-to-one.html

Tuesday, May 21, 2013