Exemplo n.º 1
0
        //GET: WeeklyReports/StartNewWeek
        //public ActionResult StartNewWeek()
        //{
        //    var currentUserId = User.Identity.GetUserId();
        //    if (currentUserId == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    WeeklyReport weeklyReport = db.WeeklyReports.Where(x => x.UserId == currentUserId).FirstOrDefault();
        //    if (weeklyReport == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View();
        //}
        ////POST: WeeklyReports/StartNewWeek
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult StartNewWeek(/*[Bind(Include = "WeekOf,WeeklyIncome,WeeklyBudget,Spending,Balance")] WeeklyReport weeklyReport*/)
        {
            var            currentUserId   = User.Identity.GetUserId();
            Budget         budget          = db.Budgets.Where(x => x.UserId == currentUserId).FirstOrDefault();
            WeeklyReport   myWeeklyReport  = db.WeeklyReports.Where(x => x.UserId == currentUserId).FirstOrDefault();
            WeeklyReport   newWeeklyReport = new WeeklyReport();
            SpendingHabits spendingHabits  = new SpendingHabits();

            db.SpendingHabits.Add(spendingHabits);

            spendingHabits.UserId        = currentUserId;
            spendingHabits.WeekOf        = myWeeklyReport.WeekOf;
            spendingHabits.WeekTotal     = (myWeeklyReport.WeeklyIncome - myWeeklyReport.Spending);
            spendingHabits.BudgetBalance = myWeeklyReport.Balance;
            spendingHabits.CashTotal    += (myWeeklyReport.WeeklyIncome - myWeeklyReport.Spending);
            //spendingHabits.AssetTotal +=
            spendingHabits.AccountTotal += spendingHabits.CashTotal + spendingHabits.AssetTotal;

            db.WeeklyReports.Remove(myWeeklyReport);
            db.WeeklyReports.Add(newWeeklyReport);

            newWeeklyReport.UserId       = currentUserId;
            newWeeklyReport.WeekOf       = DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek));
            newWeeklyReport.WeeklyIncome = budget.WeeklyWage;
            newWeeklyReport.WeeklyBudget = budget.Bills + budget.Groceries + budget.Transportation + budget.GoingOutFund;
            newWeeklyReport.Balance      = newWeeklyReport.WeeklyBudget - newWeeklyReport.Spending;

            db.SaveChanges();

            return(RedirectToAction("Details", new { id = myWeeklyReport.Id }));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SpendingHabits spendingHabits = db.SpendingHabits.Find(id);

            db.SpendingHabits.Remove(spendingHabits);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,UserId,CashTotal,AssetTotal,AccountTotal")] SpendingHabits spendingHabits)
 {
     if (ModelState.IsValid)
     {
         db.Entry(spendingHabits).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.UserId = new SelectList(db.ApplicationUsers, "Id", "Email", spendingHabits.UserId);
     return(View(spendingHabits));
 }
        // GET: SpendingHabits/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SpendingHabits spendingHabits = db.SpendingHabits.Find(id);

            if (spendingHabits == null)
            {
                return(HttpNotFound());
            }
            return(View(spendingHabits));
        }
        // GET: SpendingHabits/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SpendingHabits spendingHabits = db.SpendingHabits.Find(id);

            if (spendingHabits == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.UserId = new SelectList(db.ApplicationUsers, "Id", "Email", spendingHabits.UserId);
            return(View(spendingHabits));
        }