示例#1
0
        public async Task<CommandResult> AddAsync(Holiday holiday)
        {
            CommandResult commandResult;
            Stopwatch watch = Stopwatch.StartNew();

            try
            {
                if (!await CanAddAsync(holiday, true))
                {
                    commandResult = CommandResult.BadRequest("Registro não pode ser salvo, existem erros.");
                }
                else
                {
                    holiday = await HolidayRepository.AddAsync(holiday);
                    commandResult = await CommitAsync(_commandName, holiday.Action);
                    if (commandResult.Success)
                    {
                        commandResult.Data = holiday;
                    }
                }
            }
            catch (Exception ex)
            {
                commandResult = CommandResult.InternalServerError($"Ocorreu um erro ao salvar.");
            }

            watch.Stop();
            commandResult.ElapsedTime = watch.ElapsedMilliseconds;

            return commandResult;
        }