public async Task <IDictionary <Id, Tuple <Todo, Id> > > Handle(AddTodosCommand command, CancellationToken cancellationToken) { var addedTodos = new List <TodoEntity>(); foreach (var todo in command.Todos) { var entity = new TodoEntity(); var model = todo.Item1.ToModel(); entity.FromModel(model, todo.Item2); entity.AssignedUserId = todo.Item2; _unitOfWork.Add(entity); addedTodos.Add(entity); } await _unitOfWork.SaveChangesAsync(); return(addedTodos .ToDictionary(x => (Id)x.Id, x => Tuple.Create(x.ToModel(), (Id)x.AssignedUserId))); }
public async Task <IDictionary <Id, Tuple <Todo, Id> > > Handle(UpdateTodosCommand command, CancellationToken cancellationToken) { var entities = new List <TodoEntity>(); foreach (var todo in command.Updates) { var oldTodo = command.OldTodos[todo.Key]; var todoEntity = new TodoEntity { Id = todo.Key }; todoEntity.FromModel(oldTodo.Item1, oldTodo.Item2); var model = todo.Value.Item1.ToModel(oldTodo.Item1); todoEntity = _unitOfWork.Update <TodoEntity>(todoEntity, e => e.FromModel(model, todo.Value.Item2)); entities.Add(todoEntity); } await _unitOfWork.SaveChangesAsync(); return(entities .ToDictionary(x => (Id)x.Id, x => Tuple.Create(x.ToModel(), (Id)x.AssignedUserId))); }