コード例 #1
0
        // PUT: api/Borrowers/5
        /// <summary>
        /// Edycja informacji wypożyczającego o podanym ID
        /// </summary>
        public async Task <IHttpActionResult> PutBorrower(int id, Borrower inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest(message: "empty model"));
            }

            if (id != inputModel.ID)
            {
                return(BadRequest());
            }

            var borrower = await _borrowerRepository.GetByIdAsync(id);

            if (borrower == null)
            {
                return(NotFound());
            }

            borrower.FirstName = inputModel.FirstName;
            borrower.LastName  = inputModel.LastName;

            var result = await _borrowerRepository.SaveAsync(borrower);

            if (!result)
            {
                return(InternalServerError());
            }
            return(Ok());
        }
コード例 #2
0
        public async Task <ActionResult> Create(Borrower borrower)
        {
            if (ModelState.IsValid)
            {
                await _borrowerRepository.SaveAsync(borrower);

                return(RedirectToAction("Index"));
            }

            return(View(borrower));
        }