public static ProcessRevisionModel ToModel(this ProcessRevision aProcessRev, string aProcessName = null) { return(new ProcessRevisionModel() { CreatedByEmp = aProcessRev.CreatedByEmp, DateTimeCreated = aProcessRev.DateCreated.Add(aProcessRev.TimeCreated), Comments = aProcessRev.Comments, ProcessId = aProcessRev.ProcessId, ProcessRevId = aProcessRev.ProcessRevId, RevStatusId = aProcessRev.RevStatusId, ProcessName = aProcessName }); }
//Takes a current process and makes a copy of it with the only revision on it being the locked rev of the existing process public async Task <ProcessModel> CopyToNewProcessFromExisting(ProcessModel aProcessModel) { var theProcessEntity = aProcessModel.ToEntity(); var lastUsedProcessId = await context.Process.MaxAsync(i => i.ProcessId); theProcessEntity.ProcessId = lastUsedProcessId + 1; //Grabs the locked revision of the process being copied. var theOldRevisionEntity = await context.ProcessRevision.Where(i => i.ProcessId == aProcessModel.ProcessId && i.RevStatusId == 1) //1 = LOCKED .Include(i => i.ProcessStepSeq) .ThenInclude(i => i.Operation) .ThenInclude(i => i.OperGroup) .Include(i => i.ProcessStepSeq) .ThenInclude(i => i.Step).FirstOrDefaultAsync(); var theRevisionEntity = new ProcessRevision(); theRevisionEntity.ProcessRevId = 1; theRevisionEntity.RevStatusId = 2; //2 = UNLOCKED theRevisionEntity.DateCreated = DateTime.Now; theRevisionEntity.TimeCreated = DateTime.Now.TimeOfDay; theRevisionEntity.ProcessId = theProcessEntity.ProcessId; theRevisionEntity.Comments = aProcessModel.Revisions.FirstOrDefault().Comments; theRevisionEntity.CreatedByEmp = aProcessModel.Revisions.FirstOrDefault().CreatedByEmp; var theNewStepSeqEntities = new List <ProcessStepSeq>(); foreach (var stepSeq in theOldRevisionEntity.ProcessStepSeq) { theNewStepSeqEntities.Add(new ProcessStepSeq { StepId = stepSeq.StepId, StepSeq = stepSeq.StepSeq, ProcessId = theProcessEntity.ProcessId, ProcessRevId = theRevisionEntity.ProcessRevId, OperationId = stepSeq.OperationId }); } theRevisionEntity.ProcessStepSeq = theNewStepSeqEntities; theProcessEntity.ProcessRevision.Add(theRevisionEntity); context.Process.Add(theProcessEntity); await context.SaveChangesAsync(); var result = await GetHydratedProcess(theProcessEntity.ProcessId); return(result); }
public static ProcessRevisionModel ToHydratedModel(this ProcessRevision aRev) { var theRevModel = aRev.ToModel(); var theStepSeqModels = new List <StepSeqModel>(); foreach (var stepSeq in aRev.ProcessStepSeq) { var theStepSeq = stepSeq.ToModel(); theStepSeqModels.Add(theStepSeq); } theRevModel.StepSeqs = theStepSeqModels; return(theRevModel); }