Ejemplo n.º 1
0
        public async Task <CommandResult> AddAsync(State state)
        {
            CommandResult commandResult;
            Stopwatch     watch = Stopwatch.StartNew();

            try
            {
                if (!await CanAddAsync(state, true))
                {
                    commandResult = CommandResult.BadRequest("Registro não pode ser salvo, existem erros.");
                }
                else
                {
                    state = await StateRepository.AddAsync(state);

                    commandResult = await CommitAsync(_commandName, state.Action);

                    if (commandResult.Success)
                    {
                        commandResult.Data = state;
                    }
                }
            }
            catch (Exception ex)
            {
                commandResult = CommandResult.InternalServerError($"Ocorreu um erro ao salvar.");
            }

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

            return(commandResult);
        }