public async Task <IActionResult> CreateProperty([FromBody] SaveEditPropertyResource resource) { if (await _propertyService.CheckIfPropertyTitleExists(resource.Title)) { return(BadRequest(_response.Error("Property with same title already exists"))); } var property = _mapper.Map <Property>(resource); property = await _propertyService.CreateProperty(property, User.GetUserId()); var propertyResource = _mapper.Map <PropertyResource>(property); return(Ok(_response.Ok(propertyResource))); }
public async Task <IActionResult> UpdateProperty(int propertyId, [FromBody] SaveEditPropertyResource resource) { var propertyToUpdate = await _propertyService.GetPropertById(propertyId); if (propertyToUpdate.OwnerId != User.GetUserId()) { return(BadRequest(_response.Error("You can't performed this action"))); } var property = _mapper.Map <Property>(resource); propertyToUpdate = await _propertyService.UpdateProperty(propertyToUpdate, property); var propertyResource = _mapper.Map <PropertyResource>(propertyToUpdate); return(Ok(_response.Ok(propertyResource))); }