public async Task <Property> CreatePropertyAsync(Property property) { var entity = PropertyEntity.MapFrom(property); _dbContext.Properties.Add(entity); await _dbContext.SaveChangesAsync(); return(PropertyEntity.MapTo(entity)); }
public async Task <Property> SavePropertyAsync(Property property) { var entity = PropertyEntity.MapFrom(property); if (_dbContext.Properties.Any(p => p.Id == property.Id)) { _dbContext.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } else { throw new BadRequestException("The property to update is not exist"); } await _dbContext.SaveChangesAsync(); return(PropertyEntity.MapTo(entity)); }