public async Task <IHttpActionResult> UpdateJobSlitPrintQCAnalysis(int id, JobSplitQCAnalysis entity) { string userId = User.Identity.GetUserId(); JobSplit jobSplit = await context.JobSplits.FindAsync(entity.JobSplitId); if (entity == null) { return(NotFound()); } var jobStatusWIP = _repo.FindJobStatusByName("WIP"); var jobTracker = await context.JobTrackers.FindAsync(jobSplit.JobTrackerId); // Update JobTracker jobTracker.PrintQCId = jobStatusWIP.Id; jobTracker.ModifiedOn = DateTime.Now; context.Entry(jobTracker).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok <JobSplitQCAnalysis>(entity)); }
public async Task <IHttpActionResult> UpdateJobSlitQCAnalysis(int id, JobSplitQCAnalysis entity) { string userId = User.Identity.GetUserId(); //JobSplitQCAnalysis existingEntity = await context.JobSplitQCAnalysis.FindAsync(entity.Id); JobSplit jobSplit = await context.JobSplits.FindAsync(entity.JobSplitId); //if (entity == null) { return NotFound(); } //if (id != entity.Id) { return BadRequest(ModelState); } //if (entity == null) //{ // //return BadRequest(ModelState); // var message = string.Format("Entry is empty"); // HttpError err = new HttpError(message); // return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, err)); //} ////if (existingEntity != null && context.Entry(existingEntity).State != EntityState.Detached) ////{ //// context.Entry(existingEntity).State = EntityState.Detached; ////} //var local = context.Set<JobSplitQCAnalysis>().Local.FirstOrDefault(f => f.Id == entity.Id); //if (local != null) { context.Entry(local).State = EntityState.Detached; } // Update JobTracker var jobStatusWIP = _repo.FindJobStatusByName("WIP"); var jobStatusCompleted = _repo.FindJobStatusByName("Completed"); var jobStatusQueue = _repo.FindJobStatusByName("Queue"); var jobStatusNotRequired = _repo.FindJobStatusByName("Not Required"); var jobTracker = await context.JobTrackers.FindAsync(jobSplit.JobTrackerId); var job = await context.Jobs.FindAsync(jobTracker.JobId); var jobTypePersoOnly = _repo.FindJobTypeByName("Perso Only"); var jobTypePrintingOnly = _repo.FindJobTypeByName("Printing Only"); var jobTypePrintingAndPerso = _repo.FindJobTypeByName("Printing And Perso"); var jobTypePrintingPersoAndMailing = _repo.FindJobTypeByName("Printing, Perso And Mailing"); var jobTypePersoAndMailing = _repo.FindJobTypeByName("Perso And Mailing"); var serviceType = job.ServiceTypeId; // Update JobTracker #region JobTrackerUpdateFlow if (serviceType == jobTypePrintingOnly.Id) { jobTracker.DispatchId = jobStatusQueue.Id; } else if (serviceType == jobTypePersoOnly.Id) { //jobTracker.DispatchId = jobStatusQueue.Id; if (jobTracker.QCId == jobStatusQueue.Id) { jobTracker.QCId = jobStatusWIP.Id; jobTracker.DispatchId = jobStatusQueue.Id; } } else if (serviceType == jobTypePrintingAndPerso.Id) { // For Perso Region if (jobTracker.QCId == jobStatusQueue.Id) { jobTracker.QCId = jobStatusWIP.Id; jobTracker.DispatchId = jobStatusQueue.Id; } } else if (serviceType == jobTypePersoAndMailing.Id) { //jobTracker.MailingId = jobStatusQueue.Id; if (jobTracker.QCId == jobStatusQueue.Id) { jobTracker.QCId = jobStatusWIP.Id; jobTracker.MailingId = jobStatusQueue.Id; } } else if (serviceType == jobTypePrintingPersoAndMailing.Id) { // For Perso Region if (jobTracker.QCId == jobStatusQueue.Id) { jobTracker.QCId = jobStatusWIP.Id; jobTracker.MailingId = jobStatusQueue.Id; } //jobTracker.MailingId = jobStatusQueue.Id; } #endregion jobTracker.ModifiedOn = DateTime.Now; context.Entry(jobTracker).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok()); }