public SaveResultVM UpdateAfterCompleteTask(WorkTask model, object additionalService = null) { switch (model.TaskTypeId) { case WorkTaskConstants.Types.CaseSessionAct_Coordinate: { var hasUnCompletedCoTasks = repo.AllReadonly <WorkTask>() .Where(x => x.ParentTaskId == model.ParentTaskId) .Where(x => x.TaskStateId != WorkTaskConstants.States.Completed) .Any(); var actModel = repo.GetById <CaseSessionAct>((int)model.SourceId); if (!hasUnCompletedCoTasks && actModel.ActStateId < NomenclatureConstants.SessionActState.Coordinated) { actModel.ActStateId = NomenclatureConstants.SessionActState.Coordinated; repo.Update(actModel); repo.SaveChanges(); return(new SaveResultVM(true, "", "reload")); } } break; case WorkTaskConstants.Types.CaseSessionAct_Sign: { var signTasks = repo.AllReadonly <WorkTask>().Where(x => x.ParentTaskId == model.ParentTaskId).ToList(); var hasUnCompletedCoTasks = signTasks.Where(x => x.TaskStateId != WorkTaskConstants.States.Completed) .Where(x => x.TaskStateId != WorkTaskConstants.States.Deleted) .Any(); var actModel = repo.GetById <CaseSessionAct>((int)model.SourceId); if (!hasUnCompletedCoTasks && (actModel.ActDeclaredDate == null)) { using (TransactionScope ts = new TransactionScope()) { actModel.ActStateId = NomenclatureConstants.SessionActState.Enforced; actModel.ActDeclaredDate = signTasks.OrderByDescending(x => x.DateCompleted).Select(x => x.DateCompleted).FirstOrDefault(); actModel.DateWrt = DateTime.Now; caseDeadlineService.DeadLineMotive(actModel); repo.Update(actModel); repo.SaveChanges(); lifecycleService.CaseLifecycle_SaveFirst_ForCaseType(actModel.CaseSessionId); if (actModel.IsFinalDoc) { lifecycleService.CaseLifecycle_CloseInterval(actModel.CaseId ?? 0, actModel.Id, actModel.ActDeclaredDate ?? DateTime.Now); } mqEpepService.AppendCaseSessionAct(actModel, EpepConstants.ServiceMethod.Add); mqEpepService.AppendCaseSessionAct_Private(actModel.Id, EpepConstants.ServiceMethod.Add); caseLoadIndexService.CaseLoadIndexAutomationElementGroupe_SRA_SaveData(actModel.CaseSessionId); ts.Complete(); return(new SaveResultVM(true, "", "reload")); } } } break; case WorkTaskConstants.Types.CaseSessionActMotives_Sign: { var acts = repo.AllReadonly <WorkTask>().Where(x => x.ParentTaskId == model.ParentTaskId).ToList(); var hasUnCompletedCoTasks = acts.Where(x => x.TaskStateId != WorkTaskConstants.States.Completed) .Any(); var actModel = repo.GetById <CaseSessionAct>((int)model.SourceId); if (!hasUnCompletedCoTasks && actModel.ActMotivesDeclaredDate == null) { using (TransactionScope ts = new TransactionScope()) { actModel.ActMotivesDeclaredDate = acts.OrderByDescending(x => x.DateCompleted).Select(x => x.DateCompleted).FirstOrDefault(); caseDeadlineService.DeadLineMotive(actModel); repo.Update(actModel); repo.SaveChanges(); mqEpepService.AppendCaseSessionAct_PrivateMotive(actModel.Id, EpepConstants.ServiceMethod.Add); ts.Complete(); return(new SaveResultVM(true, "", "reload")); } } } break; case WorkTaskConstants.Types.DocumentResolution_Sign: { var signTasks = repo.AllReadonly <WorkTask>().Where(x => x.ParentTaskId == model.ParentTaskId).ToList(); var hasUnCompletedCoTasks = signTasks.Where(x => x.TaskStateId != WorkTaskConstants.States.Completed) .Any(); var actModel = repo.GetById <DocumentResolution>(model.SourceId); if (!hasUnCompletedCoTasks && (actModel.DeclaredDate == null)) { using (TransactionScope ts = new TransactionScope()) { actModel.ResolutionStateId = NomenclatureConstants.ResolutionStates.Enforced; actModel.DeclaredDate = signTasks.OrderByDescending(x => x.DateCompleted).Select(x => x.DateCompleted).FirstOrDefault(); actModel.DateWrt = DateTime.Now; repo.Update(actModel); repo.SaveChanges(); ts.Complete(); return(new SaveResultVM(true, "", "reload")); } } } break; } return(new SaveResultVM(false)); }