2013-12-18 116 views
0

我應該能夠弄清楚這一點,但我已經與它打了很長一段時間了。會話變量和列表對象沒有正確更新

我有一個彈出頁面,有幾個可用的請求,用戶可以從中選擇。根據用戶正在訪問的頁面,可能會有一個請求或多個請求可供該用戶使用。單個和多個請求都保存在不同的會話變量中。

我需要知道用戶在流程開始時選擇的單個請求。它工作正常,除非允許用戶添加多個請求,單個請求會話變量也會更新。

例如,單個請求變量具有「佛羅里達」;然後,用戶到達多個請求頁面並將GA和LA添加到多個請求會話變量。單個請求變量也會更新爲包含GA和LA,即使該標記爲假並且從未到達該行。我不希望它被更新。我需要隨時提供單個請求,以便用戶在需要時可以查看它。

這裏就是問題發生的一個示例代碼:

List<Request> temp = new List<Request>(); 
List<Request> mySearchRequest = new List<Request>(); 
List<Request> listSingleRequest = new List<Request>(); 
if (SessionWrapper.currentRequest.AvailableRequests != null) 
{ 
    mySearchRequest = (List<Request>)SessionWrapper.currentRequest.AvailableRequests; 
} 

if (SessionWrapper.currentRequest.MultipleRequests != null) 
{ 
    temp = (List<Request>)SessionWrapper.currentRequest.MultipleRequests; 
    var test = temp.Find(delegate(Request req) { return req.RequestId == id && req.Desc == description; }); 
    // Checking if we have on the container already 
    if (mySearchRequest.Any(r => r.RequestId == id && r.Desc == description) == false) 
    { 
     mySearchRequest.Add(test); 
     if (SessionWrapper.currentRequest.SingleRequest == true && mySearchRequest.Count() == 1) 
     { 
      listSingleRequest.Add(test); 
      SessionWrapper.currentRequest.singleRequest = listSingleRequest ; 
      listSingleRequest = null; 
     } 
    } 
} 
//Set multiple request session here 

你的幫助是極大的讚賞。 謝謝, JF

回答

0

幾乎整個晚上玩了幾天後,我能夠修復它。我不確定這是否是最有效的方式,但它現在可行。

if (SessionWrapper.currentRequest.MultipleRequests != null) 
{ 
    temp = (List<Request>)SessionWrapper.currentRequest.MultipleRequests; 
    var test = temp.Find(delegate(Request req) { return req.RequestId == id && req.Desc == description; }); 
    // Checking if we have on the container already 
    if (mySearchRequest.Any(r => r.RequestId == id && r.Desc == description) == false) 
    { 
     mySearchRequest.Add(test); 
     if (SessionWrapper.currentRequest.SingleRequestPage == true && mySearchRequest.Count() == 1) 
     { 
      foreach (var item in test) 
      { 
       //Create a new request object and add it to the list 
       Request request = new Request(); 
       request.RequestId == item.RequestId; 
       request.Description == item.Description; 
       listSingleRequest.Add(request); 
      } 
      SessionWrapper.currentRequest.singleRequest = listSingleRequest ; 
      listSingleRequest = null; 
     } 
    } 
} 


if (SessionWrapper.currentRequest.singleRequest != null) 
    { 
     tempRequest = SessionWrapper.currentRequest.singleRequest.ToList(); 
     foreach (var test in tempRequest) 
     { 
     Request request = new Request(); 
     request.RequestId == item.RequestId; 
     request.Description == item.Description; 
     listSingleRequest.Add(request); 
    } 
    SessionWrapper.currentRequest.ViewRequest = listSingleRequest; 
    listSingleRequest = null; 
}