예제 #1
0
        public async Task <ActionResult> PutCustomer(int id, [FromBody] CustomersForUpdate customer)
        {
            _orm.OpenConn();
            if (!await _orm.CustomerExist(id))
            {
                return(NotFound());
            }

            var customerFromDB = await _orm.GetCustomerById(id);

            //Map from customerFromDB (Source) to customer (Destination)
            //Apply Updated fields values to that dto
            //Map from customer (Source) to customerFromDB (Destination)
            //aka. copying values from source to destination
            _mapper.Map(customer, customerFromDB);

            if (await _orm.UpdateCustomer(customerFromDB) == 0)
            {
                return(BadRequest());
            }

            await _orm.CloseConn();

            return(NoContent());
        }