/// <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); }
/// <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); }
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(); } }
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 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); }
/// <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(); }
/// <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); }
public void UpdatePoint(RewardPointsHistory point) { if (point == null) { throw new ArgumentNullException("pointHistory"); } _historyRepository.Update(point); //cache _cacheManager.RemoveByPattern(REWARD_PATTERN_KEY); }
/// <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); }
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); }
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)); }
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); } }
/// <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); }
/// <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); }
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)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }