public async Task <IActionResult> CreateRealEstate([FromBody] SaveRealEstateResource realEstateResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var realEstate = mapper.Map <SaveRealEstateResource, RealEstate>(realEstateResource); repository.Add(realEstate); await unitOfWork.CompleteAsync(); var result = mapper.Map <RealEstate, RealEstateResource>(realEstate); return(Ok(result)); }
public async Task <IActionResult> CreateHouse(int userId, [FromBody] HouseForCreationDto houseDto) { // var cred = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); // if(userId != cred) // return Unauthorized(); var house = _mapper.Map <House>(houseDto); house.City = house.City.ToLower(); house.State = house.State.ToLower(); _repo.Add(house); if (await _repo.SaveAll()) { var houseToReturn = _mapper.Map <HouseForDetailedDto>(house); return(CreatedAtRoute("GetHouse", new { id = house.Id }, houseToReturn)); } return(BadRequest("Error during house creation")); }