Is it possible for a post method to return a confirm box to the user before continuing on with the method?

Viewed 36

I am trying to allow users to edit a page, but I want there to be a warning implemented that will tell the user if the 'future stock' minus 'the qty they subtracted' is less than 0, if it is. I want a warning to popup that tells the user this and asks them if they want to continue. If they click 'confirm', continue on with the rest of the post method, but if not, break out of it.

Here is some relevant code from my edit POST method that happens when the user edits the post

 var currentData = db.JODetails.AsNoTracking().FirstOrDefault(j => j.ID == jODetails.ID);

 int oldItemCount = currentData.item_qty != null ? (int)currentData.item_qty : 0;                      
 db.Entry(jODetails).State = EntityState.Modified;                      

 Item i = db.Items.Find(jODetails.ItemID);
 int newItemCount = jODetails.item_qty != null ? (int)jODetails.item_qty : 0;
 int itemDiff = newItemCount - oldItemCount;

 if (itemDiff < 0)
 {
    i.Order(itemDiff);

        foreach (ItemHasComps ihc in jODetails.Items.IHC)
        {
          ihc.HasComps.Commit((int)Math.Ceiling(ihc.qty) * itemDiff);
          ihc.HasComps.Order((int)Math.Ceiling(ihc.qty) * itemDiff);
          foreach (JODetails jod in jo.JODetails)
          {
              if (jod.Items != null && jod.item_qty > 0 && ihc.ItemID == jod.ItemID)
              {
                 jod.comp_qty += itemDiff * (int)ihc.qty;
              }

              if (jod.Components != null && jod.comp_qty > 0 && ihc.CompID == jod.ComponentID)           
              { 
                  jod.comp_qty += itemDiff * (int)ihc.qty;
              }

           }
         }

 }

But before this is all done I would like to add a check, like this

if (i.futurestock - itemDiff < 0)

  //return confirm box to user to continue on with method

I don't know if this is possible, or if there is a better way to do it maybe using jquery? Any advice would be appreciated

1 Answers

You can easily use the following approach and open a confirmation dialog before proceed.

<input type="submit" value="Edit" onclick="return 
    confirm('Are you sure you want to proceed?')"; />

If you want to post and then open dialog then you would better to use Ajax and open the dialog in success block.

Related