Javascript function to convert a json date into more readable format to user.
// Converts a date received in JSON data from the server in format "\Date(1234567890123)\" to a short
// date string in format MM/dd/yyyy.
function ConvertJsonDateString(jsonDate) {
var shortDate = null;
if (jsonDate) {
var regex = /-?\d+/;
var matches = regex.exec(jsonDate);
var dt = new Date(parseInt(matches[0]));
var month = dt.getMonth() + 1;
var monthString = month > 9 ? month : '0' + month;
var day = dt.getDate();
var dayString = day > 9 ? day : '0' + day;
var year = dt.getFullYear();
shortDate = monthString + '/' + dayString + '/' + year;
}
return shortDate;
};
namespace MVPProject
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IWcfService" in both code and config file together.
[ServiceContract(Namespace="MVPProject")]
public interface IWcfService
{
[OperationContract]
void DoWork();
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
List GetUserDetails();
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
List GetSearchUserDetails(string search);
}
}
WcfService.svc.cs Page
namespace MVPProject
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WcfService" in code, svc and config file together.
public class WcfService : IWcfService, IViewUserData
{
#region Declaration
PresenterUserData _presenterUserData;
#endregion
#region Events
public void DoWork()
{
}
public WcfService()
{
_presenterUserData = new PresenterUserData(this);
}
public List GetUserDetails()
{
_presenterUserData.GetAllData();
return UserDatas;
}
public List GetSearchUserDetails(string search)
{
_presenterUserData.GetAllData();
if (UserDatas != null && UserDatas.Count > 0)
{
UserDatas = UserDatas.Where(x => x.FirstName.ToLower().Contains(search.ToLower()) ||
x.LastName.ToLower().Contains(search.ToLower())).ToList();
}
return UserDatas;
}
#endregion
#region Members
public EntityLib.UserData CurrentUserData { get; set; }
public List UserDatas { get; set; }
#endregion
}
}