Пример #1
0
 /// <summary>
 ///     Update a greeting
 /// </summary>
 public void Update(Greeting greeting)
 {
     var existing = Get(greeting.Id);
     if (existing == null)
     {
         throw new InvalidOperationException("Existing greeting not found.");
     }
     existing.Message = greeting.Message;
 }
Пример #2
0
 /// <summary>
 ///     Sets some default data. This would normally be stored in a database.
 /// </summary>
 private void SetDefaultData()
 {
     if (_greetings == null)
     {
         var greeting = new Greeting
         {
             Id = 1,
             Message = "Hello world"
         };
         _greetings = new List<Greeting> {greeting};
     }
 }
Пример #3
0
 /// <summary>
 ///     Add a greeting.
 /// </summary>
 public void Add(Greeting greeting)
 {
     // fake an auto-incrementing database identity
     greeting.Id = _greetings.Max(x => x.Id) + 1;
     _greetings.Add(greeting);
 }