Example #1
0
        /// <summary>
        /// Get Location by Id asynchronously.
        /// </summary>
        /// <param name="id">Identifier of the location to be retrieved.</param>
        /// <returns>
        /// The location.
        /// </returns>
        public async Task <ILocation> GetLocationByIdAsync(Guid id)
        {
            log4net.GlobalContext.Properties["AppName"] = Assembly.GetExecutingAssembly().FullName;
            try
            {
                LocationEntity location = new LocationEntity();
                using (var connection = Connection.CreateConnection())
                    using (NpgsqlCommand command = new NpgsqlCommand(LocationQueryHelper.GetSelectLocationByIdQueryString(), connection))
                    {
                        command.Parameters.AddWithValue(QueryConstants.ParId, NpgsqlDbType.Uuid, id);
                        await connection.OpenAsync();

                        DbDataReader dr = await command.ExecuteReaderAsync();

                        if (dr.Read())
                        {
                            location = new LocationEntity()
                            {
                                Id        = new Guid(dr[0].ToString()),
                                Address   = dr[1].ToString(),
                                Rating    = Convert.ToDouble(dr[2]),
                                RateCount = Convert.ToInt32(dr[3])
                            };
                        }
                    }
                return(Mapper.Map <ILocation>(location));
            }
            catch (Exception ex)
            {
                _log.Error(ex.StackTrace, ex);
                throw new Exception(ex.StackTrace);
            }
        }