Пример #1
0
        public async Task <ActionResult> PutOrder(int customerID, int orderID, [FromBody] OrdersForUpdate order)
        {
            _orm.OpenConn();
            if (!await _orm.CustomerExist(customerID))
            {
                return(NotFound());
            }

            var orderFromDB = await _orm.GetOrderById(orderID);

            if (orderFromDB == null)
            {
                return(NotFound());
            }
            //Map from entity (Source) to nidek (Destination)
            //Apply Updated fields values to that dto
            //Map from model (Source) to entity (Destination)
            //aka. copying values from source to destination
            _mapper.Map(order, orderFromDB);

            if (await _orm.UpdateOrder(orderFromDB) == 0)
            {
                return(BadRequest());
            }

            await _orm.CloseConn();

            return(NoContent());
        }