public async Task <IHttpActionResult> CreateNonPersoJob(NonPersoModel entity) { userId = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Create the CS var newEntity = new NonPersoJob() { SidProductId = entity.SidProductId, Quantity = entity.Quantity, JobName = entity.JobName, Description = entity.Description, ServiceTypeId = entity.ServiceTypeId, IsTreated = false, CreatedById = userId, ModifiedById = userId, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; context.NonPersoJobs.Add(newEntity); await context.SaveChangesAsync(); return(Ok <NonPersoJob>(newEntity)); }
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)); }