예제 #1
0
        public async Task <ICommandResult> Handle(UpdateTimeSheetCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Operação inválida", command.Notifications));
            }

            var timeShettDb = await _timeSheetRepository.GetByIdAsync(command.Id);

            if (timeShettDb == null)
            {
                return(new GenericCommandResult(false, "Apontamento não encontrado", command.Notifications));
            }

            var dateBegin = command.DateBegin.ToString("yyyy-MM-dd HH:mm:ss");
            var dateEnd   = command.DateEnd.ToString("yyyy-MM-dd HH:mm:ss");

            var stamp = command.DateEnd.Subtract(command.DateBegin);

            timeShettDb.DateBegin  = Convert.ToDateTime(dateBegin);
            timeShettDb.DateEnd    = Convert.ToDateTime(Convert.ToDateTime(dateEnd));
            timeShettDb.TotalHours = stamp.TotalHours;

            await _timeSheetRepository.UpdateAsync(timeShettDb);

            return(new GenericCommandResult(true, "Apontamento alterado com sucesso", timeShettDb));
        }
예제 #2
0
 public async Task <GenericCommandResult> Update([FromBody] UpdateTimeSheetCommand command, [FromServices] TimeSheetHandler handler)
 {
     return((GenericCommandResult)await handler.Handle(command));
 }