示例#1
0
        public async Task <IActionResult> Post([FromBody] PostProperty property)
        {
            var id = await repository.Insert(property);

            if (id == 0)
            {
                return(BadRequest("post request failed"));
            }

            return(Ok(id));
        }
示例#2
0
        public async Task <int> Insert(PostProperty property)
        {
            try
            {
                using (IDbConnection dbConnection = db)
                {
                    string insertQuery = "INSERT INTO dbo.Properties (Housenumber, Street, Town, PostCode, AvailableFrom,  Status, LandlordId)" +
                                         "VALUES(@Housenumber, @Street, @Town, @PostCode, @AvailableFrom, @Status, @LandlordId);" +
                                         "SELECT CAST(SCOPE_IDENTITY() AS int)";

                    dbConnection.Open();
                    var idCollection = await dbConnection.QueryAsync <int>(insertQuery, property);

                    return(idCollection.FirstOrDefault());
                }
            }
            catch
            {
                return(0);
            }
        }