/// <summary> /// Author: James Heim /// Created 2019-02-28 /// /// Select all shops from table as well as their /// corresponding RoomNumber and BuildingID from /// the Room Table. /// </summary> /// <returns></returns> public List <VMBrowseShop> SelectVMShops() { List <VMBrowseShop> shops = new List <VMBrowseShop>(); var conn = DBConnection.GetDbConnection(); var cmdText = @"sp_select_view_model_shops"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { VMBrowseShop shop = new VMBrowseShop() { ShopID = reader.GetInt32(0), RoomID = reader.GetInt32(1), Name = reader.GetString(2), Description = reader.GetString(3), Active = reader.GetBoolean(4), RoomNumber = reader.GetInt32(5), BuildingID = reader.GetString(6) }; shops.Add(shop); } } } catch (Exception) { throw; } finally { conn.Close(); } return(shops); }
/// <summary> /// Author: James Heim /// Created 2019-03-07 /// /// Activates the shop passed in. /// </summary> /// <returns>Whether the shop was activated</returns> private bool activateShop(VMBrowseShop vmShop) { bool result = false; // Prompt the user with a confirmation dialog. var messageBoxResult = MessageBox.Show( string.Format(_activateMessageBoxText, vmShop.Name), _activateMessageBoxCaption, MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { try { var selectedShop = _shopManager.RetrieveShopByID(vmShop.ShopID); result = _shopManager.ActivateShop(selectedShop); } catch (NullReferenceException nre) { MessageBox.Show("Could not find the Shop in the database.\n" + nre.Message + "\n" + nre.InnerException); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.InnerException); } if (result) { MessageBox.Show( string.Format(_activateConfirmMessageBoxText, vmShop.Name), _activateConfirmMessageBoxCaption); refreshShops(); } } return(result); }