NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Write a note in this area. It's really easy to share with others. Click here ...public async Task StoreEmpDataToDB(EmployeeAssignmentResponseModel obj)
{
using (var transaction = dbContext.Database.BeginTransaction())
{
try
{
Int64 employeeId = 0;
// Store and Update Candidate Data
var candidateDataToStore = mapper.Map<List<Candidate>>(obj.data?.CANDIDATE);
if (candidateDataToStore.Count > 0)
{
employeeId = Convert.ToInt64(candidateDataToStore[0].id);
}
foreach (var candidate in candidateDataToStore)
{
var existingCandidate = await dbContext.Candidate.AsNoTracking()
.Where(c => c.id == candidate.id && c.Email == candidate.Email)
.FirstOrDefaultAsync();
if (existingCandidate == null)
{
await dbContext.Candidate.AddAsync(candidate);
}
else
{
dbContext.Entry(existingCandidate).State = EntityState.Detached; // Detach the existing entity
candidate.TableId = existingCandidate.TableId;
candidate.ModifiedDate = DateTime.Now; // Set the ModifiedDate explicitly
dbContext.Entry(candidate).State = EntityState.Modified; // Attach and mark the new entity as modified
}
}

// Store and Update Job Data
var jobDataToStore = mapper.Map<List<Job>>(obj.data?.JOB);
foreach (var job in jobDataToStore)
{
var existingJob = await dbContext.Job.AsNoTracking()
.FirstOrDefaultAsync(j => j.JobId == job.JobId && j.CompanyId == job.CompanyId
&& j.CustomerId == job.CustomerId && j.EmployeeId == Convert.ToString(employeeId));
if (existingJob == null)
{
job.EmployeeId = Convert.ToString(employeeId);
await dbContext.Job.AddAsync(job);
}
else
{
dbContext.Entry(existingJob).State = EntityState.Detached; // Detach the existing entity
job.TableId = existingJob.TableId;
job.EmployeeId = Convert.ToString(employeeId);
dbContext.Entry(job).State = EntityState.Modified; // Attach and mark the new entity as modified
}
}

// Store and Update Salary Data
for (var i = 0; i < obj.data?.SALARY?.Count; i++)
{
obj.data.SALARY[i].EndDate = obj.data.SALARY[i].END_DATE?.ToString();
}
var salaryDataToStore = mapper.Map<List<Salaries>>(obj.data?.SALARY);
foreach (var salary in salaryDataToStore)
{
var existingSalary = await dbContext.Salaries.AsNoTracking()
.FirstOrDefaultAsync(s => s.EmployeeId == salary.EmployeeId && s.RecId == salary.RecId);
if (existingSalary == null)
{
await dbContext.Salaries.AddAsync(salary);
}
else
{
dbContext.Entry(existingSalary).State = EntityState.Detached; // Detach the existing entity
salary.Id = existingSalary.Id;
dbContext.Entry(salary).State = EntityState.Modified; // Attach and mark the new entity as modified
}
}

// Store and Update Billing Data
var billingDataToStore = mapper.Map<List<Billings>>(obj.data?.BILLING);
foreach (var billing in billingDataToStore)
{
var existingBilling = await dbContext.Billings.AsNoTracking()
.FirstOrDefaultAsync(b => b.EmployeeId == billing.EmployeeId && b.RecId == billing.RecId);
if (existingBilling == null)
{
await dbContext.Billings.AddAsync(billing);
}
else
{
dbContext.Entry(existingBilling).State = EntityState.Detached; // Detach the existing entity
billing.Id = existingBilling.Id;
dbContext.Entry(billing).State = EntityState.Modified; // Attach and mark the new entity as modified
}
}
await dbContext.SaveChangesAsync();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
logExceptionService.WriteToFile("Exception Error in StoreEmpDataToDB Method", ex.Message);
throw new Exception(AppConstants.ErrorSavingDataToTheDatabase + ex.Message);
}
}
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.