public async Task <IActionResult> PostTransfer([FromBody] Transaction value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var from = _tellerRepository.Query().Where(i => i.TellerId == value.TellerId).FirstOrDefault();

            if (from == null)
            {
                return(BadRequest("You Are not allowed to Make Transfer"));
            }

            var to = _nominalRepository.Query().Where(i => i.NominalId == value.NominalId).FirstOrDefault();

            if (to == null)
            {
                return(BadRequest($"There is no valid Nominal with Id {value.NominalId}"));
            }
            value.NominalId = to.NominalId; value.Type = "Debit"; value.Source = "Financial Transfer";
            value.TellerId  = null;
            var tell = new Transaction()
            {
                TransCode = value.TransCode, Amount = value.Amount,
                Method    = value.Method, Source = "Financial Transfer",
                Type      = "Credit", NominalId = from.NominalId,
                TellerId  = from.TellerId, Reference = value.Reference,
                UserId    = value.UserId, Date = value.Date
            };
            await _transactionRepository.InsertAsync(value);

            await _transactionRepository.InsertAsync(tell);

            return(Created($"transaction/{value.TransactionId}", value));
        }
        public async Task <IActionResult> Post([FromBody] Teller value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var app = _tellerRepository.Query().Any(u => u.Id.Equals(value.Id));

            if (app)
            {
                return(BadRequest("User is Already a Valid Teller"));
            }

            await _tellerRepository.InsertAsync(value);

            var teller = _tellerRepository.GetAll().Where(i => i.Id == value.Id).Select(t => new {
                t.Id,
                t.Nominal.Code,
                Name      = t.Nominal.Description,
                User      = t.AppUser.UserName,
                NoOfTrans = t.Transactions.Where(c => c.UserId == t.Id).Count()
            }).ToList();

            return(Created($"teller/{value.Id}", teller));
        }
        public async Task <IActionResult> GetOrderSummary([FromRoute] string id, DateTime date)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var order = _orderRepository.GetTodayOrders(date).Where(c => c.UserId == id);
            var now   = date;

            var sum = _tellerRepository.Query().Where(t => t.Id.Equals(id)).FirstOrDefault();

            if (sum == null)
            {
                return(BadRequest("You Are not A Valid Teller"));
            }
            var cash = new
            {
                Opening = _transactionRepository.Query().Where(c => c.Type == "Credit" && c.NominalId == sum.NominalId &&
                                                               c.TellerId == sum.TellerId && c.Date < now).Select(a => a.Amount).Sum()
                          - _transactionRepository.Query().Where(c => c.Type == "Debit" && c.NominalId == sum.NominalId &&
                                                                 c.TellerId == sum.TellerId && c.Date.Date < now).Select(a => a.Amount).Sum(),
                Credit = _transactionRepository.Query().Where(c => c.Type == "Credit" && c.NominalId == sum.NominalId &&
                                                              c.TellerId == sum.TellerId && c.Date.Date == now).Select(a => a.Amount).Sum(),
                Debit = _transactionRepository.Query().Where(c => c.Type == "Debit" && c.NominalId == sum.NominalId &&
                                                             c.TellerId == sum.TellerId && c.Date.Date == now).Select(a => a.Amount).Sum(),
                Balance = (_transactionRepository.Query().Where(c => c.Type == "Credit" && c.NominalId == sum.NominalId &&
                                                                c.TellerId == sum.TellerId && c.Date.Date == now).Select(a => a.Amount).Sum()
                           - _transactionRepository.Query().Where(c => c.Type == "Debit" && c.NominalId == sum.NominalId &&
                                                                  c.TellerId == sum.TellerId && c.Date.Date == now).Select(a => a.Amount).Sum())
                          + (_transactionRepository.Query().Where(c => c.Type == "Credit" && c.NominalId == sum.NominalId &&
                                                                  c.TellerId == sum.TellerId && c.Date < now).Select(a => a.Amount).Sum()
                             - _transactionRepository.Query().Where(c => c.Type == "Debit" && c.NominalId == sum.NominalId &&
                                                                    c.TellerId == sum.TellerId && c.Date.Date < now).Select(a => a.Amount).Sum())
            };

            return(Ok(new { order, cash }));
        }