Esempio n. 1
0
        public async Task <TaskInfo> Handle(
            AddTaskToNotepadCommand command,
            CancellationToken cancellationToken)
        {
            // Find notepad by specified Id
            var notepad = _db.Notepads
                          .FirstOrDefault(x => x.Id == command.NotepadId);

            if (notepad == null)
            {
                throw new Exception($"Cannot find Notepad with Id '{command.NotepadId}'");
            }

            // Create new task
            var task = new DataStore.Models.Task()
            {
                Title = command.TaskTitle
            };

            notepad.Tasks.Add(task);

            // Save all the changes
            var model = await _db.Tasks.AddAsync(task);

            await _db.SaveChangesAsync();

            return(new TaskInfo()
            {
                Id = model.Entity.Id,
                Title = model.Entity.Title
            });
        }
Esempio n. 2
0
        public async Task <NotepadInfo> Handle(
            CreateNotepadCommand command,
            CancellationToken cancellationToken)
        {
            var notepad = new Notepad
            {
                Title = command.Title
            };

            var result = _db.Notepads.Add(notepad);
            await _db.SaveChangesAsync();

            return(new NotepadInfo()
            {
                Id = result.Entity.Id,
                Title = result.Entity.Title
            });
        }