Example #1
0
 public void TransferMoney(Account srcAccount, Account destAccount, decimal transferAmount)
 {
     if (srcAccount.AccountTotal >= transferAmount && transferAmount >= 0)
     {
         srcAccount.AccountTotal -= transferAmount;
         destAccount.AccountTotal += transferAmount;
     }
 }
Example #2
0
        //TODO: Add up the price of all items then do overdrafts at the very end instead of after every item
        public ICollection<Purchase> PurchaseMultipleItems(ICollection<StoreItem> items, Student stud, Account acct, Account savings)
        {
            ICollection<Purchase> purchases = new List<Purchase>();

            foreach (var storeItem in items)
            {
                if ((storeItem.EnergyChange >= 0) || CanCompleteAction(stud.Energy, storeItem.EnergyChange))
                {

                    var purchase = new Purchase { PurchaseDate = DateTime.Now.Date, StoreItemName = storeItem.StoreItemName, ItemPrice = storeItem.ItemPrice, StoreName = storeItem.Store.StoreName, StudentID = stud.UserId };
                    purchases.Add(purchase);

                    stud.Energy += storeItem.EnergyChange;
                    stud.Happiness += storeItem.HappinessChange;
                    stud.Health += storeItem.HealthChange;
                    stud.Hunger += storeItem.HungerChange;
                    stud.Social += storeItem.SocialChange;

                    if (stud.Energy > 100) stud.Energy = 100;
                    if (stud.Happiness > 100) stud.Happiness = 100;
                    if (stud.Health > 100) stud.Health = 100;
                    if (stud.Hunger > 100) stud.Hunger = 100;
                    if (stud.Social > 100) stud.Social = 100;

                    if (stud.Energy < 0) stud.Energy = 0;
                    if (stud.Happiness < 0) stud.Happiness = 0;
                    if (stud.Health < 0) stud.Health = 0;
                    if (stud.Hunger < 0) stud.Hunger = 0;
                    if (stud.Social < 0) stud.Social = 0;

                    if (acct.AccountTotal < storeItem.ItemPrice)
                    {
                        decimal remainder = Math.Abs(acct.AccountTotal - storeItem.ItemPrice);

                        if (savings.AccountTotal >= remainder)
                        {
                            acct.AccountTotal = 0;
                            savings.AccountTotal -= remainder;
                            savings.AccountTotal -= 5;
                            //stud.bBillsPaid = false;
                        }
                        else if (savings.AccountTotal < remainder)
                        {
                            savings.AccountTotal -= remainder;
                            savings.AccountTotal -= 28; //Overdraft
                            //stud.bBillsPaid = false;
                        }
                    }
                    else acct.AccountTotal -= storeItem.ItemPrice;
                }
            }
            return purchases; //Maybe add else return null
        }
Example #3
0
        public Purchase PurchaseSingleItem(StoreItem item, Student stud, Account acct, Account savings)
        {
            if ((item.EnergyChange >= 0) || CanCompleteAction(stud.Energy, item.EnergyChange))
            {

                var purchase = new Purchase { PurchaseDate = DateTime.Now.Date, StoreItemName = item.StoreItemName, ItemPrice = item.ItemPrice, StoreName = item.Store.StoreName, StudentID = stud.UserId };

                stud.Energy += item.EnergyChange;
                stud.Happiness += item.HappinessChange;
                stud.Health += item.HealthChange;
                stud.Hunger += item.HungerChange;
                stud.Social += item.SocialChange;

                if (stud.Energy > 100) stud.Energy = 100;
                if (stud.Happiness > 100) stud.Happiness = 100;
                if (stud.Health > 100) stud.Health = 100;
                if (stud.Hunger > 100) stud.Hunger = 100;
                if (stud.Social > 100) stud.Social = 100;

                if (stud.Energy < 0) stud.Energy = 0;
                if (stud.Happiness < 0) stud.Happiness = 0;
                if (stud.Health < 0) stud.Health = 0;
                if (stud.Hunger < 0) stud.Hunger = 0;
                if (stud.Social < 0) stud.Social = 0;

                if (acct.AccountTotal < item.ItemPrice)
                {
                    decimal remainder = Math.Abs(acct.AccountTotal - item.ItemPrice);

                    if (savings.AccountTotal >= remainder)
                    {
                        acct.AccountTotal = 0;
                        savings.AccountTotal -= remainder;
                        savings.AccountTotal -= 5; //Overdraft
                        stud.bBillsPaid = false;
                    }
                    else if (savings.AccountTotal < remainder)
                    {
                        savings.AccountTotal -= remainder;
                        savings.AccountTotal -= 28; //Overdraft
                        //stud.bBillsPaid = false;
                    }
                }
                else acct.AccountTotal -= item.ItemPrice;

                return purchase;
            }
            else return null;
        }
Example #4
0
 //TODO: Add functionality to handle the eSTATEMENT
 public void PayExpense(Account srcAccount, StudentExpense studentExpense, Student stud, bool bIsLate)
 {
     if (srcAccount.AccountTotal >= studentExpense.CurrentAmountOwed && (studentExpense.CurrentAmountOwed > 0))
     {
         if (bIsLate == true)
         {
             srcAccount.AccountTotal -= studentExpense.CurrentAmountOwed;
             srcAccount.AccountTotal -= studentExpense.Expense.LateFee;
             studentExpense.CurrentAmountOwed = 0;
             stud.bBillsPaid = true;
         }
         else
         {
             srcAccount.AccountTotal -= studentExpense.CurrentAmountOwed;
             studentExpense.CurrentAmountOwed = 0;
             stud.bBillsPaid = true;
         }
     }
 }
Example #5
0
        public ActionResult Create(Student model)
        {
            var userProfile = db.UserProfiles.Local.SingleOrDefault(u => u.UserName == User.Identity.Name)
                ?? db.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name);

            Account CheckingsAccount = new Account { AccountName = "Checkings", AccountTotal = 100, StudentID = userProfile.UserId };
            Account SavingsAccount = new Account { AccountName = "Savings", AccountTotal = 100, StudentID = userProfile.UserId };

            //Additional Expenses will be included after purchase of things such as a house or other items.

            StudentExpense PhoneBill = new StudentExpense { ExpenseAccountNumber = "123456789", Name = "Phone Payment", Company = "Telecom Co.", bMissedPayment = false, CurrentAmountOwed = 0, StudentID = userProfile.UserId, bIsRecurring = false, ExpenseID = 1 };

            Classroom classroom = db.Classrooms.Find(model.ClassroomID);

            Student student = new Student
            {
                UserId = userProfile.UserId,
                FirstName = model.FirstName,
                LastName = model.LastName,
                EmailAddress = model.EmailAddress,
                ClassroomID = model.ClassroomID,
                bBillsPaid = true,
                bAlertSetup = false,
                AccountThreshold = 0,
                AlertAccountID = null,
                Happiness = 50,
                Health = 70,
                Hunger = 60,
                Social = 50,
                Energy = 80,
                Points = 0,
                CreditScore = 0
            };

            if (ModelState.IsValid && (classroom != null))
            {
                try
                {
                    if (userProfile != null)
                    {
                        db.Students.Add(student);
                        db.SaveChanges();

                        db.Entry(student).State = EntityState.Modified;
                        db.SaveChanges();

                        db.Accounts.Add(CheckingsAccount);
                        db.SaveChanges();

                        db.Accounts.Add(SavingsAccount);
                        db.SaveChanges();

                        db.StudentExpenses.Add(PhoneBill);
                        db.SaveChanges();

                        return RedirectToAction("Index", "Student");
                    }
                }
                catch (DataException)
                {
                    ModelState.AddModelError("","Something went wrong, try again.");
                }
            }
            return RedirectToAction("Create");
        }