예제 #1
0
        /// <summary>
        /// Add reward points history record
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="points">Number of points to add</param>
        /// <param name="storeId">Store identifier</param>
        /// <param name="message">Message</param>
        /// <param name="usedWithOrder">the order for which points were redeemed as a payment</param>
        /// <param name="usedAmount">Used amount</param>
        public virtual void AddRewardPointsHistoryEntry(Customer customer,
                                                        int points, int storeId, string message = "",
                                                        Order usedWithOrder = null, decimal usedAmount = 0M)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            if (storeId <= 0)
            {
                throw new ArgumentException("Store ID should be valid");
            }

            var rph = new RewardPointsHistory
            {
                Customer      = customer,
                StoreId       = storeId,
                UsedWithOrder = usedWithOrder,
                Points        = points,
                PointsBalance = GetRewardPointsBalance(customer.Id, storeId) + points,
                UsedAmount    = usedAmount,
                Message       = message,
                CreatedOnUtc  = DateTime.UtcNow
            };

            _rphRepository.Insert(rph);

            //event notification
            _eventPublisher.EntityInserted(rph);
        }
예제 #2
0
        /// <summary>
        /// Add reward points history record
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="points">Number of points to add</param>
        /// <param name="storeId">Store identifier</param>
        /// <param name="message">Message</param>
        /// <param name="usedWithSubscription">The subscription for which points were redeemed (spent) as a payment</param>
        /// <param name="usedAmount">Used amount</param>
        /// <param name="activatingDate">Date and time of activating reward points; pass null to immediately activating</param>
        /// <returns>Reward points history entry identifier</returns>
        public virtual int AddRewardPointsHistoryEntry(Customer customer, int points, int storeId, string message = "",
                                                       Subscription usedWithSubscription = null, decimal usedAmount = 0M, DateTime?activatingDate = null)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            if (storeId <= 0)
            {
                throw new ArgumentException("Store ID should be valid");
            }

            var rph = new RewardPointsHistory
            {
                Customer             = customer,
                StoreId              = storeId,
                UsedWithSubscription = usedWithSubscription,
                Points        = points,
                PointsBalance = activatingDate.HasValue ? null : (int?)(GetRewardPointsBalance(customer.Id, storeId) + points),
                UsedAmount    = usedAmount,
                Message       = message,
                CreatedOnUtc  = activatingDate ?? DateTime.UtcNow
            };

            _rphRepository.Insert(rph);

            //event notification
            _eventPublisher.EntityInserted(rph);

            return(rph.Id);
        }
예제 #3
0
        public void WriteRewardPointsHistory(dynamic rewardPoints, string node)
        {
            if (rewardPoints == null)
            {
                return;
            }

            if (node.HasValue())
            {
                _writer.WriteStartElement(node);
            }

            foreach (dynamic rewardPoint in rewardPoints)
            {
                RewardPointsHistory entity = rewardPoint.Entity;

                _writer.WriteStartElement("RewardPointsHistory");
                _writer.Write("Id", entity.ToString());
                _writer.Write("CustomerId", entity.ToString());
                _writer.Write("Points", entity.Points.ToString());
                _writer.Write("PointsBalance", entity.PointsBalance.ToString());
                _writer.Write("UsedAmount", entity.UsedAmount.ToString(_culture));
                _writer.Write("Message", (string)rewardPoint.Message);
                _writer.Write("CreatedOnUtc", entity.CreatedOnUtc.ToString(_culture));
                _writer.WriteEndElement();                      // RewardPointsHistory
            }

            if (node.HasValue())
            {
                _writer.WriteEndElement();
            }
        }
예제 #4
0
        public void Can_save_and_load_rewardPointsHistory()
        {
            var rewardPointsHistory = new RewardPointsHistory
            {
                Customer      = GetTestCustomer(),
                StoreId       = 1,
                Points        = 2,
                Message       = "Points for registration",
                PointsBalance = 3,
                UsedAmount    = 3.1M,
                CreatedOnUtc  = new DateTime(2010, 01, 01)
            };

            var fromDb = SaveAndLoadEntity(rewardPointsHistory);

            fromDb.ShouldNotBeNull();
            fromDb.StoreId.ShouldEqual(1);
            fromDb.Points.ShouldEqual(2);
            fromDb.Message.ShouldEqual("Points for registration");
            fromDb.PointsBalance.ShouldEqual(3);
            fromDb.UsedAmount.ShouldEqual(3.1M);
            fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01));

            fromDb.Customer.ShouldNotBeNull();
        }
예제 #5
0
        /// <summary>
        /// Add reward points history record
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="points">Number of points to add</param>
        /// <param name="storeId">Store identifier</param>
        /// <param name="message">Message</param>
        /// <param name="usedWithOrder">The order for which points were redeemed (spent) as a payment</param>
        /// <param name="usedAmount">Used amount</param>
        /// <param name="activatingDate">Date and time of activating reward points; pass null to immediately activating</param>
        /// <param name="endDate">Date and time when the reward points will no longer be valid; pass null to add date termless points</param>
        /// <returns>Reward points history entry identifier</returns>
        public virtual int AddRewardPointsHistoryEntry(Customer customer, int points, int storeId, string message = "",
                                                       Order usedWithOrder = null, decimal usedAmount = 0M, DateTime?activatingDate = null, DateTime?endDate = null)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            if (storeId == 0)
            {
                throw new ArgumentException("Store ID should be valid");
            }

            if (points < 0 && endDate.HasValue)
            {
                throw new ArgumentException("End date is available only for positive points amount");
            }

            //insert new history entry
            var newHistoryEntry = new RewardPointsHistory
            {
                Customer      = customer,
                StoreId       = storeId,
                UsedWithOrder = usedWithOrder,
                Points        = points,
                PointsBalance = activatingDate.HasValue ? null : (int?)(GetRewardPointsBalance(customer.Id, storeId) + points),
                UsedAmount    = usedAmount,
                Message       = message,
                CreatedOnUtc  = activatingDate ?? DateTime.UtcNow,
                EndDateUtc    = endDate,
                ValidPoints   = points > 0 ? (int?)points : null
            };

            InsertRewardPointsHistoryEntry(newHistoryEntry);

            //reduce valid points of previous entries
            if (points >= 0)
            {
                return(newHistoryEntry.Id);
            }

            var withValidPoints = GetRewardPointsQuery(customer.Id, storeId)
                                  .Where(historyEntry => historyEntry.ValidPoints > 0)
                                  .OrderBy(historyEntry => historyEntry.CreatedOnUtc).ThenBy(historyEntry => historyEntry.Id).ToList();

            foreach (var historyEntry in withValidPoints)
            {
                points += historyEntry.ValidPoints.Value;
                historyEntry.ValidPoints = Math.Max(points, 0);
                UpdateRewardPointsHistoryEntry(historyEntry);

                if (points >= 0)
                {
                    break;
                }
            }

            return(newHistoryEntry.Id);
        }
예제 #6
0
        /// <summary>
        /// Updates the reward point history entry
        /// </summary>
        /// <param name="rewardPointsHistory">Reward point history entry</param>
        public virtual void UpdateRewardPointsHistoryEntry(RewardPointsHistory rewardPointsHistory)
        {
            if (rewardPointsHistory == null)
            {
                throw new ArgumentNullException("rewardPointsHistory");
            }

            _rphRepository.Update(rewardPointsHistory);

            _baseService.Commit();
        }
예제 #7
0
        /// <summary>
        /// Updates the reward point history entry
        /// </summary>
        /// <param name="rewardPointsHistory">Reward point history entry</param>
        public virtual void UpdateRewardPointsHistoryEntry(RewardPointsHistory rewardPointsHistory)
        {
            if (rewardPointsHistory == null)
            {
                throw new ArgumentNullException("rewardPointsHistory");
            }

            _rphRepository.Update(rewardPointsHistory);

            //event notification
            _eventPublisher.EntityUpdated(rewardPointsHistory);
        }
예제 #8
0
        public void UpdatePoint(RewardPointsHistory point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("pointHistory");
            }

            _historyRepository.Update(point);

            //cache
            _cacheManager.RemoveByPattern(REWARD_PATTERN_KEY);
        }
예제 #9
0
        /// <summary>
        /// Delete the reward point history entry
        /// </summary>
        /// <param name="rewardPointsHistory">Reward point history entry</param>
        public virtual void DeleteRewardPointsHistoryEntry(RewardPointsHistory rewardPointsHistory)
        {
            if (rewardPointsHistory == null)
            {
                throw new ArgumentNullException(nameof(rewardPointsHistory));
            }

            _rewardPointsHistoryRepository.Delete(rewardPointsHistory);

            //event notification
            _eventPublisher.EntityDeleted(rewardPointsHistory);
        }
예제 #10
0
        protected virtual object CreateModelPart(RewardPointsHistory part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "Id", part.Id },
                { "CreatedOn", ToUserDate(part.CreatedOnUtc, messageContext) },
                { "Message", part.Message.NullEmpty() },
                { "Points", part.Points },
                { "PointsBalance", part.PointsBalance },
                { "UsedAmount", part.UsedAmount }
            };

            PublishModelPartCreatedEvent <RewardPointsHistory>(part, m);

            return(m);
        }
예제 #11
0
        public static void AddRewardPointsHistoryEntry(this Customer customer,
                                                       int points, string message = "",
                                                       Order usedWithOrder        = null, decimal usedAmount = 0M)
        {
            int newPointsBalance = customer.GetRewardPointsBalance() + points;

            var rewardPointsHistory = new RewardPointsHistory()
            {
                Customer      = customer,
                UsedWithOrder = usedWithOrder,
                Points        = points,
                PointsBalance = newPointsBalance,
                UsedAmount    = usedAmount,
                Message       = message,
                CreatedOnUtc  = DateTime.UtcNow
            };

            customer.RewardPointsHistory.Add(rewardPointsHistory);
        }
예제 #12
0
        public void Can_save_and_load_rewardPointsHistory_with_order()
        {
            var rewardPointsHistory = new RewardPointsHistory()
            {
                Customer      = GetTestCustomer(),
                UsedWithOrder = GetTestOrder(),
                Points        = 1,
                Message       = "Points for registration",
                PointsBalance = 2,
                UsedAmount    = 3,
                CreatedOnUtc  = new DateTime(2010, 01, 01)
            };

            var fromDb = SaveAndLoadEntity(rewardPointsHistory);

            fromDb.ShouldNotBeNull();

            fromDb.UsedWithOrder.ShouldNotBeNull();
            fromDb.UsedWithOrder.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01));
        }
예제 #13
0
        protected void btnAddPoints_Click(object sender, EventArgs e)
        {
            try
            {
                Customer customer = CustomerManager.GetCustomerById(this.CustomerId);
                if (customer != null)
                {
                    int    points           = txtNewPoints.Value;
                    string message          = txtNewMessage.Text;
                    RewardPointsHistory rph = OrderManager.InsertRewardPointsHistory(
                        this.CustomerId, 0, points, decimal.Zero, decimal.Zero,
                        string.Empty, message, DateTime.Now);

                    BindData();
                }
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }
예제 #14
0
        /// <summary>
        /// Add reward points
        /// </summary>
        /// <param name="customerId">Customer Id</param>
        /// <param name="points">Points</param>
        /// <param name="message">Message</param>
        /// <param name="usedWithOrderId">Used with OrderId</param>
        /// <param name="usedAmount">Used amount</param>
        /// <returns>RewardPointsHistory</returns>

        public virtual async Task <RewardPointsHistory> AddRewardPointsHistory(string customerId, int points, string storeId, string message = "",
                                                                               string usedWithOrderId = "", decimal usedAmount = 0M)
        {
            var rewardPointsHistory = new RewardPointsHistory
            {
                CustomerId      = customerId,
                UsedWithOrderId = usedWithOrderId,
                Points          = points,
                PointsBalance   = await GetRewardPointsBalance(customerId, storeId) + points,
                UsedAmount      = usedAmount,
                Message         = message,
                StoreId         = storeId,
                CreatedOnUtc    = DateTime.UtcNow
            };
            await _rphRepository.InsertAsync(rewardPointsHistory);

            //event notification
            await _mediator.EntityInserted(rewardPointsHistory);

            return(rewardPointsHistory);
        }
예제 #15
0
        /// <summary>
        /// Add reward points
        /// </summary>
        /// <param name="customerId">Customer Id</param>
        /// <param name="points">Points</param>
        /// <param name="message">Message</param>
        /// <param name="usedWithOrderId">Used with OrderId</param>
        /// <param name="usedAmount">Used amount</param>
        /// <returns>RewardPointsHistory</returns>

        public RewardPointsHistory AddRewardPointsHistory(int customerId, int points, int storeId, string message = "",
                                                          int usedWithOrderId = 0, decimal usedAmount = 0M)
        {
            var rewardPointsHistory = new RewardPointsHistory
            {
                CustomerId      = customerId,
                UsedWithOrderId = usedWithOrderId,
                Points          = points,
                PointsBalance   = GetRewardPointsBalance(customerId, storeId) + points,
                UsedAmount      = usedAmount,
                Message         = message,
                CreatedOnUtc    = DateTime.UtcNow
            };

            _rphRepository.Insert(rewardPointsHistory);

            //event notification
            _eventPublisher.EntityInserted(rewardPointsHistory);

            return(rewardPointsHistory);
        }
예제 #16
0
        public void Can_save_and_load_rewardPointHistory()
        {
            var rph = new RewardPointsHistory
            {
                StoreId       = 1,
                Customer      = GetTestCustomer(),
                Points        = 2,
                PointsBalance = 3,
                UsedAmount    = 4,
                Message       = "Message 5",
                CreatedOnUtc  = new DateTime(2010, 01, 04)
            };

            var fromDb = SaveAndLoadEntity(rph);

            fromDb.ShouldNotBeNull();
            fromDb.StoreId.ShouldEqual(1);
            fromDb.Customer.ShouldNotBeNull();
            fromDb.Points.ShouldEqual(2);
            fromDb.PointsBalance.ShouldEqual(3);
            fromDb.UsedAmount.ShouldEqual(4);
            fromDb.Message.ShouldEqual("Message 5");
            fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 04));
        }
예제 #17
0
 /// <summary>
 /// Insert the reward point history entry
 /// </summary>
 /// <param name="rewardPointsHistory">Reward point history entry</param>
 /// <returns>A task that represents the asynchronous operation</returns>
 protected virtual async Task InsertRewardPointsHistoryEntryAsync(RewardPointsHistory rewardPointsHistory)
 {
     await _rewardPointsHistoryRepository.InsertAsync(rewardPointsHistory);
 }
예제 #18
0
 /// <summary>
 /// Insert the reward point history entry
 /// </summary>
 /// <param name="rewardPointsHistory">Reward point history entry</param>
 public virtual void InsertRewardPointsHistoryEntry(RewardPointsHistory rewardPointsHistory)
 {
     _rewardPointsHistoryRepository.Insert(rewardPointsHistory);
 }
예제 #19
0
 /// <summary>
 /// Delete the reward point history entry
 /// </summary>
 /// <param name="rewardPointsHistory">Reward point history entry</param>
 /// <returns>A task that represents the asynchronous operation</returns>
 public virtual async Task DeleteRewardPointsHistoryEntryAsync(RewardPointsHistory rewardPointsHistory)
 {
     await _rewardPointsHistoryRepository.DeleteAsync(rewardPointsHistory);
 }
예제 #20
0
 /// <summary>
 /// Delete the reward point history entry
 /// </summary>
 /// <param name="rewardPointsHistory">Reward point history entry</param>
 public virtual void DeleteRewardPointsHistoryEntry(RewardPointsHistory rewardPointsHistory)
 {
     _rewardPointsHistoryRepository.Delete(rewardPointsHistory);
 }