コード例 #1
0
        /// <summary>
        /// Creates a new cigar.
        /// </summary>
        public static Cigar New()
        {
            CigarState state = new CigarState()
            {
                Id = Guid.NewGuid()
            };

            return(new Cigar(state));
        }
コード例 #2
0
        public void ShouldBindStateToProperties()
        {
            CigarState state = new CigarState()
            {
                Id = Guid.NewGuid()
            };

            Cigar cigar = Cigar.Load(state);

            Assert.Equal(state.Id, cigar.Id);
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task <Cigar> Load(Guid id)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("@Id", id, DbType.Guid, ParameterDirection.Input);

            EntityState entityState = await _client.ExecuteInManagedConnectionAsync(connection =>
                                                                                    connection.QuerySingleOrDefaultAsync <EntityState>(
                                                                                        "[Catalog].[Cigars_GetSingle]",
                                                                                        parameters,
                                                                                        commandType: CommandType.StoredProcedure)
                                                                                    );

            if (entityState == null)
            {
                return(null);
            }

            CigarState cigarState
                = _serializer.Deserialize <CigarState>(entityState.SerializedContent);

            return(Cigar.Load(cigarState));
        }
コード例 #4
0
 /// <summary>
 /// Loads a previously saved cigar.
 /// </summary>
 /// <param name="state">
 /// Required state of the cigar to load.
 /// </param>
 public static Cigar Load(CigarState state)
 {
     return(new Cigar(state));
 }
コード例 #5
0
 /// <summary>
 /// Creates a new instance of the <see cref="Cigar"/> class.
 /// </summary>
 /// <param name="state">
 /// Required cigar state.
 /// </param>
 private Cigar(CigarState state)
 {
     _state = state
              ?? throw new ArgumentNullException(nameof(state));
 }