public bool AddPoints(int userChallengeId)
        {
            using (var context = new greenMoneyEntities())
            {
                var time = DateTime.Now;

                UserChallenges userChallenge = context.UserChallenges.Single(x => x.Id == userChallengeId);
                Users1 user = context.Users1.Single(x => x.Id == userChallenge.UserId);
                Challenges challenge = context.Challenges.Single(x => x.Id == userChallenge.ChallengeId);

                userChallenge.PointsClaimed = true;

                var transaction = new Transactions
                {
                    Address_Id = user.Address_Id,
                    User_Id = user.Id,
                    Time = time,
                    Description = "Challenge " + challenge.Name,
                    Points = Convert.ToInt64(challenge.Points),
                    TransactionTypeID = 2
                };

                context.Transactions.Add(transaction);
                context.SaveChanges();

                return true;
            }
        }
Ejemplo n.º 2
0
 //add points to translactions
 public bool AddPoints(string providerUserKey, int id, string promoCode = "")
 {
     try
     {
         using (var context = new greenMoneyEntities())
         {
             var user = context.Users1.Find(new Guid(providerUserKey));
             var time = DateTime.Now;
             var userChallenge =
                 context.UserChallenges.FirstOrDefault(
                     x => x.ChallengeId == id && x.UserId == user.Id);
             if (userChallenge != null)
             {
                 userChallenge.PointsClaimed = true;
                 var challenge = context.Challenges.SingleOrDefault(x => x.Id.Equals(id));
                 if (challenge != null)
                 {
                     //just for challenge action
                     if (string.IsNullOrEmpty(promoCode) || challenge.PromoCode.Equals(promoCode))
                     {
                         var addPoints = challenge.Points.HasValue ? Convert.ToInt64(challenge.Points.Value) : 0;
                         var transaction = new Transactions
                         {
                             Addresses = user.Addresses,
                             Users1 = user,
                             Time = time,
                             Description = "Challenge " + challenge.Name,
                             Points = +addPoints,
                             TransactionTypeID = 2
                         };
                         context.Transactions.Add(transaction);
                         context.SaveChanges();
                         return true;
                     }
                 }
             }
         }
         return false;
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 3
0
        public CheckoutSubmitModel AddCartToMyWallet(string providerUserKey)
        {
            CheckoutSubmitModel model = new CheckoutSubmitModel();

            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.Find(new Guid(providerUserKey));

                var items = user.CartItems.ToList();
                long total = items.Sum(i => i.Cost);
                decimal dollartotal = items.Sum(i => i.DollarCost);

                // User don't have any items in cart
                if (!items.Any())
                {
                    model.CheckoutSubmitModelState = CheckoutSubmitModelState.NoItemsFound;
                    return model;
                }

                // User has enough points to purchase
                if (user.PointsTotal >= total)
                {
                    var time = DateTime.Now;

                    string description;
                    int? transactionType = null;

                    if (user.CartItems.Count == 1)
                    {
                        description = "Redeem " + user.CartItems.Single().Rewards.PartnerName
                            + " " + user.CartItems.Single().Rewards.Name;
                        transactionType = 4;
                    }
                    else
                    {
                        description = "Voucher redemption x" + user.CartItems.Sum(i => i.Quantity);
                        transactionType = 1;
                    }

                    var purchases = new List<OrderSummaryItemModel>();

                    int costIndex = 1;

                    foreach (var item in items)
                    {
                        int itemidx;
                        if (item.DollarCost == 0)
                        {
                            for (int i = 0; i < item.Quantity; i++)
                            {
                                var voucher = new Vouchers
                                {
                                    Id = Guid.NewGuid(),
                                    Issued = time,
                                    Rewards = item.Rewards,
                                    Users1 = user
                                };

                                context.Vouchers.Add(voucher);

                                voucher.Rewards.Popularity += 1;

                                var ownerUser = context.Users.FirstOrDefault(x => x.UserId == item.Rewards.Owner_Id);

                                purchases.Add(new OrderSummaryItemModel
                                {
                                    VoucherId = voucher.Id,
                                    Name = item.Rewards.Name,
                                    Points = item.Cost,
                                    Quantity = item.Quantity,
                                    DollarCost = item.DollarCost,
                                    PayPalIndex = 0,
                                    AttachVoucherUrl = true,
                                    NotifyOnRedeem = item.Rewards.NotifyOnRedeem,
                                    UserFirstName = user.FirstName,
                                    UserLastName = user.LastName,
                                    PartnerName = item.Rewards.PartnerName,
                                    PartnerOwnerEmail = ownerUser != null ? ownerUser.UserName : null,
                                    Category = item.Rewards.RewardCategories.Name
                                });
                            }
                        }
                        else
                        {
                            itemidx = costIndex++;
                            var ownerUser = context.Users.FirstOrDefault(x => x.UserId == item.Rewards.Owner_Id);

                            purchases.Add(new OrderSummaryItemModel
                            {
                                Name = item.Rewards.Name,
                                Points = item.Cost,
                                Quantity = item.Quantity,
                                DollarCost = item.DollarCost,
                                PayPalIndex = itemidx,
                                AttachVoucherUrl = false,
                                VoucherUrl = string.Empty,
                                NotifyOnRedeem = item.Rewards.NotifyOnRedeem,
                                UserFirstName = user.FirstName,
                                UserLastName = user.LastName,
                                PartnerName = item.Rewards.PartnerName,
                                PartnerOwnerEmail = ownerUser != null ? ownerUser.UserName : null,
                                Category = item.Rewards.RewardCategories.Name
                            });
                        }

                       // Remove from cart items after added to purchases
                       context.CartItems.Remove(item);
                    }

                    var transaction = new Transactions
                    {
                        Addresses = user.Addresses,
                        Users1 = user,
                        Time = time,
                        Description = description,
                        Points = -total,
                        TransactionTypeID = transactionType
                    };
                    context.Transactions.Add(transaction);
                    context.SaveChanges();

                    if (dollartotal > 0)
                    {
                        model.CheckoutSubmitModelState = CheckoutSubmitModelState.SuccessWithProductOrderConfirmation;
                    }
                    else
                    {
                        model.CheckoutSubmitModelState = CheckoutSubmitModelState.SuccessWithOrderConfirmation;
                    }

                    model.Purchases = purchases;

                    return model;

                }
                else // User does NOT have enough points to purchase
                {
                    model.CheckoutSubmitModelState = CheckoutSubmitModelState.NotEnoughPoints;
                    return model;
                }
            }
        }
Ejemplo n.º 4
0
        private void AddPoints(greenMoneyEntities context, Users1 user, int numPoints, string description, int? transactionType)
        {
            var transaction = new Transactions
            {
                Addresses = user.Addresses,
                Users1 = user,
                Time = DateTime.Now,
                Description = description,
                Points = numPoints,
                TransactionTypeID = transactionType
            };

            context.Transactions.Add(transaction);
        }