TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
591
1.9k
149.5k
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
public
async Task<IActionResult> OnPostPTWManagementAsync(
int
ptwNoId)
{
if
(!ModelState.IsValid)
{
return
Page();
}
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var username = await (from a
in
_context.UsersData.Where(a => a.Id == userId)
join b
in
_context.CompanyDatas on a.OrgID equals b.OrgID into TempData1
from c
in
TempData1
select
new
UserDataRole
{
UserId = a.Id,
UserName = a.UserName,
Email = a.Email,
OrgID = c.OrgID,
UserOrganization = c.CompanyName,
}).FirstOrDefaultAsync();
var ptwStatus = _context.PTWContents.First(s => s.PTWNo == ptwNoId);
ptwStatus.PTWStatus =
"Management"
;
await _context.SaveChangesAsync();
PTWLog newPTWLog =
new
PTWLog()
{
PTWNo = ptwNoId,
PTWStatus =
"Management"
,
PTWDateStatus = DateTime.Now,
UserName = username.UserName,
Remarks =
"Awaiting for Management Approval"
};
if
(await TryUpdateModelAsync(newPTWLog,
"PTWLog"
))
{
_context.PTWLogs.Add(newPTWLog);
await _context.SaveChangesAsync();
return
RedirectToPage(
"PTWForm"
,
"PTWNoId"
,
new
{ ptwNoId = ptwNoId });
}
return
RedirectToPage(
"PTWForm"
,
"PTWNoId"
,
new
{ ptwNoId = ptwNoId });
}
Second case
public
async Task<IActionResult> OnPostPTWManagementApproveAsync(
int
ptwNoId)
{
if
(!ModelState.IsValid)
{
return
Page();
}
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var username = await (from a
in
_context.UsersData.Where(a => a.Id == userId)
join b
in
_context.CompanyDatas on a.OrgID equals b.OrgID into TempData1
from c
in
TempData1
select
new
UserDataRole
{
UserId = a.Id,
UserName = a.UserName,
Email = a.Email,
OrgID = c.OrgID,
UserOrganization = c.CompanyName,
}).FirstOrDefaultAsync();
var ptwStatus = _context.PTWContents.First(s => s.PTWNo == ptwNoId);
ptwStatus.PTWStatus =
"Approved"
;
await _context.SaveChangesAsync();
PTWLog newPTWLog =
new
PTWLog()
{
PTWNo = ptwNoId,
PTWStatus =
"Approved"
,
PTWDateStatus = DateTime.Now,
UserName = username.UserName,
Remarks =
"PTW is approved by Management"
};
if
(await TryUpdateModelAsync(newPTWLog,
"PTWLog"
))
{
_context.PTWLogs.Add(newPTWLog);
await _context.SaveChangesAsync();
return
RedirectToPage(
"PTWForm"
,
"PTWNoId"
,
new
{ ptwNoId = ptwNoId });
}
return
RedirectToPage(
"PTWForm"
,
"PTWNoId"
,
new
{ ptwNoId = ptwNoId });
}
So, in the first case, the Remarks, the string, is written to the table in the second are not
Reply
Answers (
5
)
How to Bind check box inside dynamically binding dropdown using Jquery
How to set compnent blazor