Exemplo n.º 1
0
        public string AddNewBook(Book book)
        {
            logger.Info("Inside AddNewBook method");

            if (book.id < 0)
            {
                logger.Error(new InvalidIdException());
                return(new InvalidIdException().Message);
            }
            if (book.price < 50)
            {
                logger.Error(new InvalidPriceException());
                return(new InvalidPriceException().Message);
            }
            if (!book.name.All(Char.IsLetter))
            {
                logger.Error(new InvalidBookNameException());
                return(new InvalidBookNameException().Message);
            }
            if (!book.author.All(Char.IsLetter))
            {
                logger.Error(new InvalidAuthorNameException());
                return(new InvalidAuthorNameException().Message);
            }
            logger.Info("Book added succesfully");
            return(bookdata.AddBook(book));
        }
Exemplo n.º 2
0
        public bool AddBook(BookEnt book)
        {
            var result = false;

            using (var scope = new TransactionScope())
            {
                using (var data = new BookData())
                {
                    //Regla: el nombre de los libros debe de guardarse en mayusculas
                    book.NameBook = book.NameBook.ToUpper().Trim();

                    //Regla: debe de ser mayor o igual a un 10 porciento del precio de compra
                    if ((Convert.ToDouble(book.PurchasePrice) > 9999.9999) || Convert.ToDouble(book.PurchasePrice) <= (book.SalePrice * 1.10))
                    {
                        book.PurchasePrice = Convert.ToDecimal(book.SalePrice * 1.10);
                    }

                    result = data.AddBook(book);
                }

                scope.Complete();
            }

            return(result);
        }
Exemplo n.º 3
0
 public bool AddBook(Book book)
 {
     using (var data = new BookData())
     {
         var result = data.AddBook(book);
         return(result);
     }
 }
Exemplo n.º 4
0
        public void TestAddBook()
        {
            BookData bookdata;

            bookdata = new BookData();
            Book book = new Book()
            {
                name = "CleanCode", price = 100, pages = 350, author = "NoOne", id = 4
            };

            bookdata.AddBook(book);
            Assert.Equal(2, bookdata.getlist().Count);
        }
Exemplo n.º 5
0
        public bool AddBook(Book book)
        {
            using (var data = new BookData())
            {
                var result = data.AddBook(book);

                if (result)
                {
                    var message = new MessageSender();
                    //se tiene que validar que el valor ingresado si sea un correo
                    //message.SendMessage("*****@*****.**", "Se agregó nuevo libro", JsonConvert.SerializeObject(book));
                    message.SendMessageAppConfig("*****@*****.**", "Se agregó nuevo libro", JsonConvert.SerializeObject(book));
                }

                return(result);
            }
        }
Exemplo n.º 6
0
        public bool AddBook(BookEnt book)
        {
            var result = false;

            //Se inicializa la transacccion
            using (var scope = new TransactionScope())
            {
                using (var data = new BookData())
                {
                    //Regla: el nombre de los libros debe de guardarse en mayusculas
                    book.NameBook = book.NameBook.ToUpper().Trim();

                    //Regla: debe de ser mayor o igual a un 10 porciento del precio de compra
                    if ((Convert.ToDouble(book.PurchasePrice) > 9999.9999) || Convert.ToDouble(book.PurchasePrice) <= (book.SalePrice * 1.10))
                    {
                        book.PurchasePrice = Convert.ToDecimal(book.SalePrice * 1.10);
                    }

                    result = data.AddBook(book);
                }
                if (result)
                {
                    try
                    {
                        //TODO: Ver. la configuracion del correo
                        //MessageSender.SendMessageConfigurationManager("*****@*****.**", "Actualización de libro", $"Nombre: {book.NameBook} Precio de venta {book.PurchasePrice} ");
                        scope.Complete(); // si no se alcanza el scope comple, el rollback es implicito
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        CustomLogger.logger.Error(ex);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
 public OperationResult AddBook(Book book, string userName, string guid)
 {
     if (!CheckAuthenticated(userName, guid))
     {
         return(new OperationResult(Library.Models.OperationResult.ErrorEnum.NotAuthenticated,
                                    "Please authenticate first!"));
     }
     if (book == null || !book.Validate())
     {
         return(new OperationResult(Library.Models.OperationResult.ErrorEnum.InvalidInputData, "Invalid or missing book data"));
     }
     try
     {
         using (BookData bookData = new BookData())
         {
             bookData.AddBook(book);
             return(new OperationResult());
         }
     }
     catch (Exception ex)
     {
         return(new OperationResult(Library.Models.OperationResult.ErrorEnum.InternalProblem, "Some internal problem has occured"));
     }
 }
Exemplo n.º 8
0
 public void AddBook(Book newBook)
 {
     bookData.AddBook(newBook);
 }