Marius Vasile

Marius Vasile

  • 594
  • 1.9k
  • 145.6k

Similar OnPost actions with different results

Jan 14 2021 5:48 PM
I have similar OnPost actions but in one case it writes all data in another it does not. I've checked, there are no errors, however, in first case Remarks are written in the second are not. What is wrong?
 
First case
 
  1. public async Task<IActionResult> OnPostPTWManagementAsync(int ptwNoId)  
  2.         {  
  3.             if (!ModelState.IsValid)  
  4.             {  
  5.                 return Page();  
  6.             }  
  7.   
  8.             var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  9.             var username = await (from a in _context.UsersData.Where(a => a.Id == userId)  
  10.                                   join b in _context.CompanyDatas on a.OrgID equals b.OrgID into TempData1  
  11.                                   from c in TempData1  
  12.   
  13.                                   select new UserDataRole  
  14.                                   {  
  15.                                       UserId = a.Id,  
  16.                                       UserName = a.UserName,  
  17.                                       Email = a.Email,  
  18.                                       OrgID = c.OrgID,  
  19.                                       UserOrganization = c.CompanyName,  
  20.                                   }).FirstOrDefaultAsync();  
  21.   
  22.             var ptwStatus = _context.PTWContents.First(s => s.PTWNo == ptwNoId);  
  23.             ptwStatus.PTWStatus = "Management";  
  24.             await _context.SaveChangesAsync();  
  25.             PTWLog newPTWLog = new PTWLog()  
  26.             {  
  27.                 PTWNo = ptwNoId,  
  28.                 PTWStatus = "Management",  
  29.                 PTWDateStatus = DateTime.Now,  
  30.                 UserName = username.UserName,  
  31.                 Remarks = "Awaiting for Management Approval"  
  32.             };  
  33.             if (await TryUpdateModelAsync(newPTWLog, "PTWLog"))  
  34.             {  
  35.                 _context.PTWLogs.Add(newPTWLog);  
  36.                 await _context.SaveChangesAsync();  
  37.                 return RedirectToPage("PTWForm""PTWNoId"new { ptwNoId = ptwNoId });  
  38.             }  
  39.             return RedirectToPage("PTWForm""PTWNoId"new { ptwNoId = ptwNoId });  
  40.         }  
Second case
 
  1. public async Task<IActionResult> OnPostPTWManagementApproveAsync(int ptwNoId)  
  2.         {  
  3.             if (!ModelState.IsValid)  
  4.             {  
  5.                 return Page();  
  6.             }  
  7.   
  8.             var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  9.             var username = await (from a in _context.UsersData.Where(a => a.Id == userId)  
  10.                                   join b in _context.CompanyDatas on a.OrgID equals b.OrgID into TempData1  
  11.                                   from c in TempData1  
  12.   
  13.                                   select new UserDataRole  
  14.                                   {  
  15.                                       UserId = a.Id,  
  16.                                       UserName = a.UserName,  
  17.                                       Email = a.Email,  
  18.                                       OrgID = c.OrgID,  
  19.                                       UserOrganization = c.CompanyName,  
  20.                                   }).FirstOrDefaultAsync();  
  21.   
  22.             var ptwStatus = _context.PTWContents.First(s => s.PTWNo == ptwNoId);  
  23.             ptwStatus.PTWStatus = "Approved";  
  24.             await _context.SaveChangesAsync();  
  25.             PTWLog newPTWLog = new PTWLog()  
  26.             {  
  27.                 PTWNo = ptwNoId,  
  28.                 PTWStatus = "Approved",  
  29.                 PTWDateStatus = DateTime.Now,  
  30.                 UserName = username.UserName,  
  31.                 Remarks = "PTW is approved by Management"  
  32.             };  
  33.             if (await TryUpdateModelAsync(newPTWLog, "PTWLog"))  
  34.             {  
  35.                 _context.PTWLogs.Add(newPTWLog);  
  36.                 await _context.SaveChangesAsync();  
  37.                 return RedirectToPage("PTWForm""PTWNoId"new { ptwNoId = ptwNoId });  
  38.             }  
  39.             return RedirectToPage("PTWForm""PTWNoId"new { ptwNoId = ptwNoId });  
  40.   
  41.         }  
So, in the first case, the Remarks, the string, is written to the table in the second are not 

Answers (5)