question

MohamedAhmed-0355 avatar image
0 Votes"
MohamedAhmed-0355 asked tinywang-msft commented

Error for Looping by use foreach

I have error for Distinctbylast(p => p.ID)) isn't in library .



     // POST: InvPurchaseD/Edit/5
         // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
         // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
         [HttpPost]
  public ActionResult Update([FromBody] List<tblivInvInD> ivInvInDed)
         {
             try
             {
    
                 ivInvInDVM tbl = new ivInvInDVM();
    
                 // only get unique values to avoid duplication of data from grid array
                 foreach (tblivInvInD element in ivInvInDed.Distinctbylast(p => p.ID))
                 {
                     if (element.ID < 0)
                         element.ID = 0;
                     tbl.ivInvInD = element; tbl.LogonUser = User.Identity.Name;
                     int Result = tbl.Update();
    
                     if (Result == -1)
                         throw new System.ArgumentException(tbl.GlobalError, "DBlevel");
                 }
                 logger.LogInformation("ivInvInD ID {0} is Edited Scussefully  ", ivInvInDed.Count);
    
                 return Json(new { success = true });
             }
             catch (Exception dex)
             {
                 logger.LogError("Unable to save changes. in  ivInvInD with Message " + dex.Message);
                 ModelState.AddModelError("", "Unable to save changes. " + dex.Message);
                 AddPageAlerts(PageAlertType.Error, $"unable to save chnages  with error {Global.Models.SiteUtils.FriendlyErrorMessage(dex)}");
                 return Json(new { success = false, responseText = Global.Models.SiteUtils.FriendlyErrorMessage(dex) });
             }
             //         //return Json(new { success = true, responseText = "end of Page" });
         }






dotnet-aspnet-core-mvc
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You did not share any relevant code. Is Distinctbylast() a custom extension method???

1 Vote 1 ·

I want to look for recurring numbers. If the number is less than 0, it gives the value 0.
0 = Add a record
1= Record adjustment

120085-image.png


0 Votes 0 ·
image.png (45.2 KiB)

Did you find Distinctbylast in other files of your projects?

0 Votes 0 ·
Show more comments

0 Answers