private static void SetDefaultValuesToGeneralNonCore(PCRGeneralViewModel generalsViewModel)
        {
            foreach (var general in generalsViewModel.PCRGeneralViewModelList)
            {
                switch (generalsViewModel.CurrentStageType)
                {
                case PCRStageTypeEnum.TeamLeaderPreValidationStage:
                    if (!general.IsCore)
                    {
                        general.ScoreBasedOnTeamLeaderPreValidation = 0;
                        if (general.PCRGeneralType == IDB.MW.Domain.Values.PCRGeneralTypeEnum.EnvironmentalAndSocialSafeguards)
                        {
                            general.ScoreBasedOnTeamLeaderPreValidation = null;
                        }
                    }

                    break;

                case PCRStageTypeEnum.SPDPreValidationStage:
                    if (!general.IsCore)
                    {
                        general.ScoreBasedOnSPDPreValidation = general.ScoreBasedOnTeamLeaderPreValidation;
                        if (general.PCRGeneralType == IDB.MW.Domain.Values.PCRGeneralTypeEnum.EnvironmentalAndSocialSafeguards)
                        {
                            general.ScoreBasedOnSPDPreValidation = null;
                        }
                    }

                    break;

                case PCRStageTypeEnum.TeamLeaderValidationStage:
                    if (!general.IsCore)
                    {
                        general.ScoreBasedOnTeamLeaderValidation = general.ScoreBasedOnSPDPreValidation;
                        if (general.PCRGeneralType == IDB.MW.Domain.Values.PCRGeneralTypeEnum.EnvironmentalAndSocialSafeguards)
                        {
                            general.ScoreBasedOnTeamLeaderValidation = null;
                        }
                    }

                    break;

                default:
                    if (!general.IsCore)
                    {
                        general.ScoreBasedOnSPDValidation = general.ScoreBasedOnTeamLeaderValidation;
                        if (general.PCRGeneralType == IDB.MW.Domain.Values.PCRGeneralTypeEnum.EnvironmentalAndSocialSafeguards)
                        {
                            general.ScoreBasedOnSPDValidation = null;
                        }
                    }

                    break;
                }
            }
        }
        public static void UpdatePCRGeneralViewModel(this PCRGeneralViewModel generalsViewModel, ClientFieldData[] clientFieldData)
        {
            // set default value to general non core (last stage value or "N/A"), later if have value change it.
            SetDefaultValuesToGeneralNonCore(generalsViewModel);

            foreach (var generalFields in clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Id)).GroupBy(x => x.Id))
            {
                var scoreFieldId = Convert.ToInt32(generalFields.Key);

                var scoreField = generalFields.FirstOrDefault(x => x.Name.Contains("cboScore"));

                decimal?scoreValue = null;
                if (scoreField != null)
                {
                    scoreValue = !string.IsNullOrWhiteSpace(scoreField.Value) ? (decimal?)Convert.ToDecimal(scoreField.Value) : null;
                }

                var commentField = generalFields.FirstOrDefault(x => x.Name.Contains("txtCoreCriteriaComment") || x.Name.Contains("txtNonCoreCriteriaComment"));
                var general      = generalsViewModel.PCRGeneralViewModelList.First(x => x.PCRGeneralId == scoreFieldId);

                switch (generalsViewModel.CurrentStageType)
                {
                case PCRStageTypeEnum.TeamLeaderPreValidationStage:
                    general.ScoreBasedOnTeamLeaderPreValidation = scoreValue;
                    break;

                case PCRStageTypeEnum.SPDPreValidationStage:
                    general.ScoreBasedOnSPDPreValidation = scoreValue;
                    break;

                case PCRStageTypeEnum.TeamLeaderValidationStage:
                    general.ScoreBasedOnTeamLeaderValidation = scoreValue;
                    break;

                case PCRStageTypeEnum.SPDValidationStage:
                    general.ScoreBasedOnSPDValidation = scoreValue;
                    break;
                }

                if (commentField != null)
                {
                    var commentId = int.Parse(commentField.ExtraData.FirstOrDefault(x => x.Key == "data-persist-id").Value);
                    if (commentId != 0)
                    {
                        var viewModel = general.CommentList.First(x => x.CommentId == commentId);

                        //Update comment
                        if (viewModel.Comment != commentField.Value)
                        {
                            viewModel.Comment = commentField.Value;
                            viewModel.Date    = DateTime.Now;
                        }
                    }
                    else if (!string.IsNullOrWhiteSpace(commentField.Value))
                    {
                        //Add new comment
                        var newComment = new GeneralUserComment
                        {
                            Comment             = commentField.Value,
                            Date                = DateTime.Now,
                            PCRGeneralStageType = generalsViewModel.CurrentStageType
                        };

                        general.CommentList.Add(newComment);
                    }
                }
            }
        }