public void GetInvoiceHeaderEntityByInvoiceNumberFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 56
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceHeader = invoiceDao.GetByInvoiceNumber(invoiceHeader.InvoiceNumber);

            Assert.IsTrue(invoiceHeader != null);
        }
        public void DeleteInvoiceHeaderFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 10
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            var rowsAffected = invoiceDao.Delete(invoiceHeader);

            Assert.IsTrue(rowsAffected == 1);
        }
        public void GetInvoiceHeaderEntityBySqlFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 56
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            string sqlQuery = $"SELECT * FROM InvoiceHeader WHERE [Id] = {invoiceHeader.Id}";

            invoiceHeader = invoiceDao.GetBySql(sqlQuery);

            Assert.IsTrue(invoiceHeader != null);
        }
        public void WriteInvoiceHeaderEntityToDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 10
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            Assert.IsTrue(invoiceHeader.Id > 0);
        }
示例#5
0
        private IInvoice GetEntityBySql(string sqlQuery)
        {
            IInvoice entity = null;

            try
            {
                using (_connection)
                {
                    using (DbCommand getCommand = new SqlCommand(sqlQuery, _connection))
                    {
                        using (var objectReader = getCommand.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            while (objectReader.Read())
                            {
                                entity = new Invoice
                                {
                                    Id = Convert.ToInt32(objectReader["Id"]),
                                    SenderId = Convert.ToInt32(objectReader["SenderId"]),
                                    RecipientId = Convert.ToInt32(objectReader["RecipientId"]),
                                    CustomerId = Convert.ToInt32(objectReader["CustomerId"]),
                                    SupplierId = Convert.ToInt32(objectReader["SupplierId"]),
                                    InvoiceNumber = Convert.ToInt32(objectReader["InvoiceNumber"]),
                                    OrderNumber = Convert.ToString(objectReader["OrderNumber"]),
                                    FreeText = Convert.ToString(objectReader["FreeText"]),
                                    PaymentDueDate = Convert.ToDateTime(objectReader["PaymentDueDate"]),
                                    DeliveryDateTime = Convert.ToDateTime(objectReader["DeliveryDateTime"]),
                                    CreationDateTime = Convert.ToDateTime(objectReader["CreationDateTime"]),
                                    PaymentMethod = (PaymentMethod)Enum.Parse(typeof(PaymentMethod), Convert.ToString(objectReader["PaymentMethod"]))
                                };
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to retrieve InvoiceHeader entity from SQL statement, {sqlQuery}", ex);
            }

            return entity;
        }