Example #1
0
        public async Task <CommandResult <int> > Handle(AddWorkerCommand command)
        {
            var entry = _db.Workers.Add(new Worker
            {
                Name = command.Name
            });
            await _db.SaveChangesAsync();

            return(CommandResult <int> .Success(entry.Entity.Id));
        }
        public async Task <CommandResult> Handle(AddShiftCommand command)
        {
            var worker = await _db.Workers.Include(w => w.Shifts)
                         .FirstOrDefaultAsync(w => w.Id == command.WorkerId);

            var result = worker.AddShift(command.StartDate, command.EndDate);

            if (result.IsFailure)
            {
                return(result);
            }

            await _db.SaveChangesAsync();

            return(CommandResult.Success());
        }