public void Update(TODOItemModel e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var stored = toDoItems.FirstOrDefault(x => x.Id == e.Id); if (stored == null) { throw new KeyNotFoundException($"An object of a type '{nameof(TODOItemModel)}' with the key '{e.Id}' not found"); } toDoItems.RemoveAll(x => x.Id == stored.Id); toDoItems.Add(Mapper.Map <TODOItemModel>(e)); }
public void Create(TODOItemModel e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (toDoItems.Any(x => x.Id == e.Id)) { throw new DuplicateKeyException($"Can't create an object of a type {nameof(TODOItemModel)} with the key '{e.Id}'. The object with the same key is already exists"); } if (string.IsNullOrWhiteSpace(e.Id)) { e.Id = Guid.NewGuid().ToString(); } toDoItems.Add(Mapper.Map <TODOItemModel>(e)); }