Beispiel #1
0
 private static Action BuildActionModel(string sessionId, MoveMoneyTransaction moveMoneyTransaction,
                                        string description, Participant fromParticipant, Participant toParticipant)
 => new Action
 {
     SessionId   = sessionId,
     Date        = moveMoneyTransaction.Date ?? DateTime.Now,
     Description = description,
     Payers      = new[]
     {
         new Payer
         {
             Amount        = moveMoneyTransaction.Amount,
             ParticipantId = fromParticipant.Id
         }
     },
     Consumptions = new[]
     {
         new Consumption
         {
             Amount          = moveMoneyTransaction.Amount,
             Description     = description,
             Quantity        = 1,
             SplittedEqually = false,
             Consumers       = new[]
             {
                 new Consumer
                 {
                     Amount        = moveMoneyTransaction.Amount,
                     ParticipantId = toParticipant.Id
                 }
             }
         }
     }
 };
        public async Task <Action> Post(string sessionId, [FromBody] MoveMoneyTransaction moveMoneyTransaction)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var sessionModel = await _repository.GetSession(sessionId);

            var actionModel = _moneyMover.CreateMoveMoneyTransaction(sessionModel, moveMoneyTransaction);

            return(await _repository.UpdateAction(sessionId, actionModel));
        }
Beispiel #3
0
        public Action CreateMoveMoneyTransaction(Session session, MoveMoneyTransaction moveMoneyTransaction)
        {
            var fromParticipant = session.Participants.FirstOrDefault(p => p.Name == moveMoneyTransaction.From);
            var toParticipant   = session.Participants.FirstOrDefault(p => p.Name == moveMoneyTransaction.To);

            if (fromParticipant == null || toParticipant == null)
            {
                throw new ArgumentException("Either fromParticipant or toParticipant not exist", nameof(session));
            }

            var description = moveMoneyTransaction.Reason ?? $"{fromParticipant.Name} -> {toParticipant.Name}";

            var actionModel = BuildActionModel(session.Id, moveMoneyTransaction, description, fromParticipant, toParticipant);

            return(actionModel);
        }