public static Property MapPropertyDtoToEntity(PropertyDto propertyDto) { return new Property() { Id = propertyDto.Id, Name = propertyDto.Name, Price = propertyDto.Price, Description = propertyDto.Description, Sold = propertyDto.Sold, OwnerId = propertyDto.Owner.UserId, Created = propertyDto.Created, Location = Mapper.MapAddressDtoToEntity(propertyDto.Location) }; }
public async Task<IHttpActionResult> PutProperty(Guid id, PropertyDto propertyDto) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (propertyDto.Id == Guid.Empty) { propertyDto.Id = id; } await this.propertiesRepository.UpdateProperty(Mapper.MapPropertyDtoToEntity(propertyDto)); return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostProperty(PropertyDto propertyDto) { if (!ModelState.IsValid) { return BadRequest(ModelState); } propertyDto.Id = Guid.NewGuid(); propertyDto.Created = DateTime.UtcNow; await this.propertiesRepository.CreateProperty(Mapper.MapPropertyDtoToEntity(propertyDto)); return CreatedAtRoute("DefaultApi", new { id = propertyDto.Id }, propertyDto); }