コード例 #1
0
        public async Task <IStandardReply <IEnumerable <Coin> > > AddCoinToTillAsync(Coin coin, int quantity, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            coin.Quantity = quantity;
            try
            {
                var result = await AddCoinToTillAsync(coin, userId, applicationId);

                if (result.Success)
                {
                    reply = await GetTillAsync(userId, applicationId);
                }
                else
                {
                    reply.Messages.AddRange(result.Messages);
                    reply.Exceptions.AddRange(result.Exceptions);
                    reply.Success = false;
                }
            }
            catch (Exception exc)
            {
                reply.ProcessException(exc, coin, logger, MethodBase.GetCurrentMethod().Name, false);
            }
            return(reply);
        }
コード例 #2
0
        public async Task <IStandardReply <decimal> > GetTillCurrentAmount(long userId, long applicationId)
        {
            IStandardReply <decimal> reply = StandardReply <decimal> .CreateInstance();

            var till = await GetTillAsync(userId, applicationId);

            reply.Response = till.Response.Sum(t => t.Quantity * t.Type.Value);
            return(reply);
        }
コード例 #3
0
        public async Task <IStandardReply <IEnumerable <Coin> > > AddCoinToTillAsync(long typeId, int quantity, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            Coin coin = Coin.CreateInstance <Coin>(userId, applicationId);

            coin.Quantity   = quantity;
            coin.CoinTypeId = typeId;
            return(await AddCoinToTillAsync(coin, quantity, userId, applicationId));
        }
コード例 #4
0
        public async Task <IStandardReply <IEnumerable <Coin> > > AdjustTillAsync(IEnumerable <Coin> coins, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            try
            {
                coins.ToList().ForEach(async(coin) => {
                    Coin lc      = (await repo.GetSingleAsync <Coin>(coin.ID, userId, applicationId)).Response;
                    lc.Quantity -= coin.Quantity;
                    await repo.SaveAsync <Coin>(lc, userId, applicationId);
                });
            }
            catch (Exception exc)
            {
                reply.ProcessException(exc, coins, logger, MethodBase.GetCurrentMethod().Name, false);
            }
            return(reply);
        }
コード例 #5
0
        public async Task <IStandardReply <IEnumerable <Coin> > > SwapTillAsync(IEnumerable <Coin> coins, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            try
            {
                (await GetTillAsync(userId, applicationId)).Response.ToList().ForEach(async(coin) => {
                    var result = await DeleteAsync <Coin>(coin.ID, userId, applicationId);
                    reply.Messages.AddRange(result.Messages);
                    reply.Exceptions.AddRange(result.Exceptions);
                });
                reply = await FillTillAsync(coins, userId, applicationId);
            }
            catch (Exception exc)
            {
                reply.ProcessException(exc, coins, logger, MethodBase.GetCurrentMethod().Name, false);
            }
            return(reply);
        }
コード例 #6
0
        public async Task <IStandardReply <IEnumerable <Coin> > > FillTillAsync(IEnumerable <Coin> coins, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            try
            {
                coins.ToList().ForEach(async(coin) => {
                    var result = await AddCoinToTillAsync(coin, userId, applicationId);
                    if (!result.Success)
                    {
                        reply.Messages.AddRange(result.Messages);
                        reply.Exceptions.AddRange(result.Exceptions);
                        reply.Success = false;
                    }
                });
            }
            catch (Exception exc)
            {
                reply.ProcessException(exc, coins, logger, MethodBase.GetCurrentMethod().Name, false);
            }
            return(reply);
        }
コード例 #7
0
        public async Task <IStandardReply <IEnumerable <Coin> > > GetCorrectChangeAsync(decimal amountToChange, long userId, long applicationId)
        {
            IStandardReply <IEnumerable <Coin> > reply = StandardReply <IEnumerable <Coin> > .CreateInstance();

            try
            {
                List <Coin> change = new List <Coin>();
                while (amountToChange > 0)
                {
                    Coin currentCoin = await coinChecker(amountToChange, userId, applicationId);

                    change.Add(currentCoin);
                    amountToChange -= currentCoin.Quantity * currentCoin.Type.Value;
                }
                await AdjustTillAsync(change, userId, applicationId);

                reply.Response = change;
            }
            catch (Exception exc)
            {
                reply.ProcessException(exc, new { amountToChange }, logger, MethodBase.GetCurrentMethod().Name, false);
            }
            return(reply);
        }