using HashidsNet; namespace Knoks.Core.Entities { public static class Uid { private static readonly Hashids LeadHashids = new Hashids("0oSe-yc2M7_5hQro!pxp45d", 8); private static readonly Hashids LoanRequestHashids = new Hashids("l_EOC36t#4yyI6D-b36TyJ5", 8); private static readonly Hashids LoanRequestAndUserHashids = new Hashids("8#TGF(6t&8jkU8P+W89Yqz3", 8); //-- Lead Uid -- public static string Lead(long? leadId) { return leadId == null ? null : LeadHashids.EncodeLong(leadId.Value); } public static long? Lead(string leadUid) { return leadUid == null ? null : (long?)LeadHashids.DecodeLong(leadUid)[0]; } //-- LoanRequest Uid -- public static string LoanRequest(long? loanRequestId) { return loanRequestId == null ? null : LoanRequestHashids.EncodeLong(loanRequestId.Value); } public static long? LoanRequest(string loanRequestUid) { return loanRequestUid == null ? null : (long?)LoanRequestHashids.DecodeLong(loanRequestUid)[0]; } //-- User & LoanRequest Uid -- public static string LoanRequestAndUser(long loanRequestId, long? userId) { return userId.HasValue ? LoanRequestAndUserHashids.EncodeLong(loanRequestId, userId.Value) : LoanRequestAndUserHashids.EncodeLong(loanRequestId); } public static void LoanRequestAndUser(string loanRequestUid, out long loanRequestId, out long? userId) { var arr = LoanRequestAndUserHashids.DecodeLong(loanRequestUid); loanRequestId = arr[0]; userId = arr.Length == 1 ? null : (long?)arr[1]; } } }