Esempio n. 1
0
 public HttpResponseMessage Post(string id, LoyaltyCardTransaction model)
 {
     try
     {
         if (model != null)
         {
             FamiHub.Models.Customers.Customer       customer = FamiHub.BusinessLayer.Loyalty.Card.GetCustomerByCardNumber(id);
             FamiHub.Models.Customers.LoyaltyPartner partner  = FamiHub.BusinessLayer.Loyalty.Card.GetLoyaltyPartnerById(model.PartnerId);
             if (customer != null && partner != null)
             {
                 FamiHub.BusinessLayer.Loyalty.Transactions.AddPoints(customer, partner, model.Points, model.Comments);
                 var _result = new ViewModels.LoyaltyCardBalance
                 {
                     CardNumber = id,
                     Balance    = Generic.CheckBalance(customer)
                 };
                 return(Request.CreateResponse(HttpStatusCode.OK, _result));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
         }
         return(Request.CreateResponse(HttpStatusCode.NotFound));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
Esempio n. 2
0
        public LoyaltyCardTransactionDTO CreateTransaction(int clientId, string cardNumber, decimal pointsEarned)
        {
            var client = _clientRepository.GetById(clientId);

            if (client == null)
            {
                throw new Exception($"Client with id #{clientId} not found");
            }

            var card = _loyaltyCardRepository.GetByCardNumber(cardNumber);

            if (card == null)
            {
                throw new Exception($"Loyalty card with No #{cardNumber} not found");
            }

            LoyaltyCardTransaction dbTransaction = new LoyaltyCardTransaction
            {
                ClientId            = client.Id,
                CardNumber          = card.Number,
                CreatedAt           = DateTime.UtcNow,
                LoyaltyPointsEarned = pointsEarned
            };

            try
            {
                return(_mapper.Map <LoyaltyCardTransactionDTO>(_loyaltyCardTransactionRepository.Insert(dbTransaction)));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        public virtual void Initialize(LoyaltyCardTransaction transaction)
        {
            Assert.ArgumentNotNull(transaction, "transaction");

            this.ExternalId     = transaction.ExternalId;
            this.EntryTime      = transaction.EntryDateTime.ToShortTimeString();
            this.EntryDate      = transaction.EntryDateTime.ToDisplayedDate();
            this.EntryType      = transaction.EntryType.Name;
            this.ExpirationDate = transaction.ExpirationDate.ToDisplayedDate();
            this.Points         = transaction.RewardPointAmount.ToString(Sitecore.Context.Language.CultureInfo);
            this.Store          = transaction.ShopName;
        }
        /// <summary>
        /// Initializes the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        public virtual void Initialize(LoyaltyCardTransaction transaction)
        {
            Assert.ArgumentNotNull(transaction, "transaction");

            this.ExternalId = transaction.ExternalId;
            this.EntryTime = transaction.EntryDateTime.ToShortTimeString();
            this.EntryDate = transaction.EntryDateTime.ToDisplayedDate();
            this.EntryType = transaction.EntryType.Name;
            this.ExpirationDate = transaction.ExpirationDate.ToDisplayedDate();
            this.Points = transaction.RewardPointAmount.ToString(Sitecore.Context.Language.CultureInfo);
            this.Store = transaction.ShopName;
        }
            /// <summary>
            /// Gets the loyalty card transaction of the given loyalty card and the reward point.
            /// </summary>
            /// <param name="loyaltyCardNumber">The loyalty card number.</param>
            /// <param name="rewardPointId">The readable identifier of the reward point.</param>
            /// <param name="top">The top count, i.e. the number of transactions to get.</param>
            /// <param name="skip">The skip number, i.e. the number of transactions to skip.</param>
            /// <param name="calculateRecordCount">
            /// The flag indicating whether the result should contains the total number of the transactions.
            /// </param>
            /// <returns>The page result containing the collection of loyalty card transactions.</returns>
            public PagedResult <LoyaltyCardTransaction> GetLoyaltyCardTransactions(string loyaltyCardNumber, string rewardPointId, long top, long skip, bool calculateRecordCount)
            {
                var parameters = new object[]
                {
                    loyaltyCardNumber,
                    rewardPointId,
                    top,
                    skip,
                    calculateRecordCount
                };

                var  data       = this.InvokeMethod(GetLoyaltyCardTransactionsMethodName, parameters);
                long?totalCount = null;

                // Translate the result data into a list of loyalty card transactions.
                string statusXML = (string)data[0];

                XDocument doc  = XDocument.Parse(statusXML);
                XElement  root = doc.Elements("LoyaltyCardRewardPointTransactions").SingleOrDefault();
                Collection <LoyaltyCardTransaction> transList = null;

                if (root != null)
                {
                    // Get total count
                    if (calculateRecordCount)
                    {
                        totalCount = Convert.ToInt64(TransactionServiceClient.GetAttributeValue(root, "TotalTransactionNumber"));
                    }

                    // Get transaction list
                    var transElementList = root.Elements("LoyaltyCardRewardPointTransaction");
                    transList = new Collection <LoyaltyCardTransaction>();
                    foreach (var transElement in transElementList)
                    {
                        var trans = new LoyaltyCardTransaction();
                        trans.TransactionId             = TransactionServiceClient.GetAttributeValue(transElement, "TransactionID");
                        trans.RewardPointAmountQuantity = Convert.ToDecimal(TransactionServiceClient.GetAttributeValue(transElement, "RewardPointAmountQty"));
                        trans.EntryType   = (LoyaltyRewardPointEntryType)Convert.ToInt32(TransactionServiceClient.GetAttributeValue(transElement, "EntryType"));
                        trans.ChannelName = TransactionServiceClient.GetAttributeValue(transElement, "ChannelName");

                        string expirationDate = TransactionServiceClient.GetAttributeValue(transElement, "ExpirationDate");
                        if (!string.IsNullOrWhiteSpace(expirationDate))
                        {
                            trans.ExpirationDate = Convert.ToDateTime(expirationDate);
                        }

                        DateTime entryDateTime = Convert.ToDateTime(TransactionServiceClient.GetAttributeValue(transElement, "EntryDate"));
                        string   entryTime     = TransactionServiceClient.GetAttributeValue(transElement, "EntryTime");
                        TimeSpan entryTimeSpan = new TimeSpan();
                        if (TimeSpan.TryParse(entryTime, out entryTimeSpan))
                        {
                            entryDateTime += entryTimeSpan;
                        }

                        trans.EntryDateTime = entryDateTime;

                        transList.Add(trans);
                    }
                }

                var transactions = transList.AsReadOnly();

                return(new PagedResult <LoyaltyCardTransaction>(transactions, new PagingInfo(top, skip), totalCount));
            }