示例#1
0
        public async Task <TodoListDto> CreateTodoAsync(TodoListDto todo)
        {
            var todoToCreate = _mapper.Map <Todo>(todo);

            todoToCreate.OwnerId = _userResolver.CurrentUserId;

            await _context.AddAsync(todoToCreate);

            await _context.SaveChangesAsync();

            return(_mapper.Map <TodoListDto>(todoToCreate));
        }
示例#2
0
        public async Task <TodoListDto> UpdateTodoAsync(TodoListDto updatedTodo)
        {
            var originalTodo = await _context.Todos.FindAsync(updatedTodo.Id);

            if (originalTodo == null)
            {
                return(null);
            }
            if (originalTodo.Owner.Id != _userResolver.CurrentUserId)
            {
                return(null);
            }

            originalTodo.Title       = updatedTodo.Title;
            originalTodo.Done        = updatedTodo.Completed;
            originalTodo.DateExpired = updatedTodo.DateExpired;

            await _context.SaveChangesAsync();

            return(_mapper.Map <TodoListDto>(originalTodo));
        }