/// <summary>
        ///  Handles the <see cref="Views.IncomeEdit"/> form being opened from the <see cref="Views.IncomeView"/> form
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Event arguments</param>
        public static void EditButtonClicked(object sender, EventArgs e)
        {
            if (IncomeEdit == null)
            {
                IncomeEdit             = new IncomeEdit();
                IncomeEdit.FormClosed += IncomeEditViewOnFormClosed;
            }

            var selectedListItems = IncomeView.IncomeListView.SelectedItems;

            if (selectedListItems.Count > 0)
            {
                var selectedItem = selectedListItems[0];
                var incomeId     = Guid.Parse(selectedItem.SubItems[0].Text);
                var income       = ListAccessHelper.FindIncome(incomeId);

                EditIncome = income;
            }
            else
            {
                EditIncome = null;
            }

            IncomeEdit.Show(IncomeView);
            IncomeView.Hide();
        }
        /// <summary>
        ///  Handles the save and back button being pressed on the <see cref="Views.IncomeEdit"/> form
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Event arguments</param>
        public static void EditSaveAndBack(object sender, EventArgs e)
        {
            var success = SaveEditIncome();

            if (success)
            {
                IncomeEdit.Owner.Show();
                IncomeEdit.Close();
            }
        }
示例#3
0
        public bool UpdateIncome(IncomeEdit model)
        {
            if (model.LastPayDate == null)
            {
                model.LastPayDate = new DateTime(2035, 12, 31);
            }
            if (model.PayFreqType == PayFreqType.Once)
            {
                model.LastPayDate = model.InitialPayDate;
            }

            var sourceService = CreateSourceService();

            if (!sourceService.UpdateSource(model))
            {
                return(false);
            }

            using (var context = new ApplicationDbContext())
            {
                var incomeEntity = context.Incomes.Single(i => i.Id == model.Id && i.UserId == _userId);

                if (incomeEntity.Amount == model.Amount &&
                    incomeEntity.PayFreqType == model.PayFreqType &&
                    incomeEntity.FrequencyFactor == model.FrequencyFactor &&
                    incomeEntity.InitialPayDate == model.InitialPayDate &&
                    incomeEntity.LastPayDate == model.LastPayDate)
                {
                    return(true);
                }

                incomeEntity.Amount          = model.Amount;
                incomeEntity.PayFreqType     = model.PayFreqType;
                incomeEntity.FrequencyFactor = model.FrequencyFactor;
                incomeEntity.InitialPayDate  = model.InitialPayDate;
                incomeEntity.LastPayDate     = model.LastPayDate;

                if (!(context.SaveChanges() == 1))
                {
                    return(false);
                }
            }

            var payDayService = CreatePayDayService();

            if (!payDayService.UpdatePayDays(model))
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        public bool UpdateIncome(IncomeEdit model) // updates existing income
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Incomes
                             .Single(e => e.IncomeID == model.IncomeID && e.AccountID == _userID);

                entity.IncomeID     = model.IncomeID;
                entity.IncomeAmount = model.IncomeAmount;
                entity.IncomeDate   = model.IncomeDate;

                return(ctx.SaveChanges() == 1);
            }
        }
示例#5
0
        public bool UpdatePayDays(IncomeEdit model)
        {
            if (!DeletePayDays(model.Id))
            {
                return(false);
            }

            var payDates = new List <DateTime>();

            if (model.PayFreqType == PayFreqType.ByMonth)
            {
                for (var date = model.InitialPayDate;
                     (DateTime.Compare(date, model.LastPayDate)) <= 0;
                     date = date.AddMonths(1 * model.FrequencyFactor))
                {
                    payDates.Add(date);
                }
            }
            else if (model.PayFreqType == PayFreqType.ByWeek)
            {
                for (var date = model.InitialPayDate;
                     (DateTime.Compare(date, model.LastPayDate)) <= 0;
                     date = date.AddDays(7 * model.FrequencyFactor))
                {
                    payDates.Add(date);
                }
            }
            else
            {
                payDates.Add(model.InitialPayDate);
            }

            using (var context = new ApplicationDbContext())
            {
                foreach (var date in payDates)
                {
                    var payDayEntity = new PayDay()
                    {
                        IncomeId = model.Id,
                        MonthId  = (context.Months.Single(m => m.BeginDate.Month == date.Month && m.BeginDate.Year == date.Year && m.UserId == _userId)).Id,
                        Date     = date,
                        Amount   = model.Amount,
                        UserId   = _userId
                    };
                    context.PayDays.Add(payDayEntity);
                }
                return(context.SaveChanges() == payDates.Count());
            }
        }
示例#6
0
        public IHttpActionResult Put(IncomeEdit income)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateIncomeService();

            if (!service.UpdateIncome(income))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
示例#7
0
        public bool UpdateSource(IncomeEdit model)
        {
            using (var context = new ApplicationDbContext())
            {
                var sourceEntity = context.Sources.Single(s => s.Id == model.Id && s.UserId == _userId);

                if (sourceEntity.Name == model.SourceName)
                {
                    return(true);
                }

                sourceEntity.Name = model.SourceName;

                return(context.SaveChanges() == 1);
            }
        }
示例#8
0
        // GET: Income/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service      = CreateIncomeService();
            var incomeDetail = service.GetIncomeById(id);
            var model        = new IncomeEdit
            {
                Id              = incomeDetail.Id,
                SourceName      = incomeDetail.SourceName,
                Amount          = incomeDetail.Amount,
                PayFreqType     = incomeDetail.PayFreqType,
                FrequencyFactor = incomeDetail.FrequencyFactor,
                InitialPayDate  = incomeDetail.InitialPayDate,
                LastPayDate     = incomeDetail.LastPayDate
            };

            return(View(model));
        }
示例#9
0
        public ActionResult Edit(int id, IncomeEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateIncomeService();

            if (service.UpdateIncome(model))
            {
                TempData["SaveResult"] = "Your income was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your income could not be updated.");
            return(View(model));
        }
 /// <summary>
 ///  Handles the cancel button being clicked on the <see cref="Views.IncomeEdit"/>
 /// </summary>
 /// <param name="sender">The sender object</param>
 /// <param name="e">Event arguments</param>
 public static void EditCancelClicked(object sender, EventArgs e)
 {
     IncomeEdit.Owner.Show();
     IncomeEdit.Close();
 }