Ejemplo n.º 1
0
        public static void UpdatePayments(decimal newBill = 0)
        {
            var     data         = LoadBills();
            var     numRoommates = RoommateProcessor.LoadRoommates().Count;
            decimal newPayments  = newBill;

            foreach (var item in data)
            {
                newPayments += item.AmountDue;
            }
            newPayments /= numRoommates; //TODO this may need to go now too
            string sql = $"sp_UpdatePayment '{newPayments}'";

            SqlDataAccess.SaveData(sql, newPayments);
        }
        public static int CreatePayment(int billId, int roommateId, decimal amountPaid)
        {
            var bills     = BillProcessor.GetBillById(billId);
            var roommates = RoommateProcessor.GetRoommateById(roommateId);
            var data      = new PaymentModel {
                RoommateId = roommateId,
                BillId     = billId,
                AmountPaid = amountPaid
            };

            //display payment
            string sql = $"sp_AddPayment '{billId}', '{roommateId}', '{amountPaid}'";

            SqlDataAccess.SaveData(sql, data);
            decimal newAmount = bills.AmountDue - amountPaid;

            ApplyPayment(newAmount, billId);
            RemoveAssignedBill(billId, roommateId);
            Utilities.OnBillPaid(billId);
            return(0);
        }