示例#1
0
        public bool Update(Borrower input)
        {
            // Check validation
            if (input.FirstName == "")
            {
                throw new ArgumentNullException("First Name needs a value");
            }
            else if (input.LastName == "")
            {
                throw new ArgumentNullException("Last Name needs a value");
            }
            else if (!Helper.EmailIsValid(input.Login))
            {
                throw new ArgumentOutOfRangeException("Email not valid");
            }
            else if (input.Password == "")
            {
                throw new ArgumentNullException("Password needs a value");
            }

            try
            {
                _borrowerRepository.Update(input);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public JsonResult Edit(int id, FormCollection collection)
        {
            var b = borrowerRepository.GetByID(id);

            if (TryUpdateModel(b))
            {
                borrowerRepository.Update(b);
                if (borrowerRepository.Commit())
                {
                    return(Json(b));
                }
            }
            return(Json(b));
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            Borrower b = borrowerRepository.GetByID(id);

            if (TryUpdateModel(b))
            {
                borrowerRepository.Update(b);
                if (borrowerRepository.Commit())
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError("db", borrowerRepository.Errors);
            }
            return(RedirectToAction("Edit", b));
        }