Example #1
0
        public bool SP_InsertBook(SPInsertBookInput input)
        {
            bool output = false;
            DbNonQueryResponse dbData     = null;
            string             methodName = MethodBase.GetCurrentMethod().GetName();
            var sw = Stopwatch.StartNew();

            try
            {
                if (input != null)
                {
                    string commandText = $"CALL SP_INSERT_BOOK('{input.BOOK_TITLE}', ARRAY [{string.Join(",", input.AUTHORS_NAMES.Select(a => $"'{a}'"))}]);";

                    dbData = this._dbContext.ExecuteNonQuery(commandText, null, $"{methodName}");
                    if (dbData?.Success ?? false)
                    {
                        output = true;
                    }
                }

                return(output);
            }
            catch (Exception ex)
            {
                LogEngine.BookLogger.WriteToLog(LogLevels.Error, $"DAL.Exception: {JsonConvert.SerializeObject(ex)}");
                return(output = false);
            }
            finally
            {
                sw.Stop();
                LogEngine.BookLogger.WriteToLog(LogLevels.Debug, $"DAL.{methodName}(SUCCESS={dbData?.Success}) in {sw.ElapsedMilliseconds}ms");
            }
        }
Example #2
0
        private async Task <bool> CreateWorkAsync(CancellationToken ct = default(CancellationToken))
        {
            return(await Task.Run(() =>
            {
                bool output = false;
                string methodName = MethodBase.GetCurrentMethod().GetName();
                var sw = Stopwatch.StartNew();

                try
                {
                    Console.WriteLine("Insira o título da nova obra.");
                    string workTitle = Console.ReadLine();
                    if (string.IsNullOrEmpty(workTitle))
                    {
                        Console.WriteLine("Nome inválido.");
                        return false;
                    }
                    Console.WriteLine("Insira o nome do autor.");
                    string authorName = Console.ReadLine();
                    if (string.IsNullOrEmpty(authorName))
                    {
                        Console.WriteLine("Id inválido.");
                        return false;
                    }

                    SPInsertBookInput insertBookInput = new SPInsertBookInput
                    {
                        BOOK_TITLE = workTitle,
                        AUTHORS_NAMES = new List <string>()
                        {
                            authorName
                        }
                    };

                    output = _booksRepository.SP_InsertBook(insertBookInput);

                    return output;
                }
                catch (Exception ex)
                {
                    LogEngine.CLILogger.WriteToLog(LogLevels.Error, $"DAL.Exception: {JsonConvert.SerializeObject(ex)}");
                    return output = false;
                }
                finally
                {
                    sw.Stop();
                    string message = output == true ? "Livro adicionado com sucesso" : "Não foi possivel adicionar livro.";
                    Console.WriteLine(message);
                    LogEngine.CLILogger.WriteToLog(LogLevels.Debug, $"BLL.{methodName}(OUT={output}) in {sw.ElapsedMilliseconds}ms");
                }
            }, ct).ConfigureAwait(true));
        }