예제 #1
0
        public async Task <Unit> Handle(SetTaskDoneCommand request, CancellationToken cancellationToken)
        {
            // first find if any tasks exists with the id
            var task = await _context.Set <LTask>()
                       .FindAsync(request.Id);

            if (task == null)
            {
                throw new NotFoundException("Task", request.Id);
            }

            task.IsDone = true;
            _context.Set <LTask>().Update(task);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
예제 #2
0
 public async Task <TaskListViewModel> Handle(GetAllTasksQuery request, CancellationToken cancellationToken)
 {
     return(new TaskListViewModel
     {
         Tasks = await _context.Set <LTask>()
                 .ProjectTo <TaskLookupModel>(_mapper.ConfigurationProvider)
                 .ToListAsync(cancellationToken)
     });
 }
예제 #3
0
 public async Task <UserListViewModel> Handle(GetUserssListQuery request, CancellationToken cancellationToken)
 {
     return(new UserListViewModel
     {
         Users = await _context
                 .Set <AppUser>()
                 .Where(u => !u.IsAdmin)
                 .ProjectTo <UserLookupModel>(_mapper.ConfigurationProvider)
                 .ToListAsync(cancellationToken)
     });
 }
예제 #4
0
        public async Task <Unit> Handle(CreateTaskCommand request, CancellationToken cancellationToken)
        {
            var task = new LTask
            {
                TaskName        = request.Name,
                TaskDescription = request.Description,
                IsDone          = false
            };

            await _context.Set <LTask>().AddAsync(task, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }