예제 #1
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);
        }
예제 #2
0
        public bool UpdateBook(int id, BookEnt book)
        {
            var success = false;

            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) <= (book.SalePrice * 1.10))
                {
                    book.PurchasePrice = Convert.ToDecimal(book.SalePrice * 1.10);
                }

                var result = data.UpdateBook(id, book);
                success = result;
            }

            if (success)
            {
                try
                {
                    var sender = new MessageSender();
                    sender.SendMessageConfigurationManager("*****@*****.**", "Actualización de libro", $"Nombre: {book.NameBook} Precio de venta {book.PurchasePrice} ");
                }
                catch (Exception ex)
                {
                    Logger.logger.Error(ex);
                }
            }

            return(success);
        }
예제 #3
0
        /// <summary>
        /// Método utilizado para obtener los datos del formulario
        /// </summary>
        /// <returns></returns>
        private BookEnt GetBookForm()
        {
            var messageValidation = ValidateNewBookForm();

            if (!string.IsNullOrEmpty(messageValidation))
            {
                MessageBox.Show(messageValidation, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return(null);
            }

            var book = new BookEnt
            {
                NameBook = txtNameBook.Text
                ,
                DatePublishBook = dtPublishDateBook.Value
                ,
                NumberPages = Convert.ToInt16(nudPagesBook.Value)
                ,
                SalePrice = Convert.ToDouble(txtSalePrice.Text)
                ,
                PurchasePrice = !string.IsNullOrEmpty(txtPurchasePrice.Text) ? Convert.ToDecimal(txtPurchasePrice.Text) : 0
                ,
                IsAvaible = chAvaible.Checked
            };

            return(book);
        }
예제 #4
0
        public BookEnt GetBookById(int id)
        {
            var book = new BookEnt();

            using (var data = new BookData())
            {
                book = data.GetBookById(id);
            }

            return(book);
        }
예제 #5
0
        private void btnCreateRand_Click(object sender, EventArgs e)
        {
            var book = BookEntHelper.GetRandomBooks(1).First();

            lblNameBook.Text        = book.NameBook;
            lblNumberPages.Text     = book.NumberPages.ToString();
            lblSalePrice.Text       = book.SalePrice.ToString("0.00");
            lblPurchasePrice.Text   = book.PurchasePrice.ToString("0.0000");
            lblIsAvaible.Text       = book.IsAvaible.ToString();
            lblDatePublishBook.Text = book.DatePublishBook.ToString("dd/MM/yyyy");

            RandBook = book;
        }
예제 #6
0
        public Book DeleteBook(int bookID)
        {
            BookEnt dbEntry = context.Books.FirstOrDefault(b => b.BookEntId == bookID);

            if (dbEntry != null)
            {
                context.Books.Remove(dbEntry);
                context.SaveChanges();
            }
            Book book = ConvertEntity.ConvertToBook(dbEntry);

            return(book);
        }
예제 #7
0
        static public BookEnt ConvertToBookEnt(Book book)
        {
            BookEnt bookEnt = new BookEnt
            {
                Author      = book.Author,
                BookEntId   = book.BookId,
                Description = book.Description,
                Category    = book.Category,
                Count       = book.Count,
                Name        = book.Name,
                Price       = book.Price
            };

            return(bookEnt);
        }
예제 #8
0
        static public Book ConvertToBook(BookEnt bookEnt)
        {
            Book book = new Book
            {
                Author      = bookEnt.Author,
                BookId      = bookEnt.BookEntId,
                Description = bookEnt.Description,
                Category    = bookEnt.Category,
                Count       = bookEnt.Count,
                Name        = bookEnt.Name,
                Price       = bookEnt.Price
            };

            return(book);
        }
예제 #9
0
        public bool AddBook(BookEnt book)
        {
            ///Iniciaizar conexión a base de datos utilizando el método de
            ///conexión de Helper
            var command = _dbConnection.CreateCommand();

            ///Nombre del SP
            command.CommandText    = "sp_add_books";
            command.CommandTimeout = TimeOut;
            command.CommandType    = CommandType.StoredProcedure;

            ///EL orden de los parámetros debe de ser igual al orden declarado en el SP
            var parameters = new List <SqlParameter> {
                new SqlParameter {
                    ParameterName = "@NameBook", Value = book.NameBook, SqlDbType = SqlDbType.NVarChar
                },
                new SqlParameter {
                    ParameterName = "@DatePublish", Value = book.DatePublishBook, SqlDbType = SqlDbType.Date
                },
                new SqlParameter {
                    ParameterName = "@NumberPages", Value = book.NumberPages, SqlDbType = SqlDbType.SmallInt
                },
                new SqlParameter {
                    ParameterName = "@SalePrice", Value = book.SalePrice, SqlDbType = SqlDbType.Decimal
                },
                new SqlParameter {
                    ParameterName = "@PurchasePrice", Value = book.PurchasePrice, SqlDbType = SqlDbType.Decimal
                },
                new SqlParameter {
                    ParameterName = "@IsAvaible", Value = book.IsAvaible, SqlDbType = SqlDbType.Bit
                }
            };

            //agregar parámetros a commando de ejecución
            command.Parameters.AddRange(parameters.ToArray());

            //ejecutar el comando
            int rowsAffected = command.ExecuteNonQuery();

            return((rowsAffected == 1) ? true : false);
        }
예제 #10
0
        public bool UpdateBook(int id, BookEnt book)
        {
            var command = _dbConnection.CreateCommand();

            ///Nombre del SP
            command.CommandText    = "sp_update_books";
            command.CommandTimeout = TimeOut;
            command.CommandType    = CommandType.StoredProcedure;

            ///EL orden de los parámetros debe de ser igual al orden declarado en el SP
            var parameters = new List <SqlParameter> {
                new SqlParameter {
                    ParameterName = "@Id", Value = book.IdBook, SqlDbType = SqlDbType.Int
                },
                new SqlParameter {
                    ParameterName = "@NameBook", Value = book.NameBook, SqlDbType = SqlDbType.NVarChar
                },
                new SqlParameter {
                    ParameterName = "@DatePublish", Value = book.DatePublishBook, SqlDbType = SqlDbType.Date
                },
                new SqlParameter {
                    ParameterName = "@NumberPages", Value = book.NumberPages, SqlDbType = SqlDbType.SmallInt
                },
                new SqlParameter {
                    ParameterName = "@SalePrice", Value = book.SalePrice, SqlDbType = SqlDbType.Decimal
                },
                new SqlParameter {
                    ParameterName = "@PurchasePrice", Value = book.PurchasePrice, SqlDbType = SqlDbType.Decimal
                },
                new SqlParameter {
                    ParameterName = "@IsAvaible", Value = book.IsAvaible, SqlDbType = SqlDbType.Bit
                }
            };

            command.Parameters.AddRange(parameters.ToArray());

            int rowsAffected = command.ExecuteNonQuery();

            return((rowsAffected == 1) ? true : false);
        }
예제 #11
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);
        }
예제 #12
0
        public void SaveBook(Book book)
        {
            BookEnt bookEnt = ConvertEntity.ConvertToBookEnt(book);

            if (book.BookId == 0)
            {
                context.Books.Add(bookEnt);
            }
            else
            {
                BookEnt dbEntry = context.Books.FirstOrDefault(b => b.BookEntId == book.BookId);
                if (dbEntry != null)
                {
                    dbEntry.Name        = book.Name;
                    dbEntry.Description = book.Description;
                    dbEntry.Price       = book.Price;
                    dbEntry.Category    = book.Category;
                    dbEntry.Author      = book.Author;
                    dbEntry.Count       = book.Count;
                }
            }
            context.SaveChanges();
        }