Example #1
0
        public async Task <ActionResult> PutProduct(int productID, [FromBody] ProductsForUpdate product)
        {
            _orm.OpenConn();


            var productFromDB = await _orm.GetProductById(productID);

            if (productFromDB == 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(product, productFromDB);

            if (await _orm.UpdateProduct(productFromDB) == 0)
            {
                return(BadRequest());
            }

            await _orm.CloseConn();

            return(NoContent());
        }