コントローラーから次の json 出力を取得できますが、myDates と myStaff から「キー」と「値」を削除し、予定時刻を日付ごとにグループ化する必要があります - 例: date0、date1、date2..
{
"myDates": [{
"Key": "date0",
"Value": "23/02/2013"
}, {
"Key": "date1",
"Value": "24/02/2013"
}, {
"Key": "date2",
"Value": "25/02/2013"
}, {
"Key": "date3",
"Value": "26/02/2013"
}, {
"Key": "date4",
"Value": "27/02/2013"
}, {
"Key": "date5",
"Value": "28/02/2013"
}, {
"Key": "date6",
"Value": "1/03/2013"
}, {
"Key": "dname0",
"Value": "Saturday"
}, {
"Key": "dname1",
"Value": "Sunday"
}, {
"Key": "dname2",
"Value": "Monday"
}, {
"Key": "dname3",
"Value": "Tuesday"
}, {
"Key": "dname4",
"Value": "Wednesday"
}, {
"Key": "dname5",
"Value": "Thursday"
}, {
"Key": "dname6",
"Value": "Friday"
}, {
"Key": "ndate",
"Value": "2013-03-02"
}, {
"Key": "pdate",
"Value": "2013-02-16"
}],
"myStaff": [{
"Key": "staff0",
"Value": [
[{
"SlotID": 42501,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "23/02/2013",
"SlotDay": "Saturday",
"SlotTime": "10:00"
}, {
"SlotID": 42502,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "23/02/2013",
"SlotDay": "Saturday",
"SlotTime": "10:30"
}],
[{
"SlotID": 47001,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "24/02/2013",
"SlotDay": "Sunday",
"SlotTime": "10:00"
}, {
"SlotID": 47002,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "24/02/2013",
"SlotDay": "Sunday",
"SlotTime": "10:30"
}]
]
}]
}
基本的に、次のようにフォーマットされたjsonを取得する必要があります。
{
"myDates": [{
"date0": "23/02/2013",
"date1": "24/02/2013",
"date2": "25/02/2013",
"date3": "26/02/2013",
"date4": "27/02/2013",
"date5": "28/02/2013",
"date6": "1/03/2013",
"dname0": "Saturday",
"dname1": "Sunday",
"dname2": "Monday",
"dname3": "Tuesday",
"dname4": "Wednesday",
"dname5": "Thursday",
"dname6": "Friday",
"ndate": "2013-03-02",
"pdate": "2013-02-16",
}],
"myStaff": [{
"staff0": {[
"date0": {[
[{
"SlotID": 42501,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "23/02/2013",
"SlotDay": "Saturday",
"SlotTime": "10:00"
}, {
"SlotID": 42502,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "23/02/2013",
"SlotDay": "Saturday",
"SlotTime": "10:30"
}],
"date1": {[
"SlotID": 47001,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "24/02/2013",
"SlotDay": "Sunday",
"SlotTime": "10:00"
}, {
"SlotID": 47002,
"StaffID": 1,
"BusinessID": 1,
"SlotDate": "24/02/2013",
"SlotDay": "Sunday",
"SlotTime": "10:30"
}]
]}
}]
}]
}
これは私のコントローラーです:
public ActionResult Index(DateTime start, string id = null)
{
var allids = Request.QueryString["id"];
// split the input into anonymous objects containing staffid and businessid
var staffids = from staffid in allids.Split(',').Select(x => x.Split('-'))
select new { sid = int.Parse(staffid[0]), bid = int.Parse(staffid[1]) };
// get the days you need
var days = Enumerable.Range(0, 7).Select(x => start.AddDays(x));
// create myDates
int i = 0;
var myDates = (from day in days
select new KeyValuePair<string, string>(
String.Format("date{0}", i++),
day.ToShortDateString())).ToList();
i = 0;
myDates.AddRange(
(from day in days
select new KeyValuePair<string, string>(
String.Format("dname{0}", i++),
day.DayOfWeek.ToString())).ToList());
myDates.Add(new KeyValuePair<string, string>("ndate", days.First().AddDays(7).ToString("yyyy-MM-dd")));
myDates.Add(new KeyValuePair<string, string>("pdate", days.First().AddDays(-7).ToString("yyyy-MM-dd")));
// receive all the stored_procedures
i = 0;
var myStaff = from staff in staffids
select new KeyValuePair<string, object>(
String.Format("staff{0}", i++),
(from day in days
select db.Database.SqlQuery<GetAvailableAppointments>("EXEC SP_GetAvailableAppointments @StaffID, @BusinessID, @StartDate",
new SqlParameter("StaffID", staff.sid),
new SqlParameter("BusinessID", staff.bid),
new SqlParameter("StartDate", day))).ToList()
);
return Json(new { myDates, myStaff }, JsonRequestBehavior.AllowGet);
}
どんな助けでも大歓迎です:)