예제 #1
0
        public Vendor GetVendorOrNull(int id)
        {
            _logger.Info($"BLL.{nameof(VendorBll)}.{nameof(GetVendorOrNull)}: Getting the vendor id = " + id);

            if (_vendorDao.IsVendor(id))
            {
                _logger.Info($"BLL.{nameof(VendorBll)}.{nameof(GetVendorOrNull)}: Vendor id = {id} received");

                return(_vendorDao.GetVendor(id));
            }
            else
            {
                _logger.Warn($"BLL.{nameof(VendorBll)}.{nameof(GetVendorOrNull)}: Vendor id = {id} not found");

                return(null);
            }
        }
        public IEnumerable <CommodityUnit> GetAllCommodityUnits()
        {
            _logger.Info($"DAL.{nameof(CommodityUnitDao)}.{nameof(GetAllCommodityUnits)}: Getting all commodity units");

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                SqlCommand command = new SqlCommand("dbo.Product_Store_Vendor_Status_GetAllCommodityUnits", connection)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };

                SqlDataReader reader;

                try
                {
                    connection.Open();

                    reader = command.ExecuteReader();

                    _logger.Info($"DAL.{nameof(CommodityUnitDao)}.{nameof(GetAllCommodityUnits)}: Connected to database");
                }
                catch (InvalidOperationException ex)
                {
                    _logger.Error($"DAL.{nameof(CommodityUnitDao)}.{nameof(GetAllCommodityUnits)}: Not connected to database: " + ex.Message);

                    throw new SystemException("Connection error", ex);
                }

                int?ProductID, StatusID, StoreID, VendorID;

                while (reader.Read())
                {
                    ProductID = (int?)reader["ProductID"];
                    StatusID  = (int?)reader["StatusID"];
                    StoreID   = (int?)reader["StoreID"];
                    VendorID  = (int?)reader["VendorID"];

                    yield return(new CommodityUnit(
                                     (int?)reader["Id"],
                                     ProductID is null ? null : _productDao.GetProduct(ProductID ?? -1),
                                     StoreID is null ? null : _storeDao.GetStore(StoreID ?? -1),
                                     VendorID is null ? null : _vendorDao.GetVendor(VendorID ?? -1),
                                     StatusID is null ? null : _statusDao.GetStatus(StatusID ?? -1),
                                     (decimal)reader["Price"]));
                }
            }

            _logger.Info($"DAL.{nameof(ProductDao)}.{nameof(GetAllCommodityUnits)}: All commodity units received");

            yield break;
        }