public async Task <IHttpActionResult> MarkUnDeleteServerJob(int id, ServerJobQueue entity) { var existingEntity = await context.ServerJobQueues.FindAsync(entity.Id); if (id != entity.Id) { return(BadRequest(ModelState)); } if (existingEntity != null && context.Entry(existingEntity).State != EntityState.Detached) { context.Entry(existingEntity).State = EntityState.Detached; } var local = context.Set <ServerJobQueue>().Local.FirstOrDefault(f => f.Id == entity.Id); if (local != null) { context.Entry(local).State = EntityState.Detached; } //existingEntity.IsTreated = true; existingEntity.IsDeleted = false; existingEntity.ModifiedOn = DateTime.Now; context.ServerJobQueues.Attach(existingEntity); context.Entry(existingEntity).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok <ServerJobQueue>(entity)); }
public async Task <IHttpActionResult> CreateJob([FromBody] JobModel entity) //Todo: Create the model for this entity { //Todo: check if the job already exist if (entity == null) { return(BadRequest(ModelState)); } if (entity.RemarkId == 0) { var remark = context.Remarks.FirstOrDefault(a => a.Name == "Null"); entity.RemarkId = remark.Id; } // Get Required Resources var jobTypePersoOnly = _repo.FindJobTypeByName("Perso Only"); var jobTypePrintingOnly = _repo.FindJobTypeByName("Printing Only"); var jobTypeMailingOnly = _repo.FindJobTypeByName("Mailing Only"); var jobTypeDispatchOnly = _repo.FindJobTypeByName("Dispatch Only"); var jobTypePrintingAndPerso = _repo.FindJobTypeByName("Printing And Perso"); var jobTypePrintingPersoAndMailing = _repo.FindJobTypeByName("Printing, Perso And Mailing"); var jobTypePersoAndMailing = _repo.FindJobTypeByName("Perso And Mailing"); var jobName = _repo.FindServerJobByName(entity.JobName); var jobStatusPending = _repo.FindJobStatusByName("Pending"); var jobStatusCompleted = _repo.FindJobStatusByName("Completed"); var jobStatusQueue = _repo.FindJobStatusByName("Queue"); var jobStatusNotRequired = _repo.FindJobStatusByName("Not Required"); //var jobTrackerStatusNew = _repo.FindJobTrackerStatusByName("New"); if (entity.JobType == "NonPerso") { NonPersoJob nonPersoJob = await _repo.FindNonPersoJobById(entity.Id); nonPersoJob.IsTreated = true; context.Entry(nonPersoJob).State = EntityState.Modified; await context.SaveChangesAsync(); } else { ServerJobQueue serverJobQueue = await _repo.FindServerJobQueueById(jobName.Id); // Update ServerJob as Treated serverJobQueue.IsTreated = true; context.Entry(serverJobQueue).State = EntityState.Modified; await context.SaveChangesAsync(); } var newJob = new Job() { JobName = entity.JobName, SidCardTypeId = entity.SidCardTypeId, SidClientId = entity.SidClientId, RemarkId = entity.RemarkId, Quantity = entity.Quantity, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, JobStatusId = jobStatusPending.Id }; // Create Job //newJob.JobStatusId = jobStatusPending.Id; context.Jobs.Add(newJob); await context.SaveChangesAsync(); var lastCreatedJob = _repository.Jobs.Where(m => m.JobName == entity.JobName).OrderByDescending(p => p.Id).ToList().FirstOrDefault(); // Create JobTracker var jobTrackerPersoOnly = new JobTracker() { JobId = lastCreatedJob.Id, CardOpsId = jobStatusCompleted.Id, InventoryId = jobStatusQueue.Id, PrintingId = jobStatusNotRequired.Id, PrintQAId = jobStatusPending.Id, PrintQCId = jobStatusPending.Id, CardEngrId = jobStatusPending.Id, QAId = jobStatusPending.Id, FirstJobRunId = jobStatusPending.Id, CardEngrResumeId = jobStatusPending.Id, QCId = jobStatusPending.Id, MailingId = jobStatusPending.Id, DispatchId = jobStatusPending.Id, //Create dispatch setups CustomerServiceId = jobStatusPending.Id, MAudId = jobStatusPending.Id, JobStatusId = jobStatusPending.Id, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; context.JobTrackers.Add(jobTrackerPersoOnly); await context.SaveChangesAsync(); // CardOpsLogs entity.Id = lastCreatedJob.Id; var t1 = CreateCardOpsLogs(newJob); await Task.WhenAll(t1); return(Ok <Job>(newJob)); }