Exemple #1
0
 /// <summary>
 /// Gets the total number of items in specified shop.
 /// </summary>
 /// <param name="shop">The shop.</param>
 /// <returns></returns>
 public int TotalNumberOfItemsInShop(Shop shop)
 {
     int totalItemsCount = 0;
     foreach (ShopItem shopItem in shopItems)
     {
         if (shopItem.ShopId == shop.Id)
         {
             totalItemsCount += shopItem.NumberOfItems;
         }
     }
     return totalItemsCount;
 }
Exemple #2
0
 /// <summary>
 /// Updates the existing shop.
 /// </summary>
 /// <param name="shop">The shop.</param>
 public bool UpdateShop(Shop shop)
 {
     Log.DebugFormat("UpdateShop '{0}'", shop);
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             string commandText = String.Format(CultureInfo.InvariantCulture,
                                                "UPDATE Shops SET Name='{1}', Address='{2}', Owner='{3}', PostalCode='{4}', City='{5}', IsCompany={6} WHERE Id='{0}'",
                                                shop.Id, shop.Name, shop.Address, shop.Owner, shop.PostalCode,
                                                shop.City, shop.IsCompany ? 1 : 0);
             dbCommand.CommandText = commandText;
             Log.Debug(commandText);
             if (dbCommand.ExecuteNonQuery() == 1)
             {
                 return true;
             }
             Log.ErrorFormat("Failed to update shop [{0}]", shop);
             return false;
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// Inserts new shop.
 /// </summary>
 /// <param name="shop">The shop.</param>
 /// <returns><c>true</c> on success.</returns>
 public bool InsertShop(Shop shop)
 {
     Log.DebugFormat("InsertShop '{0}'", shop);
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             string guid = shop.Id.ToString();
             string commandText = String.Format(CultureInfo.InvariantCulture,
                                                "INSERT INTO Shops (Id, Name, Address, Owner, PostalCode, City, IsCompany) VALUES('{0}', '{1}', '{2}', '{3}', {4}, '{5}', {6})",
                                                guid, shop.Name, shop.Address, shop.Owner, shop.PostalCode,
                                                shop.City, shop.IsCompany ? 1 : 0);
             Log.Debug(commandText);
             dbCommand.CommandText = commandText;
             if (dbCommand.ExecuteNonQuery() == 1)
             {
                 return true;
             }
             Log.ErrorFormat("Failed to insert shop [{0}]", shop);
             return false;
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Gets the shop.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <returns><c>null</c> if not found.</returns>
 public Shop GetShopByName(string name)
 {
     Log.DebugFormat("GetShopByName with name='{0}'", name);
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             string commandText = String.Format(CultureInfo.InvariantCulture,
                                           "SELECT * FROM Shops WHERE Name='{0}'", name);
             dbCommand.CommandText = commandText;
             Log.Debug(commandText);
             using (DbDataReader reader = dbCommand.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     Shop shop = new Shop
                         {
                             Id = new Guid(reader[0].ToString()),
                             Name = reader[1].ToString(),
                             Address = reader[2].ToString(),
                             Owner = reader[3].ToString(),
                             PostalCode = Int32.Parse(reader[4].ToString()),
                             City = reader[5].ToString(),
                             IsCompany = Boolean.Parse(reader[6].ToString()),
                         };
                     Log.InfoFormat("Found shop: [{0}]", shop);
                     return shop;
                 }
             }
         }
     }
     Log.WarnFormat("Shop with name={0} not found!", name);
     return null;
 }
Exemple #5
0
 /// <summary>
 /// Gets the price for specified item in specified shop.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="shop">The shop.</param>
 /// <returns></returns>
 public Price GetPrice(Item item, Shop shop)
 {
     Log.DebugFormat("GetPrice. Item='{0}', Shop='{1}'", item, shop);
     Price price = null;
     using (dbConnection)
     {
         using (DbCommand dbCommand = dbConnection.CreateCommand())
         {
             dbConnection.Open();
             string commandText = String.Format(CultureInfo.InvariantCulture,
                                           "SELECT * FROM Price WHERE Item='{0}' AND Shop='{1}'",
                                           item.UniqueId, shop.Id);
             dbCommand.CommandText = commandText;
             Log.Debug(commandText);
             using (DbDataReader reader = dbCommand.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     price = new Price
                         {
                             Gross = Double.Parse(reader[1].ToString()),
                             Net = Double.Parse(reader[2].ToString()),
                             Id = new Guid(reader[4].ToString()),
                         };
                     Log.InfoFormat("Price={0}", price);
                     break;
                 }
             }
         }
     }
     Log.Warn("Price not found!");
     return price;
 }