Exemple #1
0
        public virtual JsonResult MissionWorkFlow(string operationNumber)
        {
            ResponseBase response        = new ResponseBase();
            var          jsonDataRequest = PageSerializationHelper.DeserializeJsonForm(Request.Form[0]);
            var          viewModel       = PageSerializationHelper.DeserializeObject <MissionsWorkflowViewModels>(jsonDataRequest.SerializedData);

            try
            {
                viewModel.UpdateMissionWorkFlowViewModel(jsonDataRequest.ClientFieldData);

                var workFlow = jsonDataRequest.ClientFieldData.FirstOrDefault(o => o.Name.Equals("changeStatus"));

                var parameters = new Dictionary <string, object>();

                var userName = string.IsNullOrEmpty(viewModel.UserName) ? IDBContext.Current.UserName : viewModel.UserName;
                Logger.GetLogger().WriteDebug("SaveController", "Method: MissionsWorkflow : UserName: "******"StartWorkflow":

                    var workflowCode = jsonDataRequest.ClientFieldData.FirstOrDefault(o => o.Name.Equals("taskTypeCode")).Value;

                    var listAdditionalValidators = viewModel.Validators.Where(a => a.Mandatory == false).Select(x => new { x.Role });
                    var listValidators           = new List <string>();

                    foreach (var validator in listAdditionalValidators)
                    {
                        listValidators.Add(validator.Role);
                    }

                    var listAdditionalValidatorsPresent = listAdditionalValidators.Count() == 0 ? false : true;
                    parameters.Add(K2HelperOpus.AdditionalValidatorsBool, listAdditionalValidatorsPresent);

                    parameters.Add(K2HelperOpus.MissionId, Convert.ToString(viewModel.missionId));

                    parameters.Add(K2HelperOpus.MissionCode, viewModel.missionCode);

                    parameters.Add(K2HelperOpus.StartProfileTM, viewModel.StartProfileTM);

                    var arrayTag = new List <string>();

                    arrayTag.Add("\"MissionID\":" + Convert.ToString(viewModel.missionId));

                    arrayTag.Add("\"AddValidators\":" + (listAdditionalValidators.Count() > 0 ? "\"" + string.Join(",", listValidators) + "\"" : "\"\""));

                    parameters.Add(K2HelperOpus.AddValidators, listAdditionalValidators.Count() > 0 ? string.Join(",", listValidators) : "\"\"");

                    parameters.Add(K2HelperOpus.GeneralTag, "{" + string.Join(",", arrayTag) + "}");

                    parameters.Add(K2HelperOpus.Economic, jsonDataRequest.ClientFieldData.FirstOrDefault(o => o.Name.Equals("Type")).Value.Equals("Economic"));

                    parameters.Add(K2HelperOpus.IsHaiti, jsonDataRequest.ClientFieldData.FirstOrDefault(o => o.Name.Equals("IsHaiti")).Value.Equals("True"));

                    var objetiveMission    = jsonDataRequest.ClientFieldData.FirstOrDefault(o => o.Name.Equals("MissionObjetive")).Value;
                    var objetiveMissionNew = objetiveMission.Replace("\"", "\\\"");
                    parameters.Add(K2HelperOpus.MissionObjetive, objetiveMissionNew);

                    response.IsValid = _k2IntegrationOpus.StartAdvanceWorkflowOpus(workflowCode, "0", operationNumber, K2HelperOpus.entityTypeOpusMission, null, parameters, K2IntegrationEnumerator.GeneralActions.StartWorkflow, 0);

                    if (response.IsValid)
                    {
                        var nextMissionStatus =
                            GetNextMissionStatusByAction(viewModel.missionId, "StartWorkflow");

                        response = _missionService.ChangeMissionStatus(
                            viewModel.missionId, nextMissionStatus);
                    }

                    if (response.IsValid)
                    {
                        response = _missionReportService.GenerationTorMissionReport(viewModel.missionId);
                    }

                    break;

                case "ApproveWorkflow":

                    if (viewModel.IsLastApproved.Equals("sendLastTor"))
                    {
                        parameters.Add(K2HelperOpus.UrlLastDocumentTor, viewModel.UrlDocumentTOR);
                    }

                    response.IsValid = _k2IntegrationOpus.StartAdvanceWorkflowOpus(viewModel.TaskDataModel.Code, viewModel.TaskDataModel.TaskFolio, operationNumber, K2HelperOpus.entityTypeOpusMission, viewModel.TaskDataModel.TaskTypeCode, parameters, K2IntegrationEnumerator.GeneralActions.ApproveWorkflow, viewModel.TaskDataModel.TaskId);

                    if (response.IsValid)
                    {
                        string recipients = Role.TEAM_LEADER + ";" + Role.PROJECT_ASSISTANT;

                        SendEmailToRolesApproveWorkflow(
                            viewModel.TaskDataModel.TaskFolio,
                            viewModel.TaskDataModel.Code,
                            recipients);

                        if (_missionService.IsAdditionalValidator(viewModel.TaskDataModel.UserProfile, viewModel.TaskDataModel.WorkflowInstanceId))
                        {
                            response = _missionService.ChanceAdditionalValidatorStatus(viewModel.TaskDataModel.UserProfile, viewModel.TaskDataModel.WorkflowInstanceId, "Approved");
                        }
                        else if (_missionService.IsLastValidator(viewModel.TaskDataModel.UserProfile, viewModel.TaskDataModel.Code))
                        {
                            var nextMissionStatus = GetNextMissionStatusByAction(
                                viewModel.missionId, "ApproveWorkflow");

                            response = _missionService.ChangeMissionStatus(
                                viewModel.missionId, nextMissionStatus);

                            _missionService.UpdateMilestoneDateAndStatus(
                                operationNumber, viewModel.missionId);
                        }
                    }

                    break;

                case "RejectWorkflow":
                    string missionComments = string.Empty;
                    int    i = 1;
                    foreach (var ObjComment in viewModel.UserComments)
                    {
                        if (i < viewModel.UserComments.Count)
                        {
                            missionComments += ObjComment.Comment + "|";
                        }
                        else
                        {
                            missionComments += ObjComment.Comment;
                        }
                        i++;
                    }

                    if (missionComments.Equals(string.Empty))
                    {
                        missionComments = null;
                    }

                    parameters.Add(K2HelperOpus.MissionComment, missionComments);
                    response.IsValid = _k2IntegrationOpus.StartAdvanceWorkflowOpus(viewModel.TaskDataModel.Code, viewModel.TaskDataModel.TaskFolio, operationNumber, K2HelperOpus.entityTypeOpusMission, viewModel.TaskDataModel.TaskTypeCode, parameters, K2IntegrationEnumerator.GeneralActions.RejectWorkflow, viewModel.TaskDataModel.TaskId);

                    if (response.IsValid)
                    {
                        string recipients = Role.TEAM_LEADER + ";" + Role.PROJECT_ASSISTANT;

                        SendEmailToRolesRejectWorkflow(
                            viewModel.TaskDataModel.TaskFolio,
                            viewModel.TaskDataModel.Code,
                            recipients);

                        var nextMissionStatus = GetNextMissionStatusByAction(
                            viewModel.missionId, "RejectWorkflow");

                        response = _missionService.ChangeMissionStatus(
                            viewModel.missionId, nextMissionStatus);
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                response.IsValid      = false;
                response.ErrorMessage = e.ToString();
            }

            return(Json(response));
        }