public IActionResult Edit(IncomeFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                Account s = _accountRepo.Accounts.Where(x => x.TypeID == _accountTypeRepo.AccountTypes.Where(y => y.Name.Equals("Personal")).FirstOrDefault().ID).FirstOrDefault();
                if (model.Income.ID == 0)
                {
                    s.Amount = Math.Round(s.Amount + model.Income.Amount, 2);
                }
                else
                {
                    IncomeEntry i = _repo.IncomeEntries.Where(x => x.ID == model.Income.ID).FirstOrDefault();
                    s.Amount = Math.Round(s.Amount - i.Amount + model.Income.Amount, 2);
                }

                _repo.Save(model.Income);
                _accountRepo.Save(s);
                TempData["message"] = $"{model.Income.Description} has been saved";
                return(RedirectToAction("MonthlyReport"));
            }
            else
            {
                if (model.Income.ID == 0)
                {
                    ViewBag.FormTitle = "Create Income";
                }
                else
                {
                    ViewBag.FormTitle = "Edit Income";
                }

                model.IncomeCategories = new SelectList(_catRepo.Categories.ToList(), "ID", "Name");
                return(View(model));
            }
        }
        public ActionResult DeleteConfirmedIncome(int id)
        {
            IncomeEntry incomeEntry = db.IncomeEntries.Find(id);

            db.IncomeEntries.Remove(incomeEntry);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult EditIncome([Bind(Include = "Id,AccountTypeID,AdoptionsDecimal,NumCatAdoptions,NumDogAdoptions,AdoptionsComment,DonationsDecimal,DonationsComment,MiscellaneousIncomeDecimal,MiscellaneousIncomeComment,EffectiveDate")] IncomeEntry incomeEntry)
 {
     if (ModelState.IsValid)
     {
         db.Entry(incomeEntry).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "AccountTypeID", "AccountTypeName", incomeEntry.AccountTypeID);
     return(View(incomeEntry));
 }
Beispiel #4
0
 public ActionResult EditIncome(IncomeEntry incomeEntry)
 {
     if (ModelState.IsValid)
     {
         db.Entry(incomeEntry).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Entries"));
     }
     ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "AccountTypeID", "AccountTypeName", incomeEntry.AccountTypeID);
     return(View(incomeEntry));
 }
Beispiel #5
0
        public ActionResult CreateIncome(IncomeEntry incomeEntry)
        {
            if (ModelState.IsValid)
            {
                db.IncomeEntries.Add(incomeEntry);
                db.SaveChanges();
                return(RedirectToAction("Entries"));
            }

            ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "AccountTypeID", "AccountTypeName", incomeEntry.AccountTypeID);
            return(View(incomeEntry));
        }
Beispiel #6
0
        public IncomeEntry Delete(int incomeId)
        {
            IncomeEntry dbEntry = context.IncomeEntries.FirstOrDefault(i => i.ID == incomeId);

            if (dbEntry != null)
            {
                context.IncomeEntries.Remove(dbEntry);
                context.SaveChanges();
            }

            return(dbEntry);
        }
        // GET: IncomeEntries/Details/5
        public ActionResult DetailsIncome(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IncomeEntry incomeEntry = db.IncomeEntries.Find(id);

            if (incomeEntry == null)
            {
                return(HttpNotFound());
            }
            return(View(incomeEntry));
        }
        public IActionResult Delete(int incomeId)
        {
            Account     s             = _accountRepo.Accounts.Where(x => x.TypeID == _accountTypeRepo.AccountTypes.Where(y => y.Name.Equals("Personal")).FirstOrDefault().ID).FirstOrDefault();
            IncomeEntry deletedIncome = _repo.Delete(incomeId);

            s.Amount = Math.Round(s.Amount - deletedIncome.Amount, 2);
            _accountRepo.Save(s);
            if (deletedIncome != null)
            {
                TempData["message"] = $"{deletedIncome.Description} was deleted";
            }

            return(RedirectToAction("MonthlyReport"));
        }
        // GET: IncomeEntries/Edit/5
        public ActionResult EditIncome(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IncomeEntry incomeEntry = db.IncomeEntries.Find(id);

            if (incomeEntry == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "AccountTypeID", "AccountTypeName", incomeEntry.AccountTypeID);
            return(View(incomeEntry));
        }
Beispiel #10
0
 public void Save(IncomeEntry i)
 {
     if (i.ID == 0)
     {
         context.IncomeEntries.Add(i);
     }
     else
     {
         IncomeEntry dbEntry = context.IncomeEntries.FirstOrDefault(x => x.ID == i.ID);
         if (dbEntry != null)
         {
             dbEntry.Description = i.Description;
             dbEntry.Amount      = i.Amount;
             dbEntry.Date        = i.Date;
             dbEntry.CategoryID  = i.CategoryID;
         }
     }
     context.SaveChanges();
 }
 public void OnEditClick(object sender, EventArgs e)
 {
     try
     {
         IncomeEntry deleteID = null;
         if (sender is MenuItem)
         {
             deleteID = (IncomeEntry)((sender as Button).CommandParameter);
         }
         else if (sender is Button)
         {
             deleteID = (IncomeEntry)((sender as Button).CommandParameter);
         }
         Navigation.PushAsync(new AddItem(null, deleteID)
         {
             Title = "Edit " + deleteID.AccountName + " Account"
         });
         focusFlag = true;
     }
     catch (Exception ex)
     {
         DependencyService.Get <IToast>().Show(ex.Message);
     }
 }