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
Praveen Kumar
NA
235
22.5k
You cannot call savechanges() more than once on a dbcontextscope.
Jul 13 2020 11:10 PM
HI,
I am getting this error when trying to run multiple failed billing.Can any one help me to fix this.
Controller
[HttpPost]
[ValidateAntiForgeryToken]
public
async Task<ActionResult> ReRunFailedSelectedBilling(List<BillingFailedViewModel> FailedGroups)
{
if
(_logger.IsInfoEnabled)
_logger.LogInfo(
string
.Format(
"Entering ReRunFailedSelectedBilling"
));
List<BillingFailedViewModel> CGs = FailedGroups.Where(x => x.ReRunFlag).ToList();
// Re-using code to get something working for GPSI. This should actually remove all the CGs and then process a single WFR. For now, we'll process one WFR for each CG...
using
(var dbContextScope = _dbContextScopeFactory.Create())
{
foreach
(BillingFailedViewModel group
in
CGs)
{
ReRunModel run =
new
ReRunModel((
int
)group.Id, DbConnection, ServerURL);
var login = HttpContext.User.Identity.Name;
run.Reject(login);
if
(run._Status.Success ==
false
)
{
TempData[
"Failure"
] =
"Error in rejection. Failed to reject."
;
}
else
{
// Create a new workflow request and re-run
var wfr = run.SetWorkflowRequest();
dbContextScope.SaveChanges();
run.WorkflowRequestId = wfr.Id;
await run.RunAsync(login);
}
}
}
using
(var dbContextScope = _dbContextScopeFactory.Create())
{
if
(_logger.IsInfoEnabled)
_logger.LogInfo(
"Exiting ReRunFailedSelectedBilling"
);
var query = FailedGroups.First().Query;
return
RedirectToAction(
"Billing"
,
"Manage"
,
new
{ Area =
"Billing"
, CalendarPeriodId = query.CalendarPeriodId, WorkflowGroupId = query.WorkflowGroupId, CompanyId = query.CompanyId, GroupSearch = query.GroupSearch, DisplayBucket = query.DisplayBucket, ShowWorkflowRequests =
true
});
//, calendarPeriodId = FailedGroups.First().QueryPeriodId });
}
}
Model.cs
public
async Task RunAsync(
string
login)
{
logger.LogInfo(
string
.Format(
"PERF RunAsync starting"
));
// Kick off the server job
string
customer = _WfRepo.GetCurrentUserCustomer(_User.WindowsUserName).Customer.Code;
ServiceStatus status =
new
ServiceStatus { Success =
false
, Message =
"Run failed."
};
if
(WorkflowRequestId!=
null
)
{
BusinessActionService.WorkflowRequest request =
new
BusinessActionService.WorkflowRequest()
{
WorkflowRequestId = WorkflowRequestId.ToString(),
CustomerCode = customer,
UserName = _User.WindowsUserName,
LoginName = login
};
try
{
logger.LogInfo(
string
.Format(
"PERF RequestBillingAsync {0} called"
, WorkflowRequestId.ToString()));
await _Service.RequestBillingAsync(request).ConfigureAwait(
false
);
}
catch
(Exception e)
{
logger.LogError(
"RequestBilling failed "
, e);
}
logger.LogInfo(
string
.Format(
"PERF RequestBillingAsync {0} returned"
, WorkflowRequestId.ToString()));
}
logger.LogInfo(
string
.Format(
"PERF RunAsync ending "
));
}
Reply
Answers (
5
)
Cookies in asp.net mvc core.
how to append selected value to Session using J query