private ACSession ConvertDto(ACSessionDTO sessionDTO, ACSession instance) { instance = instance ?? new ACSession(); instance.IncludeAcEmails = sessionDTO.includeACEmails; instance.AccountId = sessionDTO.accountId; instance.MeetingUrl = sessionDTO.meetingURL; if (instance.IsTransient()) { instance.DateCreated = DateTime.Now; } instance.ScoId = sessionDTO.scoId; try { instance.Status = (ACSessionStatusEnum)sessionDTO.status; } catch (Exception) { instance.Status = instance.IsTransient() ? ACSessionStatusEnum.Created : ACSessionStatusEnum.Played; } instance.Language = this.LanguageModel.GetOneById(sessionDTO.languageId).Value; instance.SubModuleItem = this.SubModuleItemModel.GetOneById(sessionDTO.subModuleItemId).Value; instance.ACUserMode = this.ACUserModeModel.GetOneById(sessionDTO.acUserModeId).Value; instance.User = this.UserModel.GetOneById(sessionDTO.userId).Value; return(instance); }
public ACSessionDTO Save(ACSessionDTO session) { if (session == null) { throw new ArgumentNullException(nameof(session)); } try { ValidationResult validationResult; if (IsValid(session, out validationResult)) { ACSessionModel sessionModel = this.ACSessionModel; bool isTransient = session.acSessionId == 0; ACSession sessionInstance = isTransient ? null : sessionModel.GetOneById(session.acSessionId).Value; sessionInstance = this.ConvertDto(session, sessionInstance); sessionModel.RegisterSave(sessionInstance, true); return(new ACSessionDTO(sessionInstance)); } var error = this.GenerateValidationError(validationResult); this.LogError("ACSession.Save", error); throw new FaultException <Error>(error, error.errorMessage); } catch (Exception ex) { Logger.Error("ACSession.Save", ex); throw; } }
public async Task SaveAll(TestSummaryResultDTO testResult) { if (testResult == null) { throw new ArgumentNullException(nameof(testResult)); } if (testResult.testResults == null) { testResult.testResults = new TestResultDTO[0]; } try { if (!IsValid(testResult, out var valResult)) { return; } Test test = TestModel.GetOneById(testResult.testId).Value; ACSession acSession = ACSessionModel.GetOneById(testResult.acSessionId).Value; if (acSession == null) { throw new ArgumentException($"There are not session with acSessionId : {testResult.acSessionId}"); } int acSessionId = acSession.Id; foreach (var appletResultDTO in testResult.testResults) { appletResultDTO.acSessionId = testResult.acSessionId; if (IsValid(appletResultDTO, out var validationResult)) { var appletResult = ConvertDto(appletResultDTO, test, acSessionId); TestResultModel.RegisterSave(appletResult); if (appletResultDTO.results != null) { SaveAll(appletResult, appletResultDTO.results); } } } } catch (ArgumentException ex) { Logger.Error("TestResultService.SaveAll: ", ex); throw; } catch (Exception ex) { Logger.Error($"TestResultService.SaveAll json={JsonConvert.SerializeObject(testResult)}", ex); throw; } }
public async Task SaveAll(SurveySummaryResultDTO sResult) { if (sResult == null) { throw new ArgumentNullException(nameof(sResult)); } if (sResult.surveyResults == null) { sResult.surveyResults = new SurveyResultDTO[0]; } try { if (!IsValid(sResult, out ValidationResult valResult)) { return; } Survey survey = SurveyModel.GetOneById(sResult.surveyId).Value; ACSession acSession = ACSessionModel.GetOneById(sResult.acSessionId).Value; if (acSession == null) { throw new ArgumentException($"There are not session with acSessionId : {sResult.acSessionId}"); } int acSessionId = acSession.Id; foreach (var surveyResultDTO in sResult.surveyResults) { surveyResultDTO.acSessionId = sResult.acSessionId; if (IsValid(surveyResultDTO, out ValidationResult validationResult)) { var surveyResult = ConvertDto(surveyResultDTO, survey, acSessionId); SurveyResultModel.RegisterSave(surveyResult); if (surveyResultDTO.results != null) { await SaveAllAsync(surveyResult, surveyResultDTO.results); } } } } catch (ArgumentException ex) { Logger.Error("SurveyResultService.SaveAll: ", ex); throw; } catch (Exception ex) { Logger.Error($"SurveyResultService.SaveAll json={JsonConvert.SerializeObject(sResult)}", ex); throw; } }
/// <summary> /// Initializes a new instance of the <see cref="ACSessionDTO"/> class. /// </summary> /// <param name="result"> /// The result. /// </param> public ACSessionDTO(ACSession result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } this.acSessionId = result.Id; this.subModuleItemId = result.SubModuleItem.With(x => x.Id); this.acUserModeId = result.ACUserMode.With(x => x.Id); this.userId = result.User.With(x => x.Id); this.languageId = result.Language.With(x => x.Id); this.accountId = result.AccountId; this.meetingURL = result.MeetingUrl; this.scoId = result.ScoId; this.dateCreated = result.DateCreated.With(x => x.ConvertToUnixTimestamp()); this.status = (int)result.Status; this.includeACEmails = result.IncludeAcEmails ?? false; }
public async Task <OperationResultDto> SaveAll(QuizSummaryResultDTO quizResult) { if (quizResult == null) { Logger.Fatal("QuizResultService.SaveAll: ArgumentNullException for quizResult"); throw new ArgumentNullException(nameof(quizResult)); } if (quizResult.quizResults == null) { quizResult.quizResults = new QuizResultDTO[0]; } Logger.Info($"QuizResultService.SaveAll Start: AcSessionId {quizResult.acSessionId}, quizId : {quizResult.quizId}, companyId : {quizResult.companyId}, Count : {quizResult.quizResults.Length}"); IList <string> errorMessages = new List <string>(); try { //TRICK to get eventQuizMappingId var eventQuizMappingId = GetEventQuizMappingId(quizResult); // Quiz quiz = QuizModel.GetOneById(quizResult.quizId).Value; ACSession acSession = ACSessionModel.GetOneById(quizResult.acSessionId).Value; if (acSession == null) { throw new ArgumentException($"There are not session with acSessionId : {quizResult.acSessionId}"); } int acSessionId = acSession.Id; CompanyEventQuizMapping companyEventQuizMapping = null; if (eventQuizMappingId.HasValue && eventQuizMappingId.Value != 0) { companyEventQuizMapping = EventQuizMappingModel.GetOneById(eventQuizMappingId.Value).Value; } if (!IsValid(quizResult, out ValidationResult validationSummaryDtoResult)) { errorMessages = UpdateResultToShortString(validationSummaryDtoResult); return(OperationResultDto.Error(string.Join(";", errorMessages))); } foreach (var appletResultDTO in quizResult.quizResults) { appletResultDTO.acSessionId = quizResult.acSessionId; if (IsValid(appletResultDTO, out ValidationResult validationResult)) { var appletResult = ConvertDto(appletResultDTO, quiz, acSessionId, companyEventQuizMapping); QuizResultModel.RegisterSave(appletResult); if (appletResultDTO.results != null) { await SaveAllAsync(appletResult, appletResultDTO.results); } } else { errorMessages.AddRange(UpdateResultToShortString(validationResult)); } } } catch (ArgumentException ex) { Logger.Error("QuizResultService.SaveAll:", ex); throw; } catch (Exception ex) { Logger.Error($"QuizResultService.SaveAll json={JsonConvert.SerializeObject(quizResult)}", ex); throw; } return(errorMessages.Any() ? OperationResultDto.Error(string.Join(";", errorMessages)) : OperationResultDto.Success()); }