public static CorrectiveAction MapToUIModelOnCreate(CorrectiveActionFormViewModel vm, string[] selectedErrorTypes) { var logSnippet = "[CorrectiveActionUtil][MapToUIModelOnCreate] => "; CorrectiveAction newCorrectiveAction = new CorrectiveAction { Id = vm.CorrectiveActionId, ActionRequestTypeId = Int32.Parse(vm.ActionRequestTypeId), EmplId = CorrectiveActionUtil.ExtractEmplId(vm.EmployeeSearchResult), Employee = null, // CorrectiveActionService will hydrate this object NOACode = vm.NatureOfAction, NatureOfAction = new ReferenceService().RetrieveNatureOfAction(vm.NatureOfAction), EffectiveDateOfPar = (DateTime)vm.EffectiveDateOfPar, IsPaymentMismatch = vm.IsPaymentMismatch, Details = vm.Details, ActionId = Int32.Parse(vm.StatusTypeId) }; Console.WriteLine(logSnippet + $"(vm.CorrectiveActionId): '{vm.CorrectiveActionId}' / (vm.NatureOfAction): '{vm.NatureOfAction}'"); Console.WriteLine(logSnippet + "(newCorrectiveAction.NatureOfAction == null): " + (newCorrectiveAction.NatureOfAction == null)); if (newCorrectiveAction.NatureOfAction != null) { Console.WriteLine(logSnippet + $"(newCorrectiveAction.NatureOfAction.NoaCode): '{newCorrectiveAction.NatureOfAction.NoaCode}' / (newCorrectiveAction.NatureOfAction.RoutesToBr): '{newCorrectiveAction.NatureOfAction.RoutesToBr}'"); } ErrorTypeDictionary errorTypeDict = new ErrorTypeDictionary(); foreach (var errorTypeId in selectedErrorTypes) { newCorrectiveAction.ErrorTypes.Add(errorTypeDict.GetErrorType(Int32.Parse(errorTypeId))); } return(newCorrectiveAction); }
public static CorrectiveAction MapToUIModelOnUpdate(CorrectiveActionFormViewModel vm, string[] selectedErrorTypes, CorrectiveAction existingCA) { var logSnippet = "[CorrectiveActionUtil][MapToUIModelOnUpdate] => "; Console.WriteLine(logSnippet + $"(vm.Details): '{vm.Details}'"); existingCA.EmplId = CorrectiveActionUtil.ExtractEmplId(vm.EmployeeSearchResult); existingCA.Employee = null; // CorrectiveActionService will hydrate this object existingCA.NOACode = vm.NatureOfAction; existingCA.NatureOfAction = new ReferenceService().RetrieveNatureOfAction(vm.NatureOfAction); existingCA.EffectiveDateOfPar = (DateTime)vm.EffectiveDateOfPar; existingCA.IsPaymentMismatch = vm.IsPaymentMismatch; existingCA.ActionId = Int32.Parse(vm.StatusTypeId); existingCA.RowVersion = vm.RowVersion; existingCA.ActionRequestTypeId = int.Parse(vm.ActionRequestTypeId); existingCA.Details = vm.Details; if (vm.AssignedToUserId.HasValue) { existingCA.AssignedToUserId = vm.AssignedToUserId; } Console.WriteLine(logSnippet + $"(existingCA.Id): '{existingCA.Id}' / (existingCA.NatureOfAction): '{existingCA.NatureOfAction}'"); Console.WriteLine(logSnippet + "(existingCA.NatureOfAction == null): " + (existingCA.NatureOfAction == null)); if (existingCA.NatureOfAction != null) { Console.WriteLine(logSnippet + $"(existingCA.NatureOfAction.NoaCode): '{existingCA.NatureOfAction.NoaCode}' / (existingCA.NatureOfAction.RoutesToBr): '{existingCA.NatureOfAction.RoutesToBr}'"); } ErrorTypeDictionary errorTypeDict = new ErrorTypeDictionary(); existingCA.ErrorTypes = new List <ErrorType>(); foreach (var errorTypeId in selectedErrorTypes) { existingCA.ErrorTypes.Add(errorTypeDict.GetErrorType(Int32.Parse(errorTypeId))); } return(existingCA); }