I have a "Commit This Batch" button on my View where samples are entered into a pre-determined batch.
on click, I would like to do 2 updates:
1--Update all records with batch id=Session["BatchID"] to today's date. (Only one field needs updating but in multiple rows.)
2--update the batch's status to "C" (closed), in the batches table.
Pretty sure I do this from an ActionResult something like this which I know I won't have a problem with:
<button onclick="location.href='@Url.Action("<ActionResultName>", "ControllerName")';return false;">Commit This Batch</button>
In my ActionResult I am totally drawing a blank. Here is SQL from Query Window in Management Studio that I would like to emulate with as little code as possible:
UPDATE dbo.BactiBatches SET BatchStatus= 'C'
WHERE BactiBatchID= <SessionValue>
UPDATE dbo.BactiBucket SET ReceivedDate = GetDate()
WHERE BactiBatchID= <SessionValue>
I'm using EF and MVC4.
Ok, not sure how to make my question simpler. But I found this answer that voila! works. https://stackoverflow.com/a/8566906/564810
So below is the code in my HomeController that when called does EXACTLY what I want. No need for anything else. Of course, the controller does a lot of other CRUD so EF declaration is at the top:
public class HomeController : Controller
{