using BuddyFinance.Common.Encryption; using BuddyFinance.Integration; using BuddyFinance.Integration.Models; using BuddyFinance.Integration.Models.Enums; using BuddyFinance.Integration.Models.Profiles; using BuddyFinance.WebApi.Filters; using BuddyFinance.WebApi.Models; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Http; /*Tumelo 15 Sep 17 * */ namespace BuddyFinance.WebApi.Controllers { /// /// Profiles API /// [RoutePrefix("api/profiles")] public class ProfilesController : BaseController { private ProfilesIntegrator _profileIntegrator = new ProfilesIntegrator(); /// /// Gets all profiles /// /// [HttpGet] [Route("")] [Authenticate] public GetProfilesResult GetAllProfiles() { return _profileIntegrator.GetAllProfiles(); } /// /// Gets profiles by profile type /// /// profile type Id /// [HttpGet] [Route("profileTypeId={profileTypeId}")] //api/profiles/profileTypeId={profileTypeId} [Authenticate] public GetProfilesResult GetProfiles(int profileTypeId) { return _profileIntegrator.GetProfiles(profileTypeId); } /// /// Get approved lender profiles /// /// [HttpGet] [Route("approvedlenders")] [Authenticate] public GetProfilesResult ApprovedLenders() { var result = GetProfiles((int)ProfileTypeEnum.Lender); if (result.Result != null && result.Result.Any()) result.Result = result.Result.Where(m => m.StatusId == (int)ProfileStatusEnum.Approved).ToList(); return result; } /// /// Gets a profile by Id /// /// profile Id /// [HttpGet] [Route("{profileId}")] //api/profiles/45 [Authenticate] public GetProfileResult GetProfile(int profileId) { return _profileIntegrator.GetProfile(profileId); } /// /// Gets profile notifications /// /// /// [HttpGet] [Route("{profileId}/notifications")] // api/profiles/45/notifications public GetProfileNotificationsResult GetProfileNotifications(string profileId) { return _profileIntegrator.GetNotifications(profileId); } /// /// Gets a profile by username /// /// username: email /// [HttpGet] [Route("getbyuser")] [Authenticate] public GetProfileResult GetProfileByUser(string username) { return _profileIntegrator.GetProfileByUser(username); } /// /// Approves a profile application /// /// /// [HttpPost] [Route("approve")] public ApproveProfileResult ApproveProfile(ReviewProfileModel model) { if (!ModelState.IsValid) { var errors = ""; foreach (var modelValue in ModelState.Values) { foreach (var modelError in modelValue.Errors) { errors += modelError.ErrorMessage; } } return new ApproveProfileResult { ErrorCode = (int)ResponseCodes.ValidationError, ErrorMessage = errors, }; } var userId = model.UserId.ToDecryptedInt(); return _profileIntegrator.ApproveProfile(model.ProfileId.ToDecryptedInt(), model.Approve, model.Comments, userId); } /// /// Suspends a profile /// /// Suspend info /// [HttpPost] [Route("suspend")] public BaseResult Suspend(SuspendProfileModel model) { if (!ModelState.IsValid) { var errors = ""; foreach (var modelValue in ModelState.Values) { foreach (var modelError in modelValue.Errors) { errors += modelError.ErrorMessage; } } return new BaseResult { ErrorCode = (int)ResponseCodes.ValidationError, ErrorMessage = errors, }; } return _profileIntegrator.Suspend(model); } /// /// Updates a profile /// /// profile data /// [HttpPost] [Route("save")] public SaveProfileResult SaveProfile(Profile profile) //save status into profileApproval { return _profileIntegrator.SaveProfile(profile); } /// /// Approve or decline a profile account /// /// profile data /// [HttpPost] [Route("ReviewAccount")] public BaseResult ReviewAccount(ReviewProfileModel model) { return _profileIntegrator.ReviewAccount(model); } /// /// suspend/unsuspend account /// /// /// [HttpPost] [Route("SuspendAccount")] public BaseResult SuspendAccount(SuspendProfileAccountModel model) { return _profileIntegrator.SuspendAccount(model); } /// /// Updates a profile /// /// profile data /// [HttpPost] [Route("updatedetails")] public BaseResult Update(Profile profile) { return _profileIntegrator.Update(profile); } /// /// Updates profile details or create new profile /// /// profile details /// [HttpPost] [Route("updateprofiledetails")] public BaseResult UpdateProfileDetails(ProfileDetails profileDetails) { return _profileIntegrator.UpdateDetails(profileDetails); } /// /// Adds or updates profile address /// /// profile address /// [HttpPost] [Route("updateaddress")] public UpdateAddressResult UpdateAddress(Address address) { return _profileIntegrator.UpdateAddress(address); } /// /// Update profile addresses /// /// /// [HttpPost] [Route("updateaddresses")] public BaseResult UpdateAddresses(List
addresses) { return _profileIntegrator.UpdateAddresses(addresses); } /// /// removes profile address /// /// Address Id /// [HttpPost] [Route("removeaddress")] public BaseResult RemoveAddress(int addressId) { return _profileIntegrator.RemoveAddress(addressId); } /// /// get profile address /// /// /// [HttpGet] [Route("getaddress")] public BaseResult
GetAddress(int addressId) { return _profileIntegrator.GetAddress(addressId); } /// /// get profile addresses /// /// /// [HttpGet] [Route("{profileId}/addresses")] public BaseResult> GetAddresses(int profileId) { return _profileIntegrator.GetAddresses(profileId); } /// /// Removes profile document /// /// Document Id /// [HttpPost] [Route("removedocument")] public BaseResult RemoveDocument(int documentId) { return _profileIntegrator.RemoveDocument(documentId); } /// /// Adds or Updates Profile Document /// /// Profile Document /// [HttpPost] [Route("updatedocument")] public UpdateDocumentResult UpdateDocument(Document document) { return _profileIntegrator.UpdateDocument(document); } /// /// get profile documents /// /// /// [HttpGet] [Route("{profileId}/documents")] public BaseResult> GetDocuments(int profileId) { return _profileIntegrator.GetDocuments(profileId); } /// /// update profile documents /// /// /// [HttpPost] [Route("UpdateDocuments")] public BaseResult UpdateDocuments(List documents) { var updateDocuments = documents.Select(m => new Document { DocumentId = m.DocumentId, DocumentTypeId = m.DocumentTypeId, FileId = m.FileId, ProfileId = m.ProfileId, UploadedDate = m.UploadedDate, FileData = m.FileData == null ? null : new Integration.Models.Files.FileData { Id = m.FileData.Id, FileName = m.UploadFile != null ? m.UploadFile.FileName : m.FileData.FileName, ContentType = m.UploadFile != null ? m.UploadFile.ContentType: m.FileData.ContentType, Size = m.UploadFile != null ? m.UploadFile.ContentLength : m.FileData.Size, Contents = m.UploadFile != null ? Convert.ToBase64String(GetFileContents(m.UploadFile)) : m.FileData.Contents, } }).ToList(); return _profileIntegrator.UpdateDocuments(updateDocuments); } private byte[] GetFileContents(HttpPostedFileBase uploadFile) { byte[] data; using (Stream inputStream = uploadFile.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } data = memoryStream.ToArray(); } return data; } /// /// Updates Banking details /// /// Banking details /// [HttpPost] [Route("updatebankingdetails")] public UpdateBankingDetailsResult UpdateBankingDetails(BankingDetail bankingDetails) { return _profileIntegrator.UpdateBankingDetails(bankingDetails); } /// /// Updates Employment details /// /// Employment details /// [HttpPost] [Route("updateemployment")] public UpdateEmploymentResult UpdateEmployment(EmploymentDetail employmentDetail) { return _profileIntegrator.UpdateEmployment(employmentDetail); } /// /// Updates Tax information /// /// Tax information /// [HttpPost] [Route("updatetaxinformation")] public UpdateTaxInformationResult UpdateTaxInformation(TaxInformation taxInformation) { return _profileIntegrator.UpdateTaxInformation(taxInformation); } /// /// Updates Next of Kin /// /// Next of Kin details /// [HttpPost] [Route("updatenextofkin")] public BaseResult UpdateNextOfKin(NextOfKin nextOfKin) { return _profileIntegrator.UpdateNextOfKin(nextOfKin); } /// /// Update FICA Compliance information /// /// FICA Compliance information /// [HttpPost] [Route("updatefica")] public BaseResult UpdateFica(FicaCompliance ficaCompliance) { return _profileIntegrator.UpdateFica(ficaCompliance); } /// /// Return profile summary - Loans and Loan request for borrower /// /// /// [HttpGet] [Route("summary")] //api/profiles/summary/stjyjzxfaihkfjash ///{profileId} public ProfileSummaryResult Summary(string profileId) { return _profileIntegrator.Summary(profileId); } /// /// /// /// /// [HttpGet] [Route("getProfileEarning")] public GetProfileEarnings GetProfileEarnings(string profileId) { int profileId_ = profileId.ToDecryptedInt(); return _profileIntegrator.GetProfileEarning(profileId_); } /// /// /// /// [HttpGet] [AllowAnonymous] [Route("getearnings")] //api/profiles/getearnings public GetProfileEarnings GetProfileEarnings() { return _profileIntegrator.GetEarning(); } /// /// /// /// /// [HttpPost] [AllowAnonymous] [Route("getloanscalculations")] //api/profiles/getloanscalculations public BaseResult LoanCulculator(LoanCalculatorModel model) { return _profileIntegrator.LoanCulculator(model); } /// /// /// /// /// [HttpPost] [AllowAnonymous] [Route("contactus")] public BaseResult ContactUs(Contact model) { return _profileIntegrator.ContactUs(model); } /// /// Activate profile account /// /// /// type of account to activate (Borrower or Lender) /// [HttpPost] [Route("activate/{profileId}")] public BaseResult Activate(string profileId, int type) { var profileId_ = profileId.ToDecryptedInt(); return _profileIntegrator.Activate(profileId_, type); } /// /// submit new profile for review /// /// /// [HttpPost] [Route("{profileId}/Submit")] public BaseResult Submit(int profileId) { //var profileId_ = profileId.ToDecryptedInt(); return _profileIntegrator.Submit(profileId); } } }