public async Task <IHttpActionResult> UpdateJobSlitQCAnalysis(int id, JobSplitPrintCEAnalysis entity) { string userId = User.Identity.GetUserId(); JobSplitPrintCEAnalysis existingEntity = await context.JobSplitPrintCEAnalysis.FindAsync(entity.Id); var 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 <JobSplitPrintCEAnalysis>().Local.FirstOrDefault(f => f.Id == entity.Id); if (local != null) { context.Entry(local).State = EntityState.Detached; } // Analysis Computation var range = (jobSplit.RangeTo - jobSplit.RangeFrom) + 1; var quantityGood = range - (existingEntity.HeldReturned + (entity.QuantityBad + entity.QuantityHeld)); existingEntity.QuantityGood = quantityGood; existingEntity.QuantityBad = entity.QuantityBad; existingEntity.QuantityHeld = entity.QuantityHeld; // Todo Audit fix existingEntity.CreatedById = userId; existingEntity.CreatedOn = DateTime.Now; existingEntity.ModifiedById = userId; existingEntity.ModifiedOn = DateTime.Now; existingEntity.IsCEInitialized = true; //Todo: inbuilt Tracker for QA, QC context.JobSplitPrintCEAnalysis.Attach(existingEntity); context.Entry(existingEntity).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok <JobSplitPrintCEAnalysis>(existingEntity)); }
public async Task <IHttpActionResult> CreateJobPrintSplitCEAnalysis(JobSplitPrintCEAnalysis entity) { userId = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newEntity = entity; context.JobSplitPrintCEAnalysis.Add(newEntity); await context.SaveChangesAsync(); return(Ok <JobSplitPrintCEAnalysis>(newEntity)); }
public async Task <IHttpActionResult> CreateFirstCard(IList <FirstCardModel> entity) { userId = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var jobTracker = await context.JobTrackers.FindAsync(entity[0].JobTrackerId); var job = await context.Jobs.FindAsync(jobTracker.JobId); var serviceType = job.ServiceTypeId; // Create the JobSlip foreach (var m in entity) { var newJobSlit = new JobSplit() { JobTrackerId = m.JobTrackerId, DepartmentId = m.DepartmentId, SidMachineId = m.SidMachineId, RangeFrom = m.RangeFrom, RangeTo = m.RangeTo, CreatedById = userId, CreatedOn = DateTime.Now }; var t1 = await CreateJobSlit(newJobSlit); var lastJobSplit = _repository.JobSplits.OrderByDescending(x => x.Id).Take(1).ToList(); // Create the QA Process var newQA = new Sid05QA() { JobTrackerId = m.JobTrackerId, JobSplitId = lastJobSplit[0].Id, CreatedOn = DateTime.Now, CreatedById = userId }; var t11 = await CreateSidQA(newQA); // Create the CEAnalysis var goodQty = (m.RangeTo - m.RangeFrom) + 1; var newJobSlitCEAnalysis = new JobSplitPrintCEAnalysis() { JobSplitId = lastJobSplit[0].Id, JobTrackerId = m.JobTrackerId, QuantityGood = goodQty, QuantityBad = 0, QuantityHeld = 0, CreatedOn = DateTime.Now, CreatedById = userId, ModifiedById = userId, ModifiedOn = DateTime.Now }; var t2 = await CreateJobPrintSplitCEAnalysis(newJobSlitCEAnalysis); } var jobStatusWIP = _repo.FindJobStatusByName("WIP"); var jobStatusQueue = _repo.FindJobStatusByName("Queue"); 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"); #region JobTrackerUpdateFlow if (serviceType == jobTypePrintingOnly.Id) { jobTracker.PrintQAId = jobStatusQueue.Id; } else if (serviceType == jobTypePrintingAndPerso.Id) { jobTracker.PrintQAId = jobStatusQueue.Id; } else if (serviceType == jobTypePrintingPersoAndMailing.Id) { jobTracker.PrintQAId = jobStatusQueue.Id; } #endregion jobTracker.ModifiedOn = DateTime.Now; jobTracker.PrintingId = jobStatusWIP.Id; context.Entry(jobTracker).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok()); }