public async Task UpdateAsync(BreweryDto breweryDto)
 {
     await _client.MapAsync<BreweryDto>(d => d.Properties(p => p
         .String(s => s.Name(n => n.Name).Analyzer("autocomplete"))
         ));
     await _client.IndexAsync(breweryDto);
 }
 public async Task UpdateAsync(BreweryDto breweryDto)
 {
     var brewery = Mapper.Map<BreweryDto, Brewery>(breweryDto);
     await _breweryRepository.UpdateAsync(brewery);
     var result = await _breweryRepository.GetSingleAsync(breweryDto.Id, "Members.Member", "Origin", "Beers", "Socials", "Beers.Beer.IBU", "Beers.Beer.ABV", "Beers.Beer.SRM", "Beers.Beer.BeerStyle");
     var mappedResult = Mapper.Map<Brewery, BreweryDto>(result);
     if (brewery.Members.Any()) await _userService.ReIndexBreweryRelationElasticSearch(mappedResult);
     await _breweryElasticsearch.UpdateAsync(mappedResult);
 }
        public async Task<BreweryDto> AddAsync(BreweryDto breweryDto)
        {
            var brewery = Mapper.Map<BreweryDto, Brewery>(breweryDto);
            await _breweryRepository.AddAsync(brewery);
            var result = await _breweryRepository.GetSingleAsync(brewery.BreweryId, "Members.Member", "Origin", "Beers", "Socials", "Beers.Beer.IBU", "Beers.Beer.ABV", "Beers.Beer.SRM", "Beers.Beer.BeerStyle");
            var mappedResult = Mapper.Map<Brewery,BreweryDto>(result);
            await _breweryElasticsearch.UpdateAsync(mappedResult);
            return mappedResult;

        }
        public async Task<IHttpActionResult> PutBrewery(int id, BreweryDto breweryDto)
        {
            // Checks if login user is allowed to change brewery.
            var isAllowed = ClaimsAuthorization.CheckAccess("Post", "BreweryId", id.ToString());
            if (!isAllowed)
            {
                return StatusCode(HttpStatusCode.Unauthorized);
            }
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != breweryDto.Id)
            {
                return BadRequest();
            }
            await _breweryService.UpdateAsync(breweryDto);
            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PostBrewery(BreweryDto brewery)
        {
            if (brewery == null) return BadRequest();
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            try
            {
                var result = await _breweryService.AddAsync(brewery);
                return CreatedAtRoute("DefaultApi", new {controller = "breweries"}, result);
            }
            catch (DbEntityValidationException exception)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = exception.EntityValidationErrors
                    .SelectMany(x => x.ValidationErrors)
                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                return BadRequest(string.Concat(exception.Message, " The validation errors are: ", fullErrorMessage));
            }
            catch (DbUpdateException exception)
            {
                
                if (exception.ToString().Contains("IX_BreweryName"))
                    ModelState.AddModelError("Name", "Duplicate brewery name not allowed.");

                return BadRequest(ModelState);
            }
            
        }
 public BlobStorageMultipartStreamProvider(BreweryDto breweryDto)
 {
     _breweryDto = breweryDto;
 }
Esempio n. 7
0
 public async Task ReIndexBreweryRelationElasticSearch(BreweryDto brewerDto)
 {
     foreach (var memberDto in brewerDto.Members)
     {
         var member = memberDto;
         var result = await _userRepository.GetSingleAsync(member.Username, _userInclude);
         if (result != null)
             await _userElasticsearch.UpdateAsync(Mapper.Map<User, UserDto>(result));
     }
 }