public DataTable list() { DBResult ret = DbManager.Query(" ID,ORG_ID,USER_COUNT,CREATEDATETIME,REMARK", "XT_JB_SEND", "", "id desc ", 1, 20); return(ret.dtrows); }
/// <inheritdoc /> public Stream GetComments(DateTime?startDate, DateTime?endDate) { DBResult <IEnumerable <Comment> > comments = this.commentDelegate.GetAll(Page, PageSize); return(GetStream <Comment, CommentCsvMap>(comments.Payload)); }
/// <inheritdoc /> public Stream GetUserProfiles(DateTime?startDate, DateTime?endDate) { DBResult <IEnumerable <UserProfile> > profiles = this.userProfileDelegate.GetAll(Page, PageSize); return(GetStream <UserProfile, UserProfileCsvMap>(profiles.Payload)); }
public static bool IsWaitLock(this DBResult dbResult) { return(dbResult == DBResult.WaitLock); }
public static bool IsSplitPage(this DBResult dbResult) { return(dbResult == DBResult.SplitPage); }
public virtual DBResult Validation() { DBResult dBResult = new DBResult(); List <FieldError> fieldErrors = new List <FieldError>(); Type type = this.GetType(); foreach (var tpi in type.GetProperties()) { var value = tpi.GetValue(this); if (tpi.IsDefined(typeof(Core.Infrastructure.DataTables.Attributes.RequireAttribute))) { if (value == null || string.IsNullOrEmpty(value.ToString())) { var err = tpi.GetCustomAttribute <Core.Infrastructure.DataTables.Attributes.RequireAttribute>(); Core.Infrastructure.DataTables.DtResponse.FieldError fe = new Core.Infrastructure.DataTables.DtResponse.FieldError(); fe.name = tpi.Name; fe.status = err.Msg; fieldErrors.Add(fe); continue; } } if (tpi.IsDefined(typeof(System.ComponentModel.DataAnnotations.MaxLengthAttribute))) { if (value != null || !string.IsNullOrEmpty(value.ToString())) { var max = tpi.GetCustomAttribute <System.ComponentModel.DataAnnotations.MaxLengthAttribute>(); string result = value.ToString(); if (result.Length > max.Length) { Core.Infrastructure.DataTables.DtResponse.FieldError fe = new Core.Infrastructure.DataTables.DtResponse.FieldError(); fe.name = tpi.Name; fe.status = "最大长度定义是:" + max.Length.ToString() + ",字段超出长度定义"; fieldErrors.Add(fe); continue; } } } if (tpi.IsDefined(typeof(System.ComponentModel.DataAnnotations.MinLengthAttribute))) { if (value != null || !string.IsNullOrEmpty(value.ToString())) { var min = tpi.GetCustomAttribute <System.ComponentModel.DataAnnotations.MinLengthAttribute>(); string result = value.ToString(); if (result.Length < min.Length) { Core.Infrastructure.DataTables.DtResponse.FieldError fe = new Core.Infrastructure.DataTables.DtResponse.FieldError(); fe.name = tpi.Name; fe.status = "最小长度定义是:" + min.Length.ToString() + ",字段未达到指定长度"; fieldErrors.Add(fe); continue; } } } } if (fieldErrors.Count > 0) { dBResult.Code = 4000; dBResult.Result = fieldErrors; } return(dBResult); }
public static bool IsError(this DBResult dbResult) { return(dbResult == DBResult.Error); }
/** * Showing an error response from DB */ private void showDBError(DBResult result) { MessageBox.Show(result.ecode.ToString(), "", MessageBoxButtons.OKCancel); }
/// <inheritdoc /> public Stream GetRatings(DateTime?startDate, DateTime?endDate) { DBResult <IEnumerable <Rating> > profiles = this.ratingDelegate.GetAll(Page, PageSize); return(GetStream <Rating, UserProfileCsvMap>(profiles.Payload)); }
public Store(DBResult res) { Name = res.FieldByName(_Column.STName, "").Trim(); BYID = res.FieldByName(_Column.BYId, "").Trim(); DisplayID = BYID; }
internal abstract T genChild(DBResult snapshot);
private IDependentService SetupMockDependentService(AddDependentRequest addDependentRequest, DBResult <UserDelegate> insertResult = null) { var mockPatientService = new Mock <IPatientService>(); RequestResult <string> patientHdIdResult = new RequestResult <string>() { ResultStatus = Common.Constants.ResultType.Success, ResourcePayload = mockHdId }; if (addDependentRequest.PHN.Equals(mockPHN)) { // Test Scenario - Happy Path: HiId found for the mockPHN patientHdIdResult.ResultStatus = Common.Constants.ResultType.Success; patientHdIdResult.ResourcePayload = mockHdId; } RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>(); // Test Scenario - Happy Path: Found HdId for the PHN, Found Patient. patientResult.ResultStatus = Common.Constants.ResultType.Success; patientResult.ResourcePayload = new PatientModel() { HdId = mockHdId, PersonalHealthNumber = mockPHN, FirstName = mockFirstName, LastName = mockLastName, Birthdate = mockDateOfBirth, Gender = mockGender, }; mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult)); UserDelegate expectedDbDependent = new UserDelegate() { DelegateId = mockParentHdId, OwnerId = mockHdId }; if (insertResult == null) { insertResult = new DBResult <UserDelegate> { Status = DBStatusCode.Created }; } insertResult.Payload = expectedDbDependent; Mock <IUserDelegateDelegate> mockDependentDelegate = new Mock <IUserDelegateDelegate>(); mockDependentDelegate.Setup(s => s.Insert(It.Is <UserDelegate>(r => r.DelegateId == expectedDbDependent.DelegateId && r.OwnerId == expectedDbDependent.OwnerId), true)).Returns(insertResult); Mock <IUserProfileDelegate> mockUserProfileDelegate = new Mock <IUserProfileDelegate>(); mockUserProfileDelegate.Setup(s => s.GetUserProfile(mockParentHdId)).Returns(new DBResult <UserProfile>() { Payload = new UserProfile() }); Mock <INotificationSettingsService> mockNotificationSettingsService = new Mock <INotificationSettingsService>(); mockNotificationSettingsService.Setup(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>())); return(new DependentService( new Mock <ILogger <DependentService> >().Object, mockUserProfileDelegate.Object, mockPatientService.Object, mockNotificationSettingsService.Object, mockDependentDelegate.Object )); }
public DBResultClass(DBResult result, string resultMessage) { this.Result = result; ResultMessage = resultMessage; }
/// <inheritdoc /> public async Task <RequestResult <UserProfileModel> > CreateUserProfile(CreateUserRequest createProfileRequest, DateTime jwtAuthTime) { this.logger.LogTrace($"Creating user profile... {JsonSerializer.Serialize(createProfileRequest)}"); string registrationStatus = this.configurationService.GetConfiguration().WebClient.RegistrationStatus; if (registrationStatus == RegistrationStatus.Closed) { this.logger.LogWarning($"Registration is closed. {JsonSerializer.Serialize(createProfileRequest)}"); return(new RequestResult <UserProfileModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Registration is closed", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState), }, }); } // Validate registration age string hdid = createProfileRequest.Profile.HdId; PrimitiveRequestResult <bool> isMimimunAgeResult = await this.ValidateMinimumAge(hdid).ConfigureAwait(true); if (isMimimunAgeResult.ResultStatus != ResultType.Success) { return(new RequestResult <UserProfileModel>() { ResultStatus = isMimimunAgeResult.ResultStatus, ResultError = isMimimunAgeResult.ResultError, }); } else if (!isMimimunAgeResult.ResourcePayload) { this.logger.LogWarning($"Patient under minimum age. {JsonSerializer.Serialize(createProfileRequest)}"); return(new RequestResult <UserProfileModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Patient under minimum age", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState), }, }); } // Create profile UserProfile newProfile = new () { HdId = hdid, IdentityManagementId = createProfileRequest.Profile.IdentityManagementId, AcceptedTermsOfService = createProfileRequest.Profile.AcceptedTermsOfService, Email = string.Empty, SMSNumber = null, CreatedBy = hdid, UpdatedBy = hdid, LastLoginDateTime = jwtAuthTime, EncryptionKey = this.cryptoDelegate.GenerateKey(), }; DBResult <UserProfile> insertResult = this.userProfileDelegate.InsertUserProfile(newProfile); if (insertResult.Status == DBStatusCode.Created) { UserProfile createdProfile = insertResult.Payload; string? requestedSMSNumber = createProfileRequest.Profile.SMSNumber; string? requestedEmail = createProfileRequest.Profile.Email; // Add email verification if (!string.IsNullOrWhiteSpace(requestedEmail)) { this.userEmailService.CreateUserEmail(hdid, requestedEmail); } // Add SMS verification if (!string.IsNullOrWhiteSpace(requestedSMSNumber)) { this.userSMSService.CreateUserSMS(hdid, requestedSMSNumber); } this.notificationSettingsService.QueueNotificationSettings(new NotificationSettingsRequest(createdProfile, requestedEmail, requestedSMSNumber)); this.logger.LogDebug($"Finished creating user profile. {JsonSerializer.Serialize(insertResult)}"); return(new RequestResult <UserProfileModel>() { ResourcePayload = UserProfileModel.CreateFromDbModel(insertResult.Payload), ResultStatus = ResultType.Success, }); } else { this.logger.LogError($"Error creating user profile. {JsonSerializer.Serialize(insertResult)}"); return(new RequestResult <UserProfileModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = insertResult.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database), }, }); } }
/// <inheritdoc /> public RequestResult <DependentModel> AddDependent(string delegateHdId, AddDependentRequest addDependentRequest) { this.logger.LogTrace($"Dependent hdid: {delegateHdId}"); int?maxDependentAge = this.configurationService.GetConfiguration().WebClient.MaxDependentAge; if (maxDependentAge.HasValue) { DateTime minimumBirthDate = DateTime.UtcNow.AddYears(maxDependentAge.Value * -1); if (addDependentRequest.DateOfBirth < minimumBirthDate) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Dependent age exceeds the maximum limit", ErrorCode = ErrorTranslator.ServiceError(ErrorType.InvalidState, ServiceType.Patient) }, }); } } this.logger.LogTrace("Getting dependent details..."); RequestResult <PatientModel> patientResult = Task.Run(async() => await this.patientService.GetPatient(addDependentRequest.PHN, PatientIdentifierType.PHN).ConfigureAwait(true)).Result; if (patientResult.ResultStatus == ResultType.Error) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Communication Exception when trying to retrieve the Dependent", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.Patient) }, }); } if (patientResult.ResultStatus == ResultType.ActionRequired) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.DataMismatch, ActionType.DataMismatch), }); } this.logger.LogDebug($"Finished getting dependent details...{JsonSerializer.Serialize(patientResult)}"); // Verify dependent's details entered by user if (patientResult.ResourcePayload == null || !this.ValidateDependent(addDependentRequest, patientResult.ResourcePayload)) { this.logger.LogDebug($"Dependent information does not match request: {JsonSerializer.Serialize(addDependentRequest)} response: {JsonSerializer.Serialize(patientResult.ResourcePayload)}"); return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.DataMismatch, ActionType.DataMismatch), }); } // Verify dependent has HDID if (string.IsNullOrEmpty(patientResult.ResourcePayload.HdId)) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId), }); } string json = JsonSerializer.Serialize(addDependentRequest.TestDate, addDependentRequest.TestDate.GetType()); JsonDocument jsonDoc = JsonDocument.Parse(json); // Insert Dependent to database var dependent = new ResourceDelegate() { ResourceOwnerHdid = patientResult.ResourcePayload.HdId, ProfileHdid = delegateHdId, ReasonCode = ResourceDelegateReason.COVIDLab, ReasonObjectType = addDependentRequest.TestDate.GetType().AssemblyQualifiedName, ReasonObject = jsonDoc, }; DBResult <ResourceDelegate> dbDependent = this.resourceDelegateDelegate.Insert(dependent, true); if (dbDependent.Status == DBStatusCode.Created) { this.logger.LogTrace("Finished adding dependent"); this.UpdateNotificationSettings(dependent.ResourceOwnerHdid, delegateHdId); return(new RequestResult <DependentModel>() { ResourcePayload = DependentModel.CreateFromModels(dbDependent.Payload, patientResult.ResourcePayload), ResultStatus = ResultType.Success, }); } else { this.logger.LogError("Error adding dependent"); return(new RequestResult <DependentModel>() { ResourcePayload = new DependentModel(), ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = dbDependent.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database) }, }); } }
private void onPlayerLeave(DBResult obj) { data.intoMap.Remove(obj.key()); }
public void DAL_ShouldThrowException_WhenNoParameterGiven() { // SP TestSP_Get_OneParam requires 1 parameter. DBResult result = dAL.ExecuteStoredProcedure("TestSP_Get_OneParam", null); }
/// <inheritdoc /> public RequestResult <DependentModel> AddDependent(string delegateHdId, AddDependentRequest addDependentRequest) { this.logger.LogTrace($"Dependent hdid: {delegateHdId}"); this.logger.LogDebug("Getting dependent details..."); RequestResult <PatientModel> patientResult = Task.Run(async() => await this.patientService.GetPatient(addDependentRequest.PHN, PatientIdentifierType.PHN).ConfigureAwait(true)).Result; if (patientResult.ResourcePayload == null) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Communication Exception when trying to retrieve the Dependent", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.Patient) }, }); } // Verify dependent's details entered by user if (!addDependentRequest.Equals(patientResult.ResourcePayload)) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "The information you entered did not match. Please try again.", ErrorCode = ErrorTranslator.ServiceError(ErrorType.InvalidState, ServiceType.Patient) }, }); } else { // Insert Dependent to database var dependent = new UserDelegate() { OwnerId = patientResult.ResourcePayload.HdId, DelegateId = delegateHdId }; DBResult <UserDelegate> dbDependent = this.userDelegateDelegate.Insert(dependent, true); if (dbDependent.Status == DBStatusCode.Created) { this.logger.LogDebug("Finished adding dependent"); this.UpdateNotificationSettings(dependent.OwnerId, delegateHdId); return(new RequestResult <DependentModel>() { ResourcePayload = DependentModel.CreateFromModels(dbDependent.Payload, patientResult.ResourcePayload), ResultStatus = ResultType.Success, }); } else { this.logger.LogError("Error adding dependent"); return(new RequestResult <DependentModel>() { ResourcePayload = new DependentModel(), ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = dbDependent.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database) }, }); } } }
public void ShouldGetComments() { string encryptionKey = "abc"; DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key); cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length)); List <Comment> commentList = new List <Comment>(); commentList.Add(new Comment { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "First Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 1, 1) }); commentList.Add(new Comment { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "Second Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 2, 2) }); List <UserComment> userCommentList = UserComment.CreateListFromDbModel(commentList, cryptoDelegateMock.Object, encryptionKey).ToList(); DBResult <IEnumerable <Comment> > commentsDBResult = new DBResult <IEnumerable <Comment> > { Payload = commentList, Status = DBStatusCode.Read }; Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>(); commentDelegateMock.Setup(s => s.GetList(hdid, parentEntryId)).Returns(commentsDBResult); ICommentService service = new CommentService( new Mock <ILogger <CommentService> >().Object, commentDelegateMock.Object, profileDelegateMock.Object, cryptoDelegateMock.Object ); RequestResult <IEnumerable <UserComment> > actualResult = service.GetList(hdid, parentEntryId); Assert.Equal(Common.Constants.ResultType.Success, actualResult.ResultStatus); Assert.True(actualResult.ResourcePayload.IsDeepEqual(userCommentList)); }
/// <inheritdoc /> public RequestResult <UserProfileModel> CreateUserProfile(CreateUserRequest createProfileRequest, Uri hostUri, string bearerToken) { this.logger.LogTrace($"Creating user profile... {JsonSerializer.Serialize(createProfileRequest)}"); string registrationStatus = this.configurationService.GetConfiguration().WebClient.RegistrationStatus; RequestResult <UserProfileModel> requestResult = new RequestResult <UserProfileModel>(); if (registrationStatus == RegistrationStatus.Closed) { requestResult.ResultStatus = ResultType.Error; requestResult.ResultError = new RequestResultError() { ResultMessage = "Registration is closed", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState) }; this.logger.LogWarning($"Registration is closed. {JsonSerializer.Serialize(createProfileRequest)}"); return(requestResult); } string hdid = createProfileRequest.Profile.HdId; MessagingVerification?emailInvite = null; if (registrationStatus == RegistrationStatus.InviteOnly) { if (!Guid.TryParse(createProfileRequest.InviteCode, out Guid inviteKey)) { requestResult.ResultStatus = ResultType.Error; requestResult.ResultError = new RequestResultError() { ResultMessage = "Invalid email invite", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState) }; this.logger.LogWarning($"Invalid email invite code. {JsonSerializer.Serialize(createProfileRequest)}"); return(requestResult); } emailInvite = this.emailInviteDelegate.GetByInviteKey(inviteKey); bool hdidIsValid = string.IsNullOrEmpty(emailInvite?.HdId) || (emailInvite?.HdId == createProfileRequest.Profile.HdId); // Fails if... // Email invite not found or // Email invite was already validated or // Email's recipient is not found // Email invite must have a blank/null HDID or be the same as the one in the request // Email address doesn't match the invite if (emailInvite == null || (emailInvite != null && (emailInvite.Email == null || emailInvite.Email.To == null || emailInvite.Validated || !hdidIsValid || !emailInvite.Email.To.Equals(createProfileRequest.Profile.Email, StringComparison.CurrentCultureIgnoreCase)))) { requestResult.ResultStatus = ResultType.Error; requestResult.ResultError = new RequestResultError() { ResultMessage = "Invalid email invite", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState) }; this.logger.LogWarning($"Invalid email invite. {JsonSerializer.Serialize(createProfileRequest)}"); return(requestResult); } } string? requestedSMSNumber = createProfileRequest.Profile.SMSNumber; string? requestedEmail = createProfileRequest.Profile.Email; UserProfile newProfile = createProfileRequest.Profile; newProfile.Email = string.Empty; newProfile.SMSNumber = null; newProfile.CreatedBy = hdid; newProfile.UpdatedBy = hdid; newProfile.EncryptionKey = this.cryptoDelegate.GenerateKey(); DBResult <UserProfile> insertResult = this.userProfileDelegate.InsertUserProfile(newProfile); if (insertResult.Status == DBStatusCode.Created) { // Update the notification settings NotificationSettingsRequest notificationRequest = this.UpdateNotificationSettings(newProfile, requestedSMSNumber); if (emailInvite != null) { // Validates the invite email emailInvite.Validated = true; emailInvite.HdId = hdid; this.emailInviteDelegate.Update(emailInvite); } if (!string.IsNullOrWhiteSpace(requestedEmail)) { this.emailQueueService.QueueNewInviteEmail(hdid, requestedEmail, hostUri); } if (!string.IsNullOrWhiteSpace(requestedSMSNumber)) { this.logger.LogInformation($"Sending sms invite for user ${hdid}"); MessagingVerification messagingVerification = new MessagingVerification(); messagingVerification.HdId = hdid; messagingVerification.SMSNumber = requestedSMSNumber; messagingVerification.SMSValidationCode = notificationRequest.SMSVerificationCode; messagingVerification.VerificationType = MessagingVerificationType.SMS; messagingVerification.ExpireDate = DateTime.MaxValue; this.messageVerificationDelegate.Insert(messagingVerification); } requestResult.ResourcePayload = UserProfileModel.CreateFromDbModel(insertResult.Payload); requestResult.ResultStatus = ResultType.Success; } this.logger.LogDebug($"Finished creating user profile. {JsonSerializer.Serialize(insertResult)}"); return(requestResult); }
public static bool IsSuccess(this DBResult dbResult) { return(dbResult == DBResult.Success); }
private Tuple <RequestResult <IEnumerable <UserComment> >, List <UserComment> > ExecuteGetComments(string encryptionKey = null, Database.Constants.DBStatusCode dbResultStatus = Database.Constants.DBStatusCode.Read) { DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key); cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length)); List <Comment> commentList = new List <Comment>(); commentList.Add(new Comment { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "First Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 1, 1) }); commentList.Add(new Comment { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "Second Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 2, 2) }); List <UserComment> userCommentList = UserComment.CreateListFromDbModel(commentList, cryptoDelegateMock.Object, encryptionKey).ToList(); DBResult <IEnumerable <Comment> > commentsDBResult = new DBResult <IEnumerable <Comment> > { Payload = commentList, Status = dbResultStatus }; Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>(); commentDelegateMock.Setup(s => s.GetByParentEntry(hdid, parentEntryId)).Returns(commentsDBResult); ICommentService service = new CommentService( new Mock <ILogger <CommentService> >().Object, commentDelegateMock.Object, profileDelegateMock.Object, cryptoDelegateMock.Object ); RequestResult <IEnumerable <UserComment> > actualResult = service.GetEntryComments(hdid, parentEntryId); return(new Tuple <RequestResult <IEnumerable <UserComment> >, List <UserComment> >(actualResult, userCommentList)); }
public static bool IsDeadlock(this DBResult dbResult) { return(dbResult == DBResult.DeadLock); }
public TransactionResult <UserVM> BL_GetProfileData(int UserId) { DBResult <DataTable> DBResult = DAL_UserOperations.DAL_GetProfileData(UserId); UserVM userVM; if (DBResult.TransactionResult) { if (DBResult.Data.Rows.Count > 0) { if (string.IsNullOrEmpty(DBResult.Data.Rows[0]["CountryId"].ToString())) { userVM = new UserVM { UserId = Convert.ToInt32(DBResult.Data.Rows[0]["UserId"]), FirstName = DBResult.Data.Rows[0]["FirstName"].ToString(), LastName = DBResult.Data.Rows[0]["LastName"].ToString(), MobileNumber = DBResult.Data.Rows[0]["MobileNumber"].ToString(), Email = DBResult.Data.Rows[0]["Email"].ToString(), CountryId = null, Gender = DBResult.Data.Rows[0]["Gender"].ToString(), LanguageId = DBResult.Data.Rows[0]["LanguageId"].ToString(), Remarks = DBResult.Data.Rows[0]["Remarks"].ToString(), }; } else { userVM = new UserVM { UserId = Convert.ToInt32(DBResult.Data.Rows[0]["UserId"]), FirstName = DBResult.Data.Rows[0]["FirstName"].ToString(), LastName = DBResult.Data.Rows[0]["LastName"].ToString(), MobileNumber = DBResult.Data.Rows[0]["MobileNumber"].ToString(), Email = DBResult.Data.Rows[0]["Email"].ToString(), CountryId = Convert.ToInt32(DBResult.Data.Rows[0]["CountryId"]), Gender = DBResult.Data.Rows[0]["Gender"].ToString(), LanguageId = DBResult.Data.Rows[0]["LanguageId"].ToString(), Remarks = DBResult.Data.Rows[0]["Remarks"].ToString(), }; } foreach (DataRow row in DAL_UserOperations.DAL_GetCountries(UserId).Data.Rows) { userVM.CountryList.Add(new CountryVM { CountryId = Convert.ToInt32(row["CountryId"]), CountryName = row["CountryName"].ToString(), CountryCode = row["CountryCode"].ToString() }); } return(new TransactionResult <UserVM> { Success = true, Data = userVM }); } else { return(new TransactionResult <UserVM> { Success = false, Message = "cannot show user profile. Please try again." }); } } else { return(new TransactionResult <UserVM> { Success = false, Message = "Something went wrong. Please try again." }); } }
public ScacEntry(DBResult res) { ScacCode = res.FieldByName(_Column.PickVal); Description = res.FieldByName(_Column.PickDesc); }
public void ShouldGetNotes() { string encryptionKey = "abc"; DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key); cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length)); List <Note> noteList = new List <Note>(); noteList.Add(new Note { HdId = hdid, Title = "First Note", Text = "First Note text", CreatedDateTime = new DateTime(2020, 1, 1) }); noteList.Add(new Note { HdId = hdid, Title = "Second Note", Text = "Second Note text", CreatedDateTime = new DateTime(2020, 2, 2) }); List <UserNote> userNoteList = UserNote.CreateListFromDbModel(noteList, cryptoDelegateMock.Object, encryptionKey).ToList(); DBResult <IEnumerable <Note> > notesDBResult = new DBResult <IEnumerable <Note> > { Payload = noteList, Status = Database.Constants.DBStatusCode.Read }; Mock <INoteDelegate> noteDelegateMock = new Mock <INoteDelegate>(); noteDelegateMock.Setup(s => s.GetNotes(hdid, 0, 500)).Returns(notesDBResult); INoteService service = new NoteService( new Mock <ILogger <NoteService> >().Object, noteDelegateMock.Object, profileDelegateMock.Object, cryptoDelegateMock.Object ); RequestResult <IEnumerable <UserNote> > actualResult = service.GetNotes(hdid, 0, 500); Assert.Equal(Common.Constants.ResultType.Success, actualResult.ResultStatus); Assert.True(actualResult.ResourcePayload.IsDeepEqual(userNoteList)); }
/// <inheritdoc /> public Stream GetNotes(DateTime?startDate, DateTime?endDate) { DBResult <IEnumerable <Note> > notes = this.noteDelegate.GetAll(Page, PageSize); return(GetStream <Note, NoteCsvMap>(notes.Payload)); }
public void AddPosition(DBResult position) { positions.Add(position); }
protected override CoreResponse Edit(CoreRequest core_request) { CoreResponse core_response = new CoreResponse(core_request); //UserDTO loginsession = Newtonsoft.Json.JsonConvert.DeserializeObject<UserDTO>(core_request.HttpContext.Session.GetString("User")); foreach (var item in core_request.DtRequest.Data) { string key = item.Key; List <Dictionary <string, object> > list_pair = new List <Dictionary <string, object> >(); var pair = item.Value as Dictionary <string, object>; UserMenuRoleDTO orgin; orgin = new UserMenuRoleDTO(); base.ConvertDictionaryToObject(orgin, pair, core_response.DtResponse.fieldErrors); if (core_response.DtResponse.fieldErrors != null && core_response.DtResponse.fieldErrors.Count > 0) { return(core_response); } if (orgin.Contents == null) { var deleteIds = this.GetAll().Where(t => t.UserId == orgin.UserId).Select(t => t.Id).ToArray(); DBResult dbresult = this.BatchDelete(d => deleteIds.Contains(d.Id)); if (dbresult.Code != 0) { core_response.DtResponse.error += dbresult.ErrMsg; } } else { DBResult dbresult; //orgin.CreateTime = DateTime.Now; orgin.Creator = "123"; List <UserMenuRoleDTO> userDataRoleDTOs = new List <UserMenuRoleDTO>(); var validData = orgin.Contents.Where(t => t.ContentId.Contains("D#")); foreach (var warehouse in validData) { var data = orgin.Clone() as UserMenuRoleDTO; data.Content = warehouse.ContentId.Replace("D#", ""); userDataRoleDTOs.Add(data); } if (userDataRoleDTOs.Count == 0) { core_response.DtResponse.error += "请选择具体货主部门权限!"; } else { var deleteIds = this.GetAll().Where(t => t.UserId == orgin.UserId).Select(t => t.Id).ToArray(); dbresult = this.BatchDelete(d => deleteIds.Contains(d.Id)); if (dbresult.Code != 0) { core_response.DtResponse.error += dbresult.ErrMsg; } else { dbresult = this.AddRange(userDataRoleDTOs.ToArray()); if (dbresult.Code != 0) { core_response.DtResponse.error += dbresult.ErrMsg; } } } } } return(core_response); }
public void ShouldGetUserProfile() { UserProfile userProfile = new UserProfile { HdId = hdid, AcceptedTermsOfService = true, }; DBResult <UserProfile> userProfileDBResult = new DBResult <UserProfile> { Payload = userProfile, Status = DBStatusCode.Read }; UserProfileModel expected = UserProfileModel.CreateFromDbModel(userProfile); LegalAgreement termsOfService = new LegalAgreement() { Id = Guid.NewGuid(), LegalText = "", EffectiveDate = DateTime.Now }; Mock <IEmailQueueService> emailer = new Mock <IEmailQueueService>(); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(userProfileDBResult); profileDelegateMock.Setup(s => s.Update(userProfile, true)).Returns(userProfileDBResult); UserPreference dbUserPreference = new UserPreference { HdId = hdid, Preference = "TutorialPopover", Value = true.ToString(), }; List <UserPreference> userPreferences = new List <UserPreference>(); userPreferences.Add(dbUserPreference); DBResult <IEnumerable <UserPreference> > readResult = new DBResult <IEnumerable <UserPreference> > { Payload = userPreferences, Status = DBStatusCode.Read }; Mock <IUserPreferenceDelegate> preferenceDelegateMock = new Mock <IUserPreferenceDelegate>(); preferenceDelegateMock.Setup(s => s.GetUserPreferences(hdid)).Returns(readResult); Mock <IEmailDelegate> emailDelegateMock = new Mock <IEmailDelegate>(); Mock <IMessagingVerificationDelegate> emailInviteDelegateMock = new Mock <IMessagingVerificationDelegate>(); emailInviteDelegateMock.Setup(s => s.GetByInviteKey(It.IsAny <Guid>())).Returns(new MessagingVerification()); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); configServiceMock.Setup(s => s.GetConfiguration()).Returns(new ExternalConfiguration()); Mock <ILegalAgreementDelegate> legalAgreementDelegateMock = new Mock <ILegalAgreementDelegate>(); legalAgreementDelegateMock .Setup(s => s.GetActiveByAgreementType(AgreementType.TermsofService)) .Returns(new DBResult <LegalAgreement>() { Payload = termsOfService }); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); Mock <IMessagingVerificationDelegate> messageVerificationDelegateMock = new Mock <IMessagingVerificationDelegate>(); IUserProfileService service = new UserProfileService( new Mock <ILogger <UserProfileService> >().Object, profileDelegateMock.Object, preferenceDelegateMock.Object, emailDelegateMock.Object, emailInviteDelegateMock.Object, configServiceMock.Object, emailer.Object, legalAgreementDelegateMock.Object, cryptoDelegateMock.Object, notificationServiceMock.Object, messageVerificationDelegateMock.Object); RequestResult <UserProfileModel> actualResult = service.GetUserProfile(hdid); Assert.Equal(ResultType.Success, actualResult.ResultStatus); Assert.True(actualResult.ResourcePayload.IsDeepEqual(expected)); }