Esempio n. 1
0
 public void AddAddress(URL url)
 {
     url.Id          = URLList.Count;
     url.ShortAdress = hashids.Encode(new Random().Next());
     URLList.Add(url);
 }
Esempio n. 2
0
 void it_encodes_a_single_number()
 {
     hashids.Encode(1).Should().Be("NV");
     hashids.Encode(22).Should().Be("K4");
     hashids.Encode(333).Should().Be("OqM");
     hashids.Encode(9999).Should().Be("kQVg");
     hashids.Encode(123000).Should().Be("58LzD");
     hashids.Encode(456000000).Should().Be("5gn6mQP");
     hashids.Encode(987654321).Should().Be("oyjYvry");
 }
Esempio n. 3
0
        private void It_can_encode_with_a_custom_alphabet()
        {
            var h = new Hashids(SALT, 0, "ABCDEFGhijklmn34567890-:");

            h.Encode(1, 2, 3, 4, 5).ShouldBe("6nhmFDikA0");
        }
Esempio n. 4
0
        public static string HashId(long id)
        {
            var code = Convert.ToInt32(id);

            return(HashMachine.Encode(code));
        }
Esempio n. 5
0
 public void AddLink(Link link)
 {
     link.ShortLink = hashids.Encode(TimeSinceMidnight());
     _context.Links.Add(link);
     _context.SaveChanges();
 }
Esempio n. 6
0
        void it_can_encode_with_a_custom_alphabet()
        {
            var h = new Hashids(salt, 0, "ABCDEFGhijklmn34567890-:");

            h.Encode(1, 2, 3, 4, 5).Should().Be("6nhmFDikA0");
        }
Esempio n. 7
0
 public string Encode(int id)
 {
     return(_hashids.Encode(id));
 }
Esempio n. 8
0
 private string EncryptHashids(int stringToEncrypt)
 {
     return(_hashids.Encode(stringToEncrypt));
 }
Esempio n. 9
0
 void it_can_encode_with_a_custom_alphabet()
 {
     var h = new Hashids(salt, 0, "ABCDEFGhijklmn34567890-:");
     h.Encode(1, 2, 3, 4, 5).Should().Be("6nhmFDikA0");
 }
Esempio n. 10
0
        void it_can_encodes_to_a_minimum_length()
        {
            var h = new Hashids(salt, 18);
            h.Encode(1).Should().Be("aJEDngB0NV05ev1WwP");

            h.Encode(4140, 21147, 115975, 678570, 4213597, 27644437).
                Should().Be("pLMlCWnJSXr1BSpKgqUwbJ7oimr7l6");
        }
Esempio n. 11
0
 private static string CreateChannel()
 {
     return(_hashids.Encode(_random.Next()));
 }
Esempio n. 12
0
        // Bijective functions
        // starbukcs.com --> 1001
        // starbukcs.com --> 1424
        // starbukcs.com --> 1001 ->afsasfba

        public static string Encode(int i)
        {
            return(hashids.Encode(i));
        }
Esempio n. 13
0
        public static string GenerateIdForAccount(object userId)
        {
            var hash = new Hashids(userId.ToString());

            return(userId + "_" + hash.Encode(DateTime.Now.Millisecond));
        }
Esempio n. 14
0
 public static string ProduceCode(params int[] values)
 {
     return(hashIds.Encode(values));
 }
Esempio n. 15
0
 public static string Obfuscate(int value)
 {
     return(String.Format(CultureInfo.InvariantCulture, "{0}{1}", HasherPrefix, hasher.Encode(value)));
 }
Esempio n. 16
0
 /// <summary>
 /// Encodes the provided numbers into a hashed string
 /// </summary>
 /// <param name="numbers">the numbers to encode</param>
 /// <returns>the hashed string</returns>
 public string Encode(params int[] numbers)
 {
     return(_hasher.Encode(numbers));
 }
 /// <summary>
 /// Sayıyı şifrelenmiş bir string olarak döner.
 /// </summary>
 public static string Encrypt(int number) =>
 number < 0 ? null : Hashids.Encode(number);
Esempio n. 18
0
 public static string ToEncodedId(this int key)
 {
     return(Hashids.Encode(key));
 }
Esempio n. 19
0
 /// <summary>
 /// 对ID进行编码
 /// </summary>
 /// <param name="id">ID</param>
 /// <returns>哈希值</returns>
 public static string Encode(int id) => _hashids.Encode(id);
 public string HashValue(Guid id)
 {
     return(_hashIds.Encode(id.ToByteArray().Select(Convert.ToInt32).ToArray()));
 }
Esempio n. 21
0
 private string GenerateHash(int id)
 {
     return(hashids.Encode(id));
 }
Esempio n. 22
0
        void it_can_encode_with_a_custom_alphabet_and_few_seps()
        {
            var h = new Hashids(salt, 0, "ABCDEFGHIJKMNOPQRSTUVWXYZ23456789");

            h.Encode(1, 2, 3, 4, 5).Should().Be("44HYIRU3TO");
        }
Esempio n. 23
0
        /// <summary>
        /// Claim the rewards
        /// </summary>
        /// <param name="db"></param>
        /// <param name="rewardsId"></param>
        /// <param name="registrationId"></param>
        /// <returns></returns>
        public static AffiliateRewardsClaim ClaimReward(NancyBlackDatabase db, int rewardsId, int registrationId)
        {
            AffiliateReward rewards;
            var             reg = db.GetById <AffiliateRegistration>(registrationId);

            rewards = db.GetById <AffiliateReward>(rewardsId);

            var canClaim = AffiliateReward.CanClaim(db, rewardsId, registrationId);

            if (canClaim == false && reg.NcbUserId != 1)
            {
                return(null);
            }

            if (rewards.MaxPerUser > 0)
            {
                lock (BaseModule.GetLockObject("RewardClaim-Reg-" + registrationId))
                {
                    var totalClaimedByUser = db.Query <AffiliateRewardsClaim>()
                                             .Where(c => c.AffiliateRewardsId == rewards.Id &&
                                                    c.AffiliateRegistrationId == registrationId).Count();

                    if (reg.NcbUserId == 1) // Super Admin
                    {
                        // not check
                    }
                    else
                    {
                        if (totalClaimedByUser >= rewards.MaxPerUser)
                        {
                            return(null);
                        }
                    }
                }
            }

            if (rewards.TotalQuota > 0)
            {
                lock (BaseModule.GetLockObject("RewardClaim-" + rewardsId))
                {
                    var totalClaimed = db.Query <AffiliateRewardsClaim>().Where(c => c.AffiliateRewardsId == rewards.Id).Count();
                    rewards.RemainingQuota = rewards.TotalQuota - totalClaimed;
                    db.UpsertRecord(rewards);
                }
            }

            if (rewards.IsRewardsClaimable == false)
            {
                return(null);
            }


            if (rewards.IsCodeDiscount || rewards.IsFreeGiftInSaleOrder)
            {
                var until = DateTime.MaxValue.Ticks;

                if (rewards.CodeDicountExpiryInDays != null)
                {
                    until = DateTime.Now.AddDays(rewards.CodeDicountExpiryInDays.Value).Ticks;
                }
                if (rewards.CodeDiscountExpiryDate != null)
                {
                    until = rewards.CodeDiscountExpiryDate.Value.Ticks;
                }

                AffiliateRewardsClaim claim = null;
                db.Transaction(() =>
                {
                    // free gift also gets created as code

                    Product p = new Product();

                    if (rewards.IsCodeDiscount)
                    {
                        p.Price      = rewards.CodeDiscountAmount * -1;
                        p.Attributes = new
                        {
                            rewardId      = rewards.Id,
                            description   = rewards.Title + ", ราคาก่อนส่วนลดขั้นต่ำ: " + rewards.MinimumPurchaseAmount,
                            min           = rewards.MinimumPurchaseAmount,
                            onetime       = true,
                            until         = until,
                            discount      = rewards.CodeDiscountAmount,
                            affiliateName = reg.AffiliateName,
                            require       = rewards.RequiredProductIds,
                        };
                    }

                    if (rewards.IsFreeGiftInSaleOrder)
                    {
                        p.DiscountPrice    = 0;
                        p.Price            = rewards.CodeDiscountAmount;
                        p.PromotionEndDate = new DateTime(until);
                        p.MasterProductId  = rewards.RewardsProductId;
                        p.IsVariation      = true;

                        p.Attributes = new
                        {
                            rewardId      = rewards.Id,
                            description   = rewards.Title + ", ราคาก่อนส่วนลดขั้นต่ำ: " + rewards.MinimumPurchaseAmount,
                            min           = rewards.MinimumPurchaseAmount,
                            onetime       = true,
                            until         = until,
                            discount      = rewards.CodeDiscountAmount,
                            isfreeproduct = 1,
                            affiliateName = reg.AffiliateName,
                            require       = rewards.RequiredProductIds,
                        };
                    }

                    db.UpsertRecord(p);

                    var code = hashids.Encode(p.Id, reg.Id);
                    p.Url    = "/promotions/code/" + code;
                    p.Title  = "Affiliate Discount: " + code;


                    if (rewards.IsFreeGiftInSaleOrder)
                    {
                        p.Title = "GIFT ITEM:" + rewards.Title;
                    }

                    db.UpsertRecord(p);

                    claim = new AffiliateRewardsClaim();
                    claim.AffiliateRegistrationId = reg.Id;
                    claim.NcbUserId          = reg.NcbUserId;
                    claim.AffiliateCode      = reg.AffiliateCode;
                    claim.DiscountCode       = code;
                    claim.RewardsName        = rewards.Title;
                    claim.AffiliateRewardsId = rewards.Id;
                    claim.ProductId          = p.Id;
                    claim.CouponAttributes   = p.Attributes;
                    db.UpsertRecord(claim);
                });

                return(claim);
            }

            {
                var claim = new AffiliateRewardsClaim();
                claim.AffiliateRegistrationId = reg.Id;
                claim.NcbUserId          = reg.NcbUserId;
                claim.AffiliateCode      = reg.AffiliateCode;
                claim.RewardsName        = rewards.Title;
                claim.AffiliateRewardsId = rewards.Id;
                claim.ProductId          = rewards.RewardsProductId;

                db.UpsertRecord(claim);

                return(claim);
            }
        }