finance_teacher
asked on
LINQ -- easy CASE statement ?
Currently below #1 works.
How can I change below #2 to be
simpler and work with "IN" statement
using ASP.net MVC4 C# ?
-------------------------- ---------- ---------- ---------- ---------- ---------- -----
#1
public ActionResult Technician(string sabProjectID)
{
var myPOs =
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 6 && p.ProjectID == sabProjectID
select p
)
;
return View(myPOs);
}
-------------------------- ---------- ---------- ---------- ---------- ---------- -----
#2
public ActionResult DisplayResults(string sabProjectID, string URLRole)
{
var myPOs =
case
WHEN URLRole='Inspector' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 2 && p.ProjectID == sabProjectID
select p
)
case
WHEN URLRole='Lead' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage in (6,7) && p.ProjectID == sabProjectID
select p
)
case
WHEN URLRole='Customer' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 4 && p.ProjectID == sabProjectID
select p
)
;
return View(myPOs);
}
How can I change below #2 to be
simpler and work with "IN" statement
using ASP.net MVC4 C# ?
--------------------------
#1
public ActionResult Technician(string sabProjectID)
{
var myPOs =
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 6 && p.ProjectID == sabProjectID
select p
)
;
return View(myPOs);
}
--------------------------
#2
public ActionResult DisplayResults(string sabProjectID, string URLRole)
{
var myPOs =
case
WHEN URLRole='Inspector' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 2 && p.ProjectID == sabProjectID
select p
)
case
WHEN URLRole='Lead' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage in (6,7) && p.ProjectID == sabProjectID
select p
)
case
WHEN URLRole='Customer' THEN
(from p in db.MAINT_WORK_REQ
where
p.WorkFlowStage == 4 && p.ProjectID == sabProjectID
select p
)
;
return View(myPOs);
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
How can I change below #1 so URLRole gets passed ?
Currently it gets passed as "NULL" ?
-------------------------- ---------- ----------
Steps
1. user clicks
<li>@Html.ActionLink("TEST ", "Index", "MAINT_WORK_REQ", new { area = "TEST" }, new { URLRole = "Inspector" })</li>
-------------------------- ---------- ----------
2. parameters get passed to below CONTROLLER method
public ActionResult Index(string URLRole)
{
string sabProgramID = "FORD";
var myPOs = from p in db.MAINT_WORK_REQ
select p;
switch (URLRole)
{
case "Inspector":
myPOs = myPOs.Where(pI => pI.WorkFlowStage == 2 && pI.ProgramID == sabProgramID);
break;
case "Lead":
List<int?> wfs = new List<int?>() { 6, 7 };
myPOs = myPOs.Where(pL => wfs.Contains(pL.WorkFlowSt age) && pL.ProgramID == sabProgramID);
break;
case "Customer":
myPOs = myPOs.Where(pC => pC.WorkFlowStage == 4 && pC.ProgramID == sabProgramID);
break;
}
return View(myPOs.ToList());
}
Currently it gets passed as "NULL" ?
--------------------------
Steps
1. user clicks
<li>@Html.ActionLink("TEST
--------------------------
2. parameters get passed to below CONTROLLER method
public ActionResult Index(string URLRole)
{
string sabProgramID = "FORD";
var myPOs = from p in db.MAINT_WORK_REQ
select p;
switch (URLRole)
{
case "Inspector":
myPOs = myPOs.Where(pI => pI.WorkFlowStage == 2 && pI.ProgramID == sabProgramID);
break;
case "Lead":
List<int?> wfs = new List<int?>() { 6, 7 };
myPOs = myPOs.Where(pL => wfs.Contains(pL.WorkFlowSt
break;
case "Customer":
myPOs = myPOs.Where(pC => pC.WorkFlowStage == 4 && pC.ProgramID == sabProgramID);
break;
}
return View(myPOs.ToList());
}
ASKER
Below works when I am already inside the AREA
** i.e. http://localhost:64587/TEST/Anypage
@Html.ActionLink("Test2", "Index", "MAINT_WORK_REQ", new { URLRole = "Inspector" }, null)
How can I get below working when outside the AREA
** i.e. http://localhost:64587/Anypage
<li>@Html.ActionLink("TEST ", "Index", "MAINT_WORK_REQ", new { area = "TEST" }, new { URLRole = "Inspector" })</li>
** i.e. http://localhost:64587/TEST/Anypage
@Html.ActionLink("Test2", "Index", "MAINT_WORK_REQ", new { URLRole = "Inspector" }, null)
How can I get below working when outside the AREA
** i.e. http://localhost:64587/Anypage
<li>@Html.ActionLink("TEST
Hi finance_teacher;
To your question, "How can I change below #1 so URLRole gets passed ?", What is the exception you are getting?
To your question, "How can I change below #1 so URLRole gets passed ?", What is the exception you are getting?
ASKER
No error, it just passes URLRole as NULL when using the below link outside the AREA
I want it to pass URLRole = Inspector
<li>@Html.ActionLink("TEST ", "Index", "MAINT_WORK_REQ", new { area = "TEST" }, new { URLRole = "Inspector" })</li>
I want it to pass URLRole = Inspector
<li>@Html.ActionLink("TEST
I am out of my comfort zone with ASP.Net MVC buy try this,
<li>@Html.ActionLink("TEST", "Index", "MAINT_WORK_REQ", new { area = "TEST" }, "Inspector")</li>
ASKER
I got the same NULL parameter result when doing the below.
How can I get the URLRole parameter to run outside the AREA ?
<li>@Html.ActionLink("TEST ", "Index", "MAINT_WORK_REQ", new { area = "TEST" }, "Inspector")</li>
How can I get the URLRole parameter to run outside the AREA ?
<li>@Html.ActionLink("TEST
Try this.
<li>@Html.ActionLink("TEST", "Index", "MAINT_WORK_REQ", "TEST", "Inspector")</li>
ASKER
That also fails with below error since I have multiple areas with the same MAINT_WORK_REQController file name.
The request for 'MAINT_WORK_REQ' has found the following matching controllers:
Areas.Testing.Controllers. MAINT_WORK _REQContro ller
Areas.__Testing.Controller s.MAINT_WO RK_REQCont roller
I really need the new { area = "TEST" } added when doing the link somehow.
The request for 'MAINT_WORK_REQ' has found the following matching controllers:
Areas.Testing.Controllers.
Areas.__Testing.Controller
I really need the new { area = "TEST" } added when doing the link somehow.
Sorry finance_teacher but I am not that up on MVC and can not give you a way to accomplish this.
You may want to post this part of the question in the ASP.Net forum.
You may want to post this part of the question in the ASP.Net forum.
I think that the following will do exactly what you want:
Open in new window
Giannis