Ejemplo n.º 1
0
        public IHttpActionResult CreateOpenLoan(OpenLoanDto openLoanDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var openLoan = Mapper.Map <OpenLoanDto, OpenLoan>(openLoanDto);

            _context.OpenLoans.Add(openLoan);
            _context.SaveChanges();

            openLoanDto.Id = openLoan.Id;

            return(Created(new Uri(Request.RequestUri + "/" + openLoan.Id), openLoanDto));
        }
Ejemplo n.º 2
0
        public IHttpActionResult UpdateOpenLoan(int id, OpenLoanDto openLoanDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var openLoanInDb = _context.OpenLoans.SingleOrDefault(c => c.Id == id);

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

            Mapper.Map(openLoanDto, openLoanInDb);

            _context.SaveChanges();
            return(Ok());
        }