示例#1
0
        public async Task <bool> UpdateBorrower(BorrowerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = await
                             ctx
                             .Borrowers
                             .SingleAsync(b => b.Id == model.Id && b.OwnerId == _userId);

                entity.FirstName    = model.FirstName;
                entity.LastName     = model.LastName;
                entity.PhoneNumber  = model.PhoneNumber;
                entity.EmailAddress = model.EmailAddress;

                return(await ctx.SaveChangesAsync() == 1);
            }
        }
示例#2
0
        // GET: Edit
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            var borrowerService = CreateBorrowerService();
            var detail          = await borrowerService.GetBorrowerById((int)id);

            var model =
                new BorrowerEdit
            {
                Id           = detail.Id,
                FirstName    = detail.FirstName,
                LastName     = detail.LastName,
                PhoneNumber  = detail.PhoneNumber,
                EmailAddress = detail.EmailAddress
            };

            return(View(model));
        }
示例#3
0
        public async Task <ActionResult> Edit(int id, BorrowerEdit model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

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

            var borrowerService = CreateBorrowerService();

            if (await borrowerService.UpdateBorrower(model))
            {
                TempData["SaveResult"] = "Your borrower was updated.";
                return(RedirectToAction("Index"));
            }

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