-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
131 lines (109 loc) · 3.52 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using FluentDynamoDb.Configuration;
using FluentDynamoDb.Converters;
using FluentDynamoDb.Mappers;
namespace FluentDynamoDb.Example
{
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime BirthDate { get; set; }
public Gender Gender { get; set; }
public Contact Contact { get; set; }
private readonly IList<Account> _accounts = new List<Account>();
public IEnumerable<Account> Accounts { get { return _accounts; } }
public void AddAccount(Account account)
{
_accounts.Add(account);
}
}
public class Account
{
public string Username { get; set; }
public string Password { get; set; }
public decimal Balance { get; set; }
}
public class Contact
{
public string Email { get; set; }
public int PhoneNumber { get; set; }
}
public class UserMap : ClassMap<User>
{
public UserMap()
{
TableName("Users");
Map(u => u.Id);
Map(u => u.Name);
Map(u => u.BirthDate);
Map(u => u.Gender).With(new DynamoDbConverterEnum<Gender>());
References(u => u.Contact);
HasMany(u => u.Accounts).With(AccessStrategy.CamelCaseUnderscoreName);
}
}
public class ContactMap : ClassMap<Contact>
{
public ContactMap()
{
Map(c => c.Email);
Map(c => c.PhoneNumber);
}
}
public class AccountMap : ClassMap<Account>
{
public AccountMap()
{
Map(c => c.Username);
Map(c => c.Password);
Map(c => c.Balance);
}
}
public enum Gender
{
Male = 1,
Female = 2
}
public class Program
{
public static void Main(string[] args)
{
/*
* You must set your DynamoDb configuration @ app.config
*
* <appSettings>
<add key="AWSProfileName" value="" />
<add key="AWSRegion" value="us-east-1" />
<add key="AWSAccessKey" value=""/>
<add key="AWSSecretKey" value=""/>
</appSettings>
*
*/
FluentDynamoDbConfiguration.Configure(Assembly.GetExecutingAssembly());
var userStore = new DynamoDbStore<User, Guid>();
var user = new User
{
Id = new Guid("1a9f6ee7-d0bf-47ab-a6f6-6225ebe713d8"),
Name = "Luiz Freneda",
BirthDate = new DateTime(1988, 05, 15),
Gender = Gender.Male,
Contact = new Contact
{
Email = "[email protected]",
PhoneNumber = 963427000
}
};
user.AddAccount(new Account { Balance = 9999.99m, Password = "password", Username = "lfreneda" });
user.AddAccount(new Account { Balance = 123.45m, Password = "password", Username = "lfrened4" });
userStore.PutItem(user);
var savedUser = userStore.GetItem(new Guid("1a9f6ee7-d0bf-47ab-a6f6-6225ebe713d8"));
savedUser.Name = "Luiz Freneda Perez Junior";
userStore.UpdateItem(savedUser);
userStore.DeleteItem(new Guid("1a9f6ee7-d0bf-47ab-a6f6-6225ebe713d8"));
Console.Read();
}
}
}