Exemplo n.º 1
0
        public Task <List <StockModel> > AddStock(int type, decimal price, int quantity, int occurence)
        {
            using (var command = DbSqlCommand.GetSqlCommand())
            {
                try
                {
                    command.CommandText = SqlConstants.Stock.spAddStock;
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@type", type);
                    command.Parameters.AddWithValue("@price", price);
                    command.Parameters.AddWithValue("@quantity", quantity);
                    command.Parameters.AddWithValue("@occurence", occurence);

                    command.Connection.Open();

                    var reader = command.ExecuteReader();

                    var stocks = new List <StockModel>();

                    while (reader.Read())
                    {
                        stocks.Add(new StockModel
                        {
                            ID              = reader.GetInt32(0),
                            Quantity        = reader.GetInt32(1),
                            Price           = reader.GetDecimal(2),
                            Name            = reader.GetString(3),
                            StockProperties = new StockPropertyModel
                            {
                                Id        = reader.GetInt32(4),
                                Cost      = reader.GetDecimal(5),
                                Tolerance = reader.GetDecimal(6),
                                StockType = new StockTypeModel
                                {
                                    Type      = reader.GetInt32(7),
                                    Name      = reader.GetString(8),
                                    Occurence = reader.GetInt32(9),
                                }
                            }
                        });
                    }

                    return(Task.FromResult <List <StockModel> >(stocks));
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                }
                finally
                {
                    command.Connection.Close();
                }

                return(null);
            }
        }
Exemplo n.º 2
0
        public IList <StockPropertyModel> GetAllStockProperties()
        {
            using (var command = DbSqlCommand.GetSqlCommand())
            {
                try
                {
                    command.CommandText = SqlConstants.StockProperty.spGetAllProperties;
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Connection.Open();

                    var reader = command.ExecuteReader();

                    var stockProperties = new List <StockPropertyModel>();

                    while (reader.Read())
                    {
                        stockProperties.Add(new StockPropertyModel
                        {
                            Id        = reader.GetInt32(3),
                            Cost      = reader.GetDecimal(4),
                            Tolerance = reader.GetDecimal(5),
                            StockType = new StockTypeModel
                            {
                                Type      = reader.GetInt32(7),
                                Name      = reader.GetString(8),
                                Occurence = reader.GetInt32(7),
                            }
                        });
                    }

                    return(stockProperties);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                }
                finally
                {
                    command.Connection.Close();
                    _logger.Debug("DbConnection");
                }

                return(null);
            }
        }
Exemplo n.º 3
0
        public Task <List <StockTypeModel> > GetAllStockTypes()
        {
            string spGetAllStocks = SqlConstants.Stock.spGetAllStocks;

            using (var command = DbSqlCommand.GetSqlCommand())
            {
                try
                {
                    command.CommandText = SqlConstants.StockType.spGetAllStockTypes;
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Connection.Open();

                    var reader = command.ExecuteReader();

                    var stockType = new List <StockTypeModel>();

                    while (reader.Read())
                    {
                        stockType.Add(new StockTypeModel
                        {
                            Type      = reader.GetInt32(0),
                            Name      = reader.GetString(1),
                            Occurence = reader.GetInt32(2),
                        });
                    }

                    return(Task.FromResult <List <StockTypeModel> >(stockType));
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                }
                finally
                {
                    command.Connection.Close();
                }

                return(null);
            }
        }
Exemplo n.º 4
0
        public void DatabaseCommandCresteCommandTesting()
        {
            var dbConnection = DbSqlCommand.GetSqlCommand();

            Xunit.Assert.NotNull(dbConnection);
        }