Exemplo n.º 1
0
        public bool UpdatePaymentReceived(PaymentReceivedEdit model)
        {
            using (var context = new ApplicationDbContext())
            {
                var paymentReceivedEntity = context.PaymentsReceived.Single(e => e.Id == model.Id && e.UserId == _userId);

                paymentReceivedEntity.Id       = model.Id;
                paymentReceivedEntity.SourceId = context.Sources.SingleOrDefault(c => c.Name == model.SourceName && c.UserId == _userId).Id;
                paymentReceivedEntity.MonthId  = context.Months.SingleOrDefault(m =>
                                                                                m.BeginDate.Month == model.PaymentDate.Month &&
                                                                                m.BeginDate.Year == model.PaymentDate.Year &&
                                                                                m.UserId == _userId)
                                                 .Id;
                paymentReceivedEntity.Amount      = model.Amount;
                paymentReceivedEntity.PaymentDate = model.PaymentDate;

                return(context.SaveChanges() == 1);
            }
        }
Exemplo n.º 2
0
        // GET: PaymentReceived/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreatePaymentReceivedService();
            var paymentReceivedDetail = service.GetPaymentReceivedById(id);
            var sourceService         = CreateSourceService();
            var sourceNames           = sourceService.GetSourceNames();
            var monthService          = CreateMonthService();
            var monthId = monthService.GetMonthId(paymentReceivedDetail.PaymentDate);
            var model   = new PaymentReceivedEdit
            {
                Id                = paymentReceivedDetail.Id,
                MonthId           = paymentReceivedDetail.MonthId,
                SourceName        = paymentReceivedDetail.SourceName,
                Amount            = paymentReceivedDetail.Amount,
                PaymentDate       = paymentReceivedDetail.PaymentDate,
                SourceEntityNames = sourceNames
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, PaymentReceivedEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreatePaymentReceivedService();

            if (service.UpdatePaymentReceived(model))
            {
                TempData["SaveResult"] = "Your payment was updated.";
                return(RedirectToAction("Transactions", "Month", new { id = model.MonthId }));
            }

            ModelState.AddModelError("", "Your payment could not be updated.");
            return(View(model));
        }