예제 #1
0
        public void Save(ApplicationDbContext db, TextWriter log)
        {
            var debts = SplitBill(log);

            var bs = new BillSplit()
            {
                Name = mName
            };

            db.BillSplit.Add(bs);
            foreach (var(debtor, creditor, pennies) in debts)
            {
                var t = new Transaction()
                {
                    Id          = Guid.NewGuid(),
                    Creditor    = creditor,
                    Debtor      = debtor,
                    Amount      = pennies,
                    Bill        = bs,
                    Description = mName,
                    Created     = mDate,
                };
                db.Transaction.Add(t);
            }

            db.SaveChanges();
        }
        UpdateBillSplitAsync(BillSplit objBillSplit)
        {
            var ExistingBillSplit =
                _context.BillSplit
                .Where(x => x.Id == objBillSplit.Id)
                .FirstOrDefault();

            if (ExistingBillSplit != null)
            {
                ExistingBillSplit.Date =
                    objBillSplit.Date;
                ExistingBillSplit.RecipientName =
                    objBillSplit.RecipientName;
                ExistingBillSplit.Amount =
                    objBillSplit.Amount;
                ExistingBillSplit.UserName =
                    objBillSplit.UserName;
                ExistingBillSplit.Description =
                    objBillSplit.Description;
                ExistingBillSplit.Currency =
                    objBillSplit.Currency;

                _context.SaveChanges();
            }
            else
            {
                return(Task.FromResult(false));
            }
            return(Task.FromResult(true));
        }
        DeleteBillSplitAsync(BillSplit objBillSplit)
        {
            var ExistingBillSplit =
                _context.BillSplit
                .Where(x => x.Id == objBillSplit.Id)
                .FirstOrDefault();

            if (ExistingBillSplit != null)
            {
                _context.BillSplit.Remove(ExistingBillSplit);
                _context.SaveChanges();
            }
            else
            {
                return(Task.FromResult(false));
            }
            return(Task.FromResult(true));
        }
예제 #4
0
        public ActionResult PostBillSplit([FromBody] BillSplit billSplit)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _db.BillSplits.Add(billSplit);
                    _db.SaveChanges();
                    foreach (var p in billSplit.Peers)
                    {
                        var s = _db.UserAccounts.SingleOrDefault(x => x.PromptPay == p.PromptPay);
                        if (s != null)
                        {
                            p.UserAccountId = s.UserId;
                        }

                        p.BillSplitId = billSplit.Id;

                        var WithServiceCharge = p.PersonalTotalPrice + (billSplit.ServiceCharge * p.PersonalTotalPrice) / 100;
                        p.PersonalNetPrice = WithServiceCharge + (billSplit.Vat * WithServiceCharge) / 100;

                        p.StatusId = _statuses.SingleOrDefault(x => x.Name == "Pending").Id;
                        _db.Peers.Add(p);
                        _db.SaveChanges();
                        SendRTP(p);
                    }

                    billSplit.CreatedDateTime = DateTime.Now;

                    _db.SaveChanges();
                    return(Json(billSplit));
                }
                return(Json("Model State is not valid"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(Json(e.InnerException.Message));
            }
        }
예제 #5
0
        private void TapGestureRecognizer_Tapped_1(object sender, EventArgs e)
        {
            if (ShowKeys)
            {
                PeopleCountSlider.FadeTo(0, 1);
                PeopleCountSlider.InputTransparent = true;
                TipSelector.FadeTo(0, 1);
                TipSelector.InputTransparent = true;
                Keypad.FadeTo(0, 1);
                Keypad.InputTransparent = true;

                BillSplit.FadeTo(1, 1);

                BillSplit.InputTransparent = false;

                //if (BillSplit.TranslationY >= 0)
                //    BillSplit.TranslateTo(0, -(MainGrid.RowDefinitions[4].Height.Value / 100 * Height), 500);

                BillSplit.SplitBill();
                BillSplit.TranslateTo(0, 0, 500);
            }
            else
            {
                BillSplit.FadeTo(0, 1);
                BillSplit.InputTransparent = true;
                //BillSplit.TranslateTo(0, -BillSplit.Height, 0);

                PeopleCountSlider.FadeTo(1, 1);
                PeopleCountSlider.InputTransparent = false;
                TipSelector.FadeTo(1, 1);
                TipSelector.InputTransparent = false;
                Keypad.FadeTo(1, 1);
                Keypad.InputTransparent = false;
            }

            ShowKeys = !ShowKeys;
        }
 CreateBillSplitAsync(BillSplit objBillSplit)
 {
     _context.BillSplit.Add(objBillSplit);
     _context.SaveChanges();
     return(Task.FromResult(objBillSplit));
 }
예제 #7
0
        private static void DebtTransfer(ApplicationDbContext db, Person debtor, Person oldCreditor, Person newCreditor, DateTime when)
        {
            var netMoney = DebtGraph.CalculateDebts(db, new[] { debtor, oldCreditor }, false, null);

            if (netMoney.Count != 1)
            {
                throw new Exception("No debt to transfer.");
            }

            var theDebt = netMoney[0];

            if (theDebt.Debtor.Id != debtor.Id || theDebt.Creditor.Id != oldCreditor.Id)
            {
                throw new Exception("Debt does not go in the expected direction.");
            }

            var msg = Transaction.CreateDebtTransferString(debtor, oldCreditor, newCreditor);

            var bs = new BillSplit();

            bs.Name = msg;
            db.BillSplit.Add(bs);

            var cancelTrans = new Transaction()
            {
                Id          = Guid.NewGuid(),
                DebtorId    = oldCreditor.Id, //owes money
                CreditorId  = debtor.Id,      //owed money
                Amount      = theDebt.Amount,
                Bill        = bs,
                Description = msg,
                Created     = when
            };

            db.Transaction.Add(cancelTrans);

            var makeCreditorWholeTransaction = new Transaction()
            {
                Id          = Guid.NewGuid(),
                DebtorId    = newCreditor.Id, //owes money
                CreditorId  = oldCreditor.Id, //owed money
                Amount      = theDebt.Amount,
                Bill        = bs,
                Description = msg,
                Created     = when
            };

            db.Transaction.Add(makeCreditorWholeTransaction);

            var makeDebtorOweNewPartyTrans = new Transaction()
            {
                Id          = Guid.NewGuid(),
                DebtorId    = debtor.Id,      //owes money
                CreditorId  = newCreditor.Id, //owed money
                Amount      = theDebt.Amount,
                Bill        = bs,
                Description = msg,
                Created     = when
            };

            db.Transaction.Add(makeDebtorOweNewPartyTrans);

            db.SaveChanges();
        }