示例#1
0
        public ActionResult Edit(int id, Schedule data)
        {
            if (data.Amount == 0)
            {
                ModelState.AddModelError(nameof(data.Amount), $"Amount can't be zero");
            }
            if (!ModelState.IsValid)
            {
                var accounts = new SqlDataServices <Data.Models.Accounts>().GetAll().Where(e => e.Active).OrderBy(e => e.Name).ToList();
                if (!accounts.Exists(e => e.ID == data.AccountsID))
                {
                    accounts.Add(new SqlDataServices <Data.Models.Accounts>().Get(data.AccountsID));
                }
                ViewBag.Accounts = accounts;
                ViewBag.Category = new SqlDataServices <Data.Models.Category>().GetAll().OrderBy(e => e.Type).ThenBy(e => e.Name);
                ViewBag.Payee    = new SqlDataServices <Data.Models.Payee>().GetAll().OrderBy(e => e.Name);
                return(View(data));
            }
            try
            {
                // TODO: Add update logic here
                if (new SqlDataServices <Category>().Get(data.CategoryID).Type == Data.Enums.CategoryType.Expense)
                {
                    data.Amount *= -1;
                }

                db.Edit(id, data.ReverseMapper());
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "An Error occoured yor entry coudn't be updated";
                return(View());
            }
        }
示例#2
0
        public ActionResult Edit(Payee data)
        {
            if (db.GetAll().Where(e => e.ID != data.ID).Select(e => e.Name).Contains(data.Name))
            {
                ModelState.AddModelError(nameof(data.Name), $"An entry with the Name {data.Name} exists already. Please use a diffrent Name");
            }

            if (!ModelState.IsValid)
            {
                var categorylist = new SqlDataServices <Data.Models.Category>().GetAll().OrderBy(e => e.Type).ThenBy(e => e.Name);
                ViewBag.Category = categorylist;
                return(View());
            }

            try
            {
                // TODO: Add update logic here
                db.Edit(data.ID, data.ReverseMapper());
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "An Error occoured yor entry coudn't be updated";
                return(RedirectToAction("Edit", data.ID));
            }
        }
示例#3
0
        public ActionResult Edit([Bind(Include = "ID,Name,Type,Active,IncludeTotal,OpeningBalance")] Accounts data)
        {
            if (db.GetAll().Where(e => e.ID != data.ID).Select(e => e.Name).Contains(data.Name))
            {
                ModelState.AddModelError(nameof(data.Name), $"An entry with the Name {data.Name} exists already. Please use a diffrent Name");
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                // TODO: Add update logic here
                int id = data.ID;
                db.Edit(id, data.ReverseMapper());

                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "An Error occoured yor entry coudn't be updated";
                return(View());
            }
        }
        public static void AddTransaction()
        {
            var todaysSchedule = db.GetAll("NextDueDay", DateTime.Today, "<=").Where(e => e.Frequency != Data.Enums.Frequency.PaidOff);


            foreach (var item in todaysSchedule)
            {
                var transaction = new Transactions
                {
                    AccountsID = item.AccountsID,
                    CategoryID = item.CategoryID,
                    PayeeID    = item.PayeeID,
                    ScheduleID = item.ID,
                    Amount     = item.Amount,
                    Date       = item.NextDueDay,
                };

                transactionsDb.Add(transaction);

                switch (item.Frequency)
                {
                case Data.Enums.Frequency.Monthly:
                    item.NextDueDay = item.NextDueDay.AddMonths(1);
                    break;

                case Data.Enums.Frequency.Weekly:
                    item.NextDueDay = item.NextDueDay.AddDays(7);
                    break;

                case Data.Enums.Frequency.Yearly:
                    item.NextDueDay = item.NextDueDay.AddYears(1);
                    break;

                case Data.Enums.Frequency.Quarterly:
                    item.NextDueDay = item.NextDueDay.AddMonths(3);
                    break;

                case Data.Enums.Frequency.OneTimePayment:
                    item.Frequency = Data.Enums.Frequency.PaidOff;
                    break;

                case Data.Enums.Frequency.EveryTwoWeeks:
                    item.NextDueDay = item.NextDueDay.AddDays(14);
                    break;

                case Data.Enums.Frequency.EveryFourWeeks:
                    item.NextDueDay = item.NextDueDay.AddDays(28);
                    break;

                case Data.Enums.Frequency.TwiceMonth:
                    item.NextDueDay = item.NextDueDay.AddDays(14);
                    break;

                case Data.Enums.Frequency.EveryTwoMonth:
                    item.NextDueDay = item.NextDueDay.AddMonths(2);
                    break;

                case Data.Enums.Frequency.TwiceYear:
                    item.NextDueDay = item.NextDueDay.AddMonths(6);
                    break;

                default:
                    break;
                }

                if (item.TotalAmount.HasValue)
                {
                    item.AmountCount = item.AmountCount.GetValueOrDefault() + (item.Amount < 0 ? item.Amount * -1 : item.Amount);
                }
                if (item.TotalCount.HasValue)
                {
                    item.CountCount = item.CountCount.GetValueOrDefault() + 1;
                }

                if ((item.EndsOnDate.HasValue && item.NextDueDay > item.EndsOnDate) || (item.TotalAmount.HasValue && item.AmountCount >= item.TotalAmount) || (item.TotalCount.HasValue && item.CountCount >= item.TotalCount))
                {
                    item.Frequency = Data.Enums.Frequency.PaidOff;
                }

                db.Edit(item.ID, item);
            }
        }