public IActionResult Post(int landlordId, [FromBody] PropertyBaseDto dto) { if (dto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _provider.AddProperty(landlordId, dto); return(result == null?StatusCode(500, "A problem occurred while handling your request.") : CreatedAtRoute("GetProperty", new { landlordId = result.LandlordId, id = result.PropertyId }, result)); }
public PropertyDto AddProperty(int landlordId, PropertyBaseDto property) { try { var itemToCreate = _mapper.Map <Domain.Entities.Property>(property); itemToCreate.LandlordId = landlordId; _rep.Add(itemToCreate); _rep.Save(); var createdDto = _mapper.Map <PropertyDto>(itemToCreate); return(createdDto); } catch (Exception e) { //Logger.ErrorException(e.Message, e); throw e; } }