コード例 #1
0
        /// <summary>
        /// Updates a brewery entity from the given DTO and id.
        /// </summary>
        /// <param name="id">Entity primary ID</param>
        /// <param name="breweryDto">Brewery entity</param>
        /// <exception cref="BreweryNotFoundException"></exception>
        public void UpdateBrewery(int id, BreweryDto breweryDto)
        {
            Brewery originalBrewery = null;
            var     updatedBrewery  = _mapper.Map <Brewery>(breweryDto);

            // Set the brewery id on the updatedBrewery before passing to validation
            updatedBrewery.BreweryId = id;

            try
            {
                originalBrewery = GetBrewery(id);
            }
            catch (BrewdoggerException brewdoggerException)
            {
                Log.Error("BreweryService::UpdateBrewery - No breweries found");
            }

            if (!ValidateBreweryExists(updatedBrewery))
            {
                throw new BreweryNotFoundException("Brewery does not exist");
            }

            if (originalBrewery != null)
            {
                _breweryRepository.UpdateBrewery(originalBrewery, updatedBrewery);
                Log.Information("BreweryService::UpdateBrewery - Brewery [{0}] successfully updated", id);
            }
        }
コード例 #2
0
        public IActionResult Put(int id, Brewery brewery)
        {
            if (id != brewery.Id)
            {
                return(BadRequest());
            }

            _breweryRepository.UpdateBrewery(brewery);
            return(NoContent());
        }