private static void SetAllTasksCurrentFieldToFalse(PCRFollowUpViewModel pcrFollowUpViewModel) { var taskChange = pcrFollowUpViewModel.Tasks.Where(x => x.IsCurrent); foreach (var taskTemp in taskChange) { taskTemp.IsCurrent = false; } }
public static void UpdateFollowUp( this PCRFollowUpViewModel pcrFollowUpViewModel, ClientFieldData[] clientFieldData, int currentTask) { //Tasks var completedDate = clientFieldData.FirstOrDefault( x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("txtCompletedDate")); completedDate = GetDate(completedDate); var editPCRCorrd = clientFieldData.FirstOrDefault( x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("editpcrcoord")); var chkActive = clientFieldData.Where( x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("chkActive")); var cultureInfo = new CultureInfo("en-US"); if (completedDate == null || string.IsNullOrEmpty(completedDate.Value)) { if (pcrFollowUpViewModel.Tasks.Any(t => t.IsActive && (t.TaskNumber == 8 || t.TaskNumber == 2))) { pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask).IsCurrent = false; if (currentTask == 7 || currentTask == 1) { currentTask++; } if (currentTask == 3) { currentTask--; } pcrFollowUpViewModel.Header.CurrentTask = currentTask; pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask).IsCurrent = true; } } var documentIndex = 0; switch (currentTask) { case 2: case 8: var taskExtension = (PCRFollowUpTaskExtensionViewModel)pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask); var approvedBy = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("approvedBy")); var extensionReason = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("txtExtensionReason")); var updatedDeadLine = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("txtUpdatedDeadLineDate")); updatedDeadLine = GetDate(updatedDeadLine); if (approvedBy != null && !string.IsNullOrWhiteSpace(approvedBy.Value)) { taskExtension.ApprovedBy = approvedBy.Value; } if (extensionReason != null && !string.IsNullOrWhiteSpace(extensionReason.Value)) { taskExtension.Reason = extensionReason.Value; } if (updatedDeadLine != null && !string.IsNullOrWhiteSpace(updatedDeadLine.Value)) { taskExtension.UpdatedDeadline = DateTime.ParseExact(updatedDeadLine.Value, Format, cultureInfo); } break; case 12: var task12 = (PCRFollowUpTask12ViewModel)pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask); var isCommentSent = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("isCommentSent")); var isWorkshopConducted = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("isWorkshopConducted")); var workshopDate = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("txtWorkshopDate")); if (isCommentSent != null && !string.IsNullOrWhiteSpace(isCommentSent.Value)) { task12.IsCommentSent = isCommentSent.Value == "Yes"; } if (isWorkshopConducted != null && !string.IsNullOrWhiteSpace(isWorkshopConducted.Value)) { task12.IsWorkshopConducted = isWorkshopConducted.Value == "Yes"; } if (workshopDate != null && !string.IsNullOrWhiteSpace(workshopDate.Value)) { task12.WorkshopDate = DateTime.ParseExact(GetDate(workshopDate).Value, Format, cultureInfo); } if (completedDate != null && !string.IsNullOrWhiteSpace(completedDate.Value)) { task12.CompletedDate = DateTime.ParseExact(completedDate.Value, Format, cultureInfo); } //Deleted Tasks 13, 15, 19 y 20 if (task12.IsCommentSent.HasValue && !task12.IsCommentSent.Value) { var task13 = (PCRFollowUpTaskBaseViewModel)pcrFollowUpViewModel.Tasks.FirstOrDefault(x => x.TaskNumber == 13); if (task13 != null) { task13.IsDeleted = true; } var task15 = (PCRFollowUpTaskBaseViewModel)pcrFollowUpViewModel.Tasks.FirstOrDefault(x => x.TaskNumber == 15); if (task15 != null) { task15.IsDeleted = true; } var task19 = (PCRFollowUpTaskBaseViewModel)pcrFollowUpViewModel.Tasks.FirstOrDefault(x => x.TaskNumber == 19); if (task19 != null) { task19.IsDeleted = true; } var task20n = (PCRFollowUpTaskBaseViewModel)pcrFollowUpViewModel.Tasks.FirstOrDefault(x => x.TaskNumber == 20); if (task20n != null) { task20n.IsDeleted = true; } } SetAllTasksCurrentFieldToFalse(pcrFollowUpViewModel); task12.IsCurrent = true; break; case 20: var task20 = (PCRFollowUpTask20ViewModel)pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask); var isDisclosure = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("isDisclosure")); if (isDisclosure != null && !string.IsNullOrWhiteSpace(isDisclosure.Value)) { task20.IsDisclosure = isDisclosure.Value == "Yes"; } if (completedDate != null && !string.IsNullOrWhiteSpace(completedDate.Value)) { task20.CompletedDate = DateTime.ParseExact(completedDate.Value, Format, cultureInfo); } //Deleted Task 21 if (task20.IsDisclosure.HasValue && !task20.IsDisclosure.Value) { var task21 = (PCRFollowUpTaskBaseViewModel)pcrFollowUpViewModel.Tasks.FirstOrDefault(x => x.TaskNumber == 21); if (task21 != null) { task21.IsDeleted = true; } } SetAllTasksCurrentFieldToFalse(pcrFollowUpViewModel); task20.IsCurrent = true; break; default: SetAllTasksCurrentFieldToFalse(pcrFollowUpViewModel); var taskChange = pcrFollowUpViewModel.Tasks.Where(x => x.IsCurrent); foreach (var taskTemp in taskChange) { taskTemp.IsCurrent = false; } var task = pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask); task.IsCurrent = true; if (completedDate != null && !string.IsNullOrWhiteSpace(completedDate.Value)) { if (completedDate.Value != string.Empty) { task.CompletedDate = DateTime.ParseExact(completedDate.Value, Format, cultureInfo); } } break; } if (editPCRCorrd != null) { var taskTemp = pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == currentTask); taskTemp.IsEditPcrCoord = true; } //Add Tasks 2 or 8 foreach (var taskCheck in chkActive.Where(task => task.Value == "True").Select(task => (PCRFollowUpTaskExtensionViewModel)pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == int.Parse(task.Id))).Where(taskCheck => !taskCheck.IsActive)) { taskCheck.IsNew = true; } //Deleted Tasks 2 or 8 foreach (var taskCheck in chkActive.Where(task => task.Value == "False").Select(task => (PCRFollowUpTaskExtensionViewModel)pcrFollowUpViewModel.Tasks.First(x => x.TaskNumber == int.Parse(task.Id))).Where(taskCheck => !taskCheck.IsNew && taskCheck.IsActive)) { taskCheck.IsDeleted = true; } //Workflow Status var isRequired = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("isRequired")); if (isRequired != null && !string.IsNullOrWhiteSpace(isRequired.Value)) { pcrFollowUpViewModel.IsRequired = isRequired.Value == "Yes"; } if (isRequired != null && isRequired.Value == "No" && currentTask == 1) { var commentNotRequired = clientFieldData.FirstOrDefault( x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("txtNotRequiredReason")); if (pcrFollowUpViewModel.NotRequiredComment == null) { pcrFollowUpViewModel.NotRequiredComment = new PCRNotRequiredUserComment { Comment = commentNotRequired.Value.ToString(), CommentId = 0, OperationId = pcrFollowUpViewModel.OperationId }; } else { pcrFollowUpViewModel.NotRequiredComment.Comment = commentNotRequired.Value.ToString(); } } var seriesCode = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("seriesCode")); if (seriesCode != null && !string.IsNullOrWhiteSpace(seriesCode.Value)) { pcrFollowUpViewModel.SeriesCode = seriesCode.Value; } var isLastInSeries = clientFieldData.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("isLastInSeries")); if (isLastInSeries != null && !string.IsNullOrWhiteSpace(isLastInSeries.Value)) { pcrFollowUpViewModel.IsLastInSeries = isLastInSeries.Value == "Yes"; } //Add, Remove and Update Documents var documentDescription = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("documentDescription")); var documentNumber = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("documentNumber")); var documentsToDelete = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("deleteDocument")); foreach (var document in documentDescription) { if (document.Value == "Select your option") { document.Value = null; } if (document.Id != string.Empty) { var documentOld = pcrFollowUpViewModel.Documents.FirstOrDefault(x => x.DocumentId == int.Parse(document.Id)); if (documentOld != null) { documentOld.Description = document.Value; } var documentToDelete = documentsToDelete.FirstOrDefault(x => x.Id == document.Id); if (documentToDelete != null) { if (documentToDelete.Value == "yes") { pcrFollowUpViewModel.Documents.Remove(documentOld); } } } else if (document.Id == string.Empty) { var documentNumberValue = documentNumber.ToArray()[documentIndex].Value; pcrFollowUpViewModel.Documents.Add( new PCRDocumentViewModel { Description = document.Value, DocumentNumber = documentNumberValue }); documentIndex++; } } }