/// <summary> /// Get Completed Checklists For A Selected Date Range /// </summary> /// <param name="checklistDataRequest"></param> /// <returns></returns> public string GetCompletedChecklistsForADateRange(ChecklistDataRequestViewModel checklistDataRequest) { try { ChecklistDataRequest request = BusinessMapper.MappingOpenChecklistViewModelToBusinessModel(checklistDataRequest); List <ChecklistDataResponse> checklistDataList = _pendingChecklistRepository.GetChecklistsForADateRange(request); ChecklistDataResponse[] checklistDataArray = checklistDataList.ToArray(); List <IDictionary <string, object> > pivotArray = checklistDataArray.ToPivotArray(item => item.EffectiveDate, item => item.RowSelector, items => items.Any() ? items.First().Answer : new AnswerResponse() { SubmittedResponse = "--" }); foreach (IDictionary <string, object> ele in pivotArray) { ChecklistDataResponse result = checklistDataList.First(c => c.RowSelector == (ele.ContainsKey("RowSelector") ? (string)ele["RowSelector"] : string.Empty)); if (result != null) { ele.Add("ChecklistName", result.ChecklistName); ele.Add("QuestionText", result.QuestionText); } } String json = JsonConvert.SerializeObject(pivotArray, new KeyValuePairConverter()); return(json); } catch (Exception ex) { _logger.Log(ex, LogLevel.Error, ex.Message); return(null); } }
/// <summary> /// Open the selected checklist i.e., Make checklist status as pending /// </summary> /// <param name="checklistDataRequest"></param> /// <returns></returns> public ValidationViewModel OpenChecklist(ChecklistDataRequestViewModel checklistDataRequest) { BusinessResponse businessResponse = new BusinessResponse(); try { ChecklistDataRequest request = BusinessMapper.MappingOpenChecklistViewModelToBusinessModel(checklistDataRequest); businessResponse.IsSuccess = _pendingChecklistRepository.OpenChecklist(request); if (businessResponse.IsSuccess) { businessResponse.Messages.Add(new MessageDTO() { Message = BusinessConstants.CHECKLIST_OPEN_SUCCESS, MessageType = Infrastructure.Enums.MessageType.Info }); } else { businessResponse.Messages.Add(new MessageDTO() { Message = BusinessConstants.CHECKLIST_OPEN_FAIL, MessageType = Infrastructure.Enums.MessageType.Error }); } return(businessResponse.ToValidationViewModel()); } catch (Exception ex) { businessResponse.IsSuccess = false; businessResponse.IsExceptionOccured = true; businessResponse.Messages.Add(new MessageDTO() { Message = BusinessConstants.CHECKLIST_OPEN_FAIL, MessageType = Infrastructure.Enums.MessageType.Error }); _logger.Log(ex, LogLevel.Error, ex.Message); return(businessResponse.ToValidationViewModel()); } }