using BuddyFinance.Admin.Models; using BuddyFinance.Common.Integration; using BuddyFinance.Integration.Logging; using BuddyFinance.Integration.Models.Enums; using BuddyFinance.Integration.Models.Profiles; using BuddyFinance.Integration.Models.ReportingServices; using BuddyFinance.Integration.Models.Statements; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System.Linq; using BuddyFinance.Common.Encryption; using System; using BuddyFinance.Common.Extensions; using BuddyFinance.Integration.Models.Lookups; using BuddyFinance.Admin.Areas.Admin.Models; namespace BuddyFinance.Admin.Controllers { public class ProfileController : BaseController { public ProfileController(IConfiguration configuration, BuddyFinanceDbContext dbContext) : base(configuration, dbContext) { } public IActionResult Index() { ViewData["Profile"] = SessionManager.Current?.CurrentUser.ProfileId; ViewData["Status"] = SessionManager.Current?.CurrentUser.ProfileStatus.Id; var currentProfileId = SessionManager.Current?.CurrentUser.ProfileId; var _token = SessionManager.Current?.CurrentUser.AccessToken; //var apiResponse = WebApiHelper.Get(API_BASE, $"profiles/GetProfile?profileId={currentProfileId}", token); var apiResponse = WebApiHelper.Get(API_BASE, "profiles/GetProfile?profileId=" + currentProfileId, _token); Logger.Log(LogTypeEnum.Error, "Profile Get apiResponse errorCode: " + apiResponse.ErrorCode, 0, "", ""); if (apiResponse.ErrorCode == 0) { if (SessionManager.Current != null && apiResponse.Result.Result != null) SessionManager.Current.CurrentUser.ProfileStatus = apiResponse.Result.Result.ProfileStatus; var result = apiResponse.Result; if (result.ErrorCode == 0) { ViewData["Profile"] = result.Result; if (result.Result.Documents.Any(m => m.DocumentTypeId == (int)DocumentTypeEnum.BankStatementOrLetter)) { var bankStatement = result.Result.Documents.FirstOrDefault(m => m.DocumentTypeId == (int)DocumentTypeEnum.BankStatementOrLetter); var index = result.Result.Documents.IndexOf(bankStatement); if (bankStatement != null) { if (result.Result.Lender != null) { bankStatement.DocumentType.Description = "1-Month Bank Statement / Letter from Bank"; } else { bankStatement.DocumentType.Description = "3-Months Bank Statement"; } result.Result.Documents[index] = bankStatement; } } } } return View(); } public ActionResult Activate(int _t) { var model = new AccountActivateViewModel { ProfileTypeId = _t, }; model.Type = EnumExtensions.GetEnumDescription((ProfileTypeEnum)model.ProfileTypeId); var currentProfileId = SessionManager.Current?.CurrentUser.ProfileId; var token = SessionManager.Current?.CurrentUser.AccessToken; var apiResponse = WebApiHelper.Get(API_BASE, $"profiles/GetProfile?profileId={currentProfileId}", token); if (apiResponse.ErrorCode == 0) { if (SessionManager.Current != null && apiResponse.Result.Result != null) SessionManager.Current.CurrentUser.ProfileStatus = apiResponse.Result.Result.ProfileStatus; var result = apiResponse.Result; if (result.ErrorCode == 0) { model.Profile = new ProfileEditViewModel(result.Result); var documents = result.Result.Documents; if (_t == (int)ProfileTypeEnum.Lender) { model.Profile.Documents = documents.Where(m => m.DocumentTypeId == (int)DocumentTypeEnum.IdentityDocument) .Select(m => new BuddyFinance.Admin.Areas.Admin.Models.DocumentViewModel(m)).ToList(); } else { model.Profile.Documents = documents.Select(m => new BuddyFinance.Admin.Areas.Admin.Models.DocumentViewModel(m)).ToList(); } var apiResponse_ = WebApiHelper.Get(API_BASE, $"master/documenttypes", token); var docTypes = apiResponse_.Result.Result; var documentTypes = _t == (int)ProfileTypeEnum.Borrower ? docTypes : docTypes.Where(m => m.Id == (int)DocumentTypeEnum.IdentityDocument).ToList(); foreach (var docType in documentTypes) { if (!model.Profile.Documents.Any(m => m.DocumentTypeId == docType.Id)) { model.Profile.Documents.Add(new Areas.Admin.Models.DocumentViewModel { DocumentTypeId = docType.Id, DocumentType = new Integration.Models.DocumentType { Id = docType.Id, Description = docType.Description }, ProfileId = model.Profile.ProfileId }); } } } } return View(model); } [HttpGet("/api/profile")] public IActionResult GetCurrent() { var currentProfileId = SessionManager.Current?.CurrentUser.ProfileId; var token = SessionManager.Current?.CurrentUser.AccessToken; var apiResponse = WebApiHelper.Get(API_BASE, $"profiles/GetProfile?profileId={currentProfileId}", token); if (apiResponse.ErrorCode == 0) { //if (SessionManager.Current != null && apiResponse.Result.Result != null) // SessionManager.Current.CurrentUser.ProfileStatus = apiResponse.Result.Result.ProfileStatus; return Json(apiResponse.Result, new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() }); //CamelCasePropertyNamesContractResolver}); } else { return Json(new GetProfileResult { ErrorCode = (int)apiResponse.ErrorCode, ErrorMessage = apiResponse.ErrorMessage }, new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() }); } } } }