Ejemplo n.º 1
0
 public void SavePurchase(GoogleUser user, int days, string transactionId)
 {
     using (var context = new HypixelContext())
     {
         Server.AddPremiumTime(days, user);
         context.Add(new Bonus()
         {
             BonusTime     = TimeSpan.FromDays(days),
             ReferenceData = transactionId,
             Type          = Bonus.BonusType.PURCHASE,
             UserId        = user.Id
         });
         if (user.ReferedBy != 0)
         {
             context.Add(new Bonus()
             {
                 BonusTime     = TimeSpan.FromDays(days) / 10,
                 ReferenceData = transactionId,
                 Type          = Bonus.BonusType.REFERED_UPGRADE,
                 UserId        = user.ReferedBy
             });
         }
         context.Update(user); context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public void WasReferedBy(GoogleUser user, string referer)
        {
            if (user.ReferedBy != 0)
            {
                throw new CoflnetException("already_refered", "You already have used a referal Link. You can only be refered once.");
            }
            var id = hashids.Decode(referer)[0];

            if (id == user.Id)
            {
                throw new CoflnetException("self_refered", "You cant refer yourself");
            }
            using (var context = new HypixelContext())
            {
                user.ReferedBy = id;
                // give the user 'test' premium time
                Server.AddPremiumTime(1, user);
                context.Update(user);
                // persist the boni
                context.Add(new Bonus()
                {
                    BonusTime     = TimeSpan.FromDays(1),
                    ReferenceData = id.ToString(),
                    Type          = Bonus.BonusType.BEING_REFERED,
                    UserId        = user.Id
                });


                var referUser = context.Users.Where(u => u.Id == id).FirstOrDefault();
                if (referUser != null)
                {
                    // award referal bonus to user who refered
                    Server.AddPremiumTime(1, referUser);
                    context.Add(new Bonus()
                    {
                        BonusTime     = TimeSpan.FromDays(1),
                        ReferenceData = user.Id.ToString(),
                        Type          = Bonus.BonusType.REFERAL,
                        UserId        = referUser.Id
                    });
                    context.Update(referUser);
                }
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 internal void AddToken(int userId, string deviceName, string token)
 {
     using (var context = new HypixelContext())
     {
         var user = context.Users.Where(u => u.Id == userId).Include(u => u.Devices).FirstOrDefault();
         if (user == null)
         {
             throw new CoflnetException("unknown_user", "The user is not known");
         }
         var target = user.Devices.Where(d => d.Name == deviceName);
         if (target.Any())
         {
             var device = target.First();
             device.Token = token;
             context.Update(device);
         }
         else
         {
             var hasPremium = user.PremiumExpires > DateTime.Now;
             if (!hasPremium && user.Devices.Count >= 3)
             {
                 throw new CoflnetException("no_premium", "You need premium to add more than 3 devices");
             }
             if (user.Devices.Count > 10)
             {
                 throw new CoflnetException("limit_reached", "You can't have more than 11 devices linked to your account");
             }
             var device = new Device()
             {
                 UserId = user.Id, Name = deviceName, Token = token
             };
             user.Devices.Add(device);
             context.Update(user);
             context.Add(device);
         }
         context.SaveChanges();
     }
 }