/// <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); }
public virtual void AddRewardPointsHistoryEntry(int points, string message = "", Order usedWithOrder = null, decimal usedAmount = 0M) { int newPointsBalance = this.GetRewardPointsBalance() + points; var rewardPointsHistory = new RewardPointsHistory() { Customer = this, UsedWithOrder = usedWithOrder, Points = points, PointsBalance = newPointsBalance, UsedAmount = usedAmount, Message = message, CreatedOnUtc = DateTime.UtcNow }; this.RewardPointsHistory.Add(rewardPointsHistory); }
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); }
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)); }
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)); }
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(); }
/// <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; }
/// <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); }