Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent Timer for each item in List on ViewModel
    primarykey
    data
    text
    <p>I have a List of actions that need to be performed by company representatives and i like to open a timer if it is on edit for X minutes. and all 10 minutes i like the page to be refreshed.</p> <p>the problem is that many company agent can access and edit those action. so i like just colored the item on my view, but if the agent "sleepee" for this X minutes - the underProcess field reset to false; </p> <p>So I start with adding to my model a field who tell me that this Action are "UnderProcess" (I love CodeFirst :) And I add to the ViewModel a static dictionary an on edit i get thare and add a row with kay-actionID and DateTime of edit. After that in my view on the foreach if item.UnderProcess the style=color:red .. Course after edit i remove from dictionary and change the bool flag.</p> <p>But that not working - it stay red after this X minutes, I think that the problem is on this static dictionary because when i debug it is always empty.</p> <p>Hare My ViewModel:</p> <pre><code>public class AgentActionViewModel { public SupplierAction Action { get; set; } public List&lt;SupplierAction&gt; Actions { get; set; }//= new List&lt;SupplierAction&gt;(); public static Dictionary&lt;int, DateTime&gt; UnderProcessFrom; public static AgentActionViewModel() { UnderProcessFrom = new Dictionary&lt;int, DateTime&gt;(); } } </code></pre> <p>The Controller:</p> <p>Index</p> <pre><code>[SupplierAuthorization] public ActionResult AgentAction(..) { Response.AddHeader("Refresh", (MINUTES*60).ToString()); List&lt;SupplierAction&gt; actions = db.SupplierActions.ToList(); bool flag = false; var collection = AgentActionViewModel.UnderProcessFrom.Keys; foreach (var aId in collection) { if (AgentActionViewModel.UnderProcessFrom[aId].AddMinutes(MINUTES) &lt;= DateTime.Now) { AgentActionViewModel.UnderProcessFrom.Remove(aId); var action = actions.Find(a=&gt;a.SupplierActionID == aId); action.UnderProcess = false; db.Entry(action).State = EntityState.Modified; } } if(flag) db.SaveChanges(); ... var vm = new AgentActionViewModel(); vm.Actions = actions.OrderByDescending(d =&gt; d.RequestDate).ToList(); return View(vm); } </code></pre> <p>GET Edit:</p> <pre><code> [SupplierAuthorization] public ActionResult Edit(int id = -1) { try { ... if (!a.UnderProcess) { a.UnderProcess = true; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); AgentActionViewModel.UnderProcessFrom.Add(id, DateTime.Now); } ... } catch (Exception ex) { .... if (a.UnderProcess) { a.UnderProcess = false; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); AgentActionViewModel.UnderProcessFrom.Remove(id); } ..... } ... } </code></pre> <p>Post Edit :</p> <pre><code>..... if (vm.Action.UnderProcess) { vm.Action.UnderProcess = false; AgentActionViewModel.UnderProcessFrom.Remove(vm.ActionID); } ..... </code></pre> <p>My View :</p> <pre><code>@model oCc.IPToGo.ViewModel.AgentActionViewModel .... &lt;tbody&gt; @foreach (var item in Model.Actions) { &lt;tr style="@(item.UnderProcess ? "color:red" : "")"&gt; &lt;td&gt; ..... </code></pre> <p>10x an sorry for my bad English =)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload