using BuddyFinance.Integration.Models; using BuddyFinance.Integration.Models.Scoring; using System; using System.Collections.Generic; using System.Linq; using BuddyFinance.Common.Encryption; namespace BuddyFinance.Integration.Mappers { public static class Profiles { public static Models.Profiles.Profile MapFromModel(BuddyFinance.Model.Profile profile, bool minimal = false) { var returnProfile = new Models.Profiles.Profile { ProfileId = profile.Id, ProfileId_ = profile.Id.ToEncryptedString(), ProfileNumber = profile.ProfileNumber, LendServiceAccount = profile.LendServiceAccount.GetValueOrDefault(), BorrowServiceAccount = profile.BorrowServiceAccount.GetValueOrDefault(), Title = profile.Title, Name = profile.Name, Surname = profile.Surname, ContactNumber = profile.ContactNumber, GenderId = profile.GenderId, DateOfBirth = profile.DateOfBirth, EmailAddress = profile.EmailAddress, AvailableFunds = (decimal)profile.AvailableFunds, CashDeposit = (double)(profile.CashDeposit == null ? 0 : profile.CashDeposit), FullNames = profile.FullNames, TaxRegistered = profile.TaxRegistered, EthnicityId = profile.EthnicityId, CountryOfBirthId = profile.CountryOfBirthId, SourceOfIncomeId = profile.SourceOfIncomeId, StatusId = profile.StatusId, //ProfileTypeId = profile.ProfileTypeId, IdentificationNumber = profile.IdentificationNumber, IdentificationTypeId = profile.IdentificationTypeId, OtherSourceOfIncome = profile.OtherSourceOfIncome }; //if (profile.ProfileType != null) //{ // returnProfile.ProfileType = new Models.ProfileType // { // ProfileTypeId = profile.ProfileTypeId, // Name = profile.ProfileType.Description // }; //} if (profile.Lender != null) { returnProfile.Lender = new Models.Profiles.Lender { Id = profile.Lender.Id, LenderNumber = profile.Lender.LenderNumber, ProfileTypeId = profile.Lender.ProfileTypeId, StatusId = profile.Lender.StatusId, ProfileStatus = profile.Lender.ProfileStatus == null ? null : new Status { Id = profile.Lender.ProfileStatus.Id, Description = profile.Lender.ProfileStatus.Description } }; if (profile.Lender.ProfileType != null) { returnProfile.Lender.ProfileType = new ProfileType { ProfileTypeId = profile.Lender.ProfileType.Id, Name = profile.Lender.ProfileType.Description }; } } if (profile.Borrower != null) { returnProfile.Borrower = new Models.Profiles.Borrower { Id = profile.Borrower.Id, BorrowerNumber = profile.Borrower.BorrowerNumber, ProfileTypeId = profile.Borrower.ProfileTypeId, StatusId = profile.Borrower.StatusId, ProfileStatus = profile.Borrower.ProfileStatus == null ? null : new Status { Id = profile.Borrower.ProfileStatus.Id, Description = profile.Borrower.ProfileStatus.Description } }; if (profile.Borrower.ProfileType != null) { returnProfile.Borrower.ProfileType = new ProfileType { ProfileTypeId = profile.Borrower.ProfileType.Id, Name = profile.Borrower.ProfileType.Description }; } } if (profile.ProfileStatus != null) { returnProfile.ProfileStatus = new Models.Status { Id = profile.ProfileStatus.Id, Description = profile.ProfileStatus.Description }; } if (!minimal) { if (profile.ProfileApproval != null) { returnProfile.Approval = new Models.Profiles.Approval { ProfileId = profile.ProfileApproval.ProfileId, Status = new Status { Id = profile.ProfileApproval.ProfileStatus.Id, Description = profile.ProfileApproval.ProfileStatus.Description }, RejectReason = profile.ProfileApproval.RejectReason, ReviewDate = profile.ProfileApproval.ReviewDate, ReviewerId = profile.ProfileApproval.ReviewerId, Reviewer = profile.ProfileApproval.User?.Name + " " + profile.ProfileApproval.User?.Surname }; } if (profile.ProfileSuspension != null) { returnProfile.Suspension = new Models.Profiles.Suspension { ProfileId = profile.ProfileSuspension.ProfileId, Reason = profile.ProfileSuspension.Reason, StartDate = profile.ProfileSuspension.StartDate, EndDate = profile.ProfileSuspension.EndDate, ReviewerId = profile.ProfileApproval.ReviewerId, Reviewer = profile.ProfileApproval.User?.Name + " " + profile.ProfileApproval.User?.Surname }; } if (profile.NextOfKin != null) { returnProfile.NextOfKin = new Models.Profiles.NextOfKin { ProfileId = profile.NextOfKin.ProfileId, NextOfKinName = profile.NextOfKin.Name, RelationshipType = profile.NextOfKin.RelationshipType, NextOfKinContactNumber = profile.NextOfKin.ContactNumber, Income = profile.NextOfKin.Income }; } if (profile.SourceOfIncome != null) { returnProfile.SourceOfIncome = new Models.SourceOfIncome { Id = profile.SourceOfIncome.Id, Description = profile.SourceOfIncome.Description }; } if (profile.FicaCompliance != null) { returnProfile.FicaCompliance = new Models.FicaCompliance { ProfileId = returnProfile.ProfileId, FicaStatusId = profile.FicaCompliance.FicaStatusId, FicaStatus = new Models.Status { Id = profile.FicaCompliance.FicaStatus.Id, Description = profile.FicaCompliance.FicaStatus.Description } }; } if (profile.Ethnicity != null) { returnProfile.Ethnicity = new Models.Ethnicity { Id = profile.Ethnicity.Id, Description = profile.Ethnicity.Description }; } if (profile.Gender != null) { returnProfile.Gender = new Models.Gender { Id = profile.Gender.Id, Description = profile.Gender.Description }; } if (profile.IdentificationType != null) { returnProfile.IdentificationType = new Models.IdentificationType { Id = profile.IdentificationType.Id, Description = profile.IdentificationType.Description, }; } //if (profile.EmploymentStatus != null) //{ // returnProfile.EmploymentStatus = new Models.EmploymentStatus // { // Id = profile.EmploymentStatus.Id, // Description = profile.EmploymentStatus.Description // }; //} if (profile.Country != null) { returnProfile.CountryOfBirth = new Models.Country { Id = profile.Country.Id, Description = profile.Country.CountryName, CountryCode = profile.Country.CountryCode }; } if (profile.BankingDetail != null) { returnProfile.BankingDetails = new Models.BankingDetail { ProfileId = profile.BankingDetail.ProfileId, AccountName = profile.BankingDetail.AccountName, AccountNumber = profile.BankingDetail.AccountNumber, AccountType = profile.BankingDetail.AccountType, //BranchCode = profile.BankingDetail.BranchCode, BankName = profile.BankingDetail.BankName, //BranchName = profile.BankingDetail.BranchName, }; } if (profile.EmploymentDetail != null) { returnProfile.EmploymentDetail = new Models.EmploymentDetail { EmploymentStatusId = profile.EmploymentStatusId, EmploymentStatus = new EmploymentStatus { Id = profile.EmploymentStatusId.GetValueOrDefault(), Description = profile.EmploymentStatus?.Description }, ProfileId = profile.Id, NetMonthlyIncome = profile.EmploymentDetail.NetMonthlyIncome, GrossMonthlyIncome = profile.EmploymentDetail.GrossMonthlyIncome, SalaryDay = profile.EmploymentDetail.SalaryDay, BillingDay = profile.EmploymentDetail.BillingDay, //BillingDate = profile.BillingDate, EmployerName = profile.EmploymentDetail.EmployerName, EmploymentStartDate = profile.EmploymentDetail.EmploymentStartDate, EmploymentEndDate = profile.EmploymentDetail.EmploymentEndDate, //EmployerContactNumber = profile.EmploymentDetail.EmployerContactNumber, EmployerNumber = profile.EmploymentDetail.EmployerNumber, EmploymentTypeId = profile.EmploymentDetail.EmploymentTypeId, EmploymentType = profile.EmploymentDetail.EmploymentType == null ? null : new Models.EmploymentType { Id = profile.EmploymentDetail.EmploymentType.Id, Description = profile.EmploymentDetail.EmploymentType.Description } }; } if (profile.TaxRegistered.GetValueOrDefault()) { if (profile.TaxInformation != null) { //map returnProfile.TaxInformation = new Models.TaxInformation { ProfileId = profile.Id, TaxCountryId = profile.TaxInformation.TaxCountryId, TaxCountry = profile.TaxInformation.Country == null ? null : new Models.Country { Id = profile.TaxInformation.Country.Id, Description = profile.TaxInformation.Country.CountryName, CountryCode = profile.TaxInformation.Country.CountryCode }, TaxNumber = profile.TaxInformation.TaxNumber, TaxIdentificationTypeId = profile.TaxInformation.TaxIdentificationTypeId, TaxIdentificationType = profile.TaxInformation.TaxIdentificationType == null ? null : new Models.TaxIdentificationType { Id = profile.TaxInformation.TaxIdentificationType.Id, Description = profile.TaxInformation.TaxIdentificationType.Description } }; } } returnProfile.Addresses = profile.ProfileAddresses.Where(m => !m.IsDeleted).ToList().ConvertAll(m => new Models.Address { AddressId = m.Id, Line1 = m.Line1, Line2 = m.Line2, City = m.City, PostalCode = m.PostalCode, AddressTypeId = m.AddressTypeId, AddressType = new Models.AddressType { Id = m.AddressType.Id, Description = m.AddressType.Description }, ProvinceId = m.ProvinceId, Province = m.Province == null ? null : new Models.Province { Id = m.Province.Id, Description = m.Province.Description }, //CountryId = m.CountryId, //Country = new Models.Country //{ // Id = m.Country?.Id ?? 0, // Description = m.Country?.CountryName, // CountryCode = m.Country?.CountryCode //}, AddressProfileId = m.ProfileId, }); returnProfile.Documents = profile.ProfileDocuments.Where(m => !m.IsDeleted).ToList().ConvertAll(m => new Models.Document { DocumentTypeId = m.DocumentTypeId, DocumentType = new Models.DocumentType { Id = m.DocumentType.Id, Description = m.DocumentType.Description }, DocumentId = m.Id, FileId = m.FileId, UploadedDate = m.UploadedDate, FileData = new Models.Files.FileData { Id = m.FileData.Id, Contents = Convert.ToBase64String(m.FileData.Contents), ContentType = m.FileData.ContentType, Size = m.FileData.Size, FileName = m.FileData.FileName, FileUrl = m.FileData.FileUrl } }); } return returnProfile; } public static BuddyFinance.Model.Profile MapToModel(Models.Profiles.Profile profileViewModel) { { var returnProfile = new BuddyFinance.Model.Profile(); return returnProfile; } } public static List MapFromListModel(List profiles) { if (!profiles.Any()) return new List(); return profiles.Select(m => MapFromModel(m, true)).ToList(); } public static List MapToModel(List profileViewModels) { if (!profileViewModels.Any()) return new List(); return profileViewModels.Select(m => MapToModel(m)).ToList(); } public static ProfileScore MapFromModel(this Model.ProfileCreditRatingScore creditRatingScore) { if (creditRatingScore == null) return new ProfileScore(); return new ProfileScore { CreditBureauScore = creditRatingScore.CreditBureauScore, CreditBureauRobotFlag = creditRatingScore.CreditBureauRobotScore.Description, CreditBureauRobotFlagColour = creditRatingScore.CreditBureauRobotScore.RobotColor, DerivedRobotFlag = creditRatingScore.DerivedScoreRobotScore.Description, DerivedScore = creditRatingScore.DerivedScore, DerivedRobotFlagColour = creditRatingScore.DerivedScoreRobotScore.RobotColor, ScoringDate = creditRatingScore.ScoreDate, FirstName = creditRatingScore.Firstname, LastName = creditRatingScore.Lastname }; } } }