Example #1
0
        // Gets VIEW to edit single Paychecks
        public ActionResult Edit(int ID)
        {
            var service = CreatePaychecksService();
            var detail  = service.GetPaychecksByID(ID);
            var model   =
                new PaychecksEdit
            {
                PaychecksID = detail.PaychecksID,
                Name        = detail.Name,
                AmountPaid  = detail.AmountPaid,
            };

            return(View(model));
        }
        public bool UpdatePaychecks(PaychecksEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Paychecks
                    .Single(e => e.PaychecksID == model.PaychecksID && e.OwnerID == _userID);

                entity.Name       = model.Name;
                entity.AmountPaid = model.AmountPaid;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #3
0
        public ActionResult Edit(int ID, PaychecksEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreatePaychecksService();

            if (service.UpdatePaychecks(model))
            {
                TempData["SaveResult"] = "Your Paychecks were updated.";
                return(RedirectToAction("Index"));
            }

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