예제 #1
0
 /// <summary>
 /// Adds the provided expense record to the database.
 /// </summary>
 /// <param name="record">The record to be added.</param>
 /// <exception cref="ArgumentNullException">Thrown if no record has been provided.</exception>
 /// <exception cref="InvalidOperationException">Thrown if the record to be added already exists in the database.</exception>
 public void Create(ExpenseRecord record)
 {
     if (record == null)
     {
         throw new ArgumentNullException(nameof(record));
     }
     lock (this.database)
     {
         if (this.FindById(record.Id) != null)
         {
             throw new InvalidOperationException($"An expense record with ID {record.Id} already exists in the database!");
         }
         this.database.Add(record);
     }
 }
예제 #2
0
        /// <summary>
        /// Updates the provided expense record in the database.
        /// </summary>
        /// <param name="record">The record to be added.</param>
        /// <exception cref="ArgumentNullException">Thrown if no record has been provided.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the record to be modified does not exist in the database.</exception>
        public void Update(ExpenseRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            lock (this.database)
            {
                var oldRecord = this.FindById(record.Id);
                if (oldRecord == null)
                {
                    throw new InvalidOperationException($"An expense record with ID {record.Id} does not exist in the database!");
                }

                oldRecord.Amount = record.Amount;
                oldRecord.Date   = record.Date;
                oldRecord.Name   = record.Name;
                oldRecord.Reason = record.Reason;
                oldRecord.Text   = record.Text;
            }
        }
예제 #3
0
 /// <summary>
 /// Adds the provided expense record to the database.
 /// </summary>
 /// <param name="record">The record to be added.</param>
 /// <exception cref="ArgumentNullException">Thrown if no record has been provided.</exception>
 /// <exception cref="InvalidOperationException">Thrown if the record to be added already exists in the database.</exception>
 public void Create(ExpenseRecord record)
 {
     // Exercise 5
     // TODO
 }
예제 #4
0
 public void Update(ExpenseRecord record)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Updates the provided expense record in the database.
 /// </summary>
 /// <param name="record">The record to be added.</param>
 /// <exception cref="ArgumentNullException">Thrown if no record has been provided.</exception>
 /// <exception cref="InvalidOperationException">Thrown if the record to be modified does not exist in the database.</exception>
 public void Update(ExpenseRecord record)
 {
     // Exercise 4
     // TODO
 }