예제 #1
0
        public ShipMethodDto GetSimple(int id)
        {
            ShipMethod shipMethodEf = this.dbContext.ShipMethods.Find(id);

            if (shipMethodEf == null)
            {
                throw new ArgumentException("Not found id");
            }

            ShipMethodDto shipMethodDto = TinyMapper.Map <ShipMethodDto>(shipMethodEf);

            return(shipMethodDto);
        }
예제 #2
0
        public ShipMethodDto GetSimple(int id)
        {
            string sql = @"SELECT TOP 1 [ShipMethodID]
      ,[Name]
      ,[ShipBase]
      ,[ShipRate]
      ,[rowguid]
      ,[ModifiedDate]
  FROM [AdventureWorks2014].[Purchasing].[ShipMethod]
  WHERE [ShipMethodID] = @id";

            using (SqlConnection connection = new SqlConnection(this.connectionString))
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = sql;
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Parameters.AddWithValue("@id", id);

                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                }

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ShipMethodDto personInfo = new ShipMethodDto();
                        personInfo.ShipMethodID = Convert.ToInt32(reader["ShipMethodID"]);
                        personInfo.ModifiedDate = this.MapToDateTime2(reader, "ModifiedDate");
                        personInfo.Name         = this.MapToString(reader, "Name");
                        personInfo.ShipBase     = Convert.ToDecimal(reader["ShipBase"]);
                        personInfo.ShipRate     = Convert.ToDecimal(reader["ShipRate"]);
                        personInfo.rowguid      = (Guid)reader["rowguid"];

                        return(personInfo);
                    }
                }
            }

            throw new ArgumentException("Not found id");
        }
예제 #3
0
        public ShipMethodDto GetSimple(int id)
        {
            string sql = @"SELECT TOP 1 [ShipMethodID]
      ,[Name]
      ,[ShipBase]
      ,[ShipRate]
      ,[rowguid]
      ,[ModifiedDate]
  FROM [AdventureWorks2014].[Purchasing].[ShipMethod]
  WHERE [ShipMethodID] = @Id";

            ShipMethodDto dto = this.connection.Query <ShipMethodDto>(sql, new { Id = id }).FirstOrDefault();

            if (dto == null)
            {
                throw new ArgumentException("Not found id");
            }

            return(dto);
        }
        public ShipMethodDto GetSimple(int id)
        {
            ShipMethod shipMethodEf = this.dbContext.ShipMethods.Find(id);

            if (shipMethodEf == null)
            {
                throw new ArgumentException("Not found id");
            }

            ShipMethodDto shipMethodDto = new ShipMethodDto();

            shipMethodDto.ModifiedDate = shipMethodEf.ModifiedDate;
            shipMethodDto.Name         = shipMethodEf.Name;
            shipMethodDto.rowguid      = shipMethodEf.rowguid;
            shipMethodDto.ShipBase     = shipMethodEf.ShipBase;
            shipMethodDto.ShipMethodID = shipMethodEf.ShipMethodID;
            shipMethodDto.ShipRate     = shipMethodEf.ShipRate;

            return(shipMethodDto);
        }
        private void MapperConfigure(MapperInstance cfd)
        {
            cfd.AddMap <Person, PersonInfoDto>(src =>
            {
                PersonInfoDto dst = new PersonInfoDto();
                dst.InjectFrom(src);
                dst.EmployeeBrithDate = src.Employee?.BirthDate;

                return(dst);
            });

            cfd.AddMap <EmailAddress, EmailDto>(src =>
            {
                EmailDto dst = new EmailDto();
                dst.InjectFrom(src);
                dst.EmailAddress = src.EmailAddress1;

                return(dst);
            });

            cfd.AddMap <ShipMethod, ShipMethodDto>(src =>
            {
                ShipMethodDto dst = new ShipMethodDto();
                dst.InjectFrom(src);
                return(dst);
            });

            cfd.AddMap <ProductListPriceHistory, ProductListPriceHistoryDto>(src =>
            {
                ProductListPriceHistoryDto dst = new ProductListPriceHistoryDto();
                dst.InjectFrom(src);
                return(dst);
            });

            cfd.AddMap <Product, ProductDto>(src =>
            {
                ProductDto dst = new ProductDto();
                dst.InjectFrom(src);
                dst.ProductListPriceHistories = new List <ProductListPriceHistoryDto>();
                foreach (ProductListPriceHistory item in src.ProductListPriceHistories)
                {
                    ProductListPriceHistoryDto itemDto = new ProductListPriceHistoryDto();
                    itemDto.InjectFrom(item);

                    dst.ProductListPriceHistories.Add(itemDto);
                }

                return(dst);
            });

            cfd.AddMap <ProductModel, ProductModelDto>(src =>
            {
                ProductModelDto dst = new ProductModelDto();
                dst.InjectFrom(src);
                return(dst);
            });

            cfd.AddMap <Product, Product2Dto>(src =>
            {
                Product2Dto dst = new Product2Dto();
                dst.InjectFrom(src);
                dst.ProductModel = new ProductModelDto();
                dst.ProductModel.InjectFrom(src.ProductModel);
                dst.ProductModelID = src.ProductModel?.ProductModelID;

                return(dst);
            });
        }