public async Task <IActionResult> Add(PetForAddDto petForAddDto) { if (await _repo.PetExists(petForAddDto)) { return(BadRequest("Pet already registered")); } petForAddDto.UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var petToCreate = _mapper.Map <Pet>(petForAddDto); var createdPet = await _repo.AddPet(petToCreate); return(StatusCode(201)); }
public async Task <bool> PetExists(PetForAddDto petForAddDto) { var pets = await _context.Pets.ToListAsync(); foreach (var pet in pets) //ugly as hell { if ( pet.City == petForAddDto.City & pet.Color == petForAddDto.Color & pet.Country == petForAddDto.Country & pet.Size == petForAddDto.Size & pet.Street == petForAddDto.Street ) { return(true); } } return(false); }