/// <summary> /// Return the ActionResult for all shops by a chain id /// The id is a Chain id /// </summary> /// <param name="id"></param> /// <returns> /// List of Shops /// </returns> public ActionResult ShopList(int?id) { // If the id is null return a empty list of shops if (id == null) { return(View(new List <Shop>())); } var proxy = new BestilNemtServiceClient(); using (proxy) { proxy.Open(); var chain_old = (Chain)Session["Chain"]; var chainId_old = chain_old?.Id; var chain = proxy.GetChain(id.Value); // Set the new Chain Session["Chain"] = chain; // If the id is not different from the id there has been set before reset the id and clear the cart and the shop id if (chain?.Id == chainId_old) { return(View(proxy.GetAllShopsByChainId(id.Value))); } // Clear the cart Session["ShoppingCart"] = null; // Clear the shop Session["Shop"] = null; return(View(proxy.GetAllShopsByChainId(id.Value))); } }
/// <summary> /// Updates the shop with the data inputed in the textfields /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateShop_Click(object sender, RoutedEventArgs e) { //Sets the proxy var proxy = new BestilNemtServiceClient(); //Gets the selected item in the datatable var drv = (DataRowView)ChainList.SelectedItem; if (ShopIdField.Text.Equals("")) { MessageBox.Show("Du skal indlæse en butik"); } else { if (ShopNameField.Text.Equals("")) { MessageBox.Show("Du mangler giv det et navn"); } if (ShopAddressField.Text.Equals("")) { MessageBox.Show("Du mangler give butikken et beskrivelse"); } if (ShopCVRField.Text.Equals("")) { MessageBox.Show("Du mangler Skrive cvr Nummer"); } //create empty table var shop = new Shop(); //Get id from text field shop.Id = int.Parse(ShopIdField.Text); //Get chainId from ChainTable shop.Chain = proxy.GetChain(int.Parse(drv["chainId"].ToString())); //Get name address and CVR from the other text fields shop.Name = ShopNameField.Text; shop.Address = ShopAddressField.Text; shop.Cvr = ShopCVRField.Text; //Gets the opening time form the textfield and sets it as a var var openingTimeRaw = ShopOpeningTimesField.Text; //Replaces the new lines with semicolons because of the databse var newOpeningTime = openingTimeRaw.Replace("\r\n", ";"); //sets the opening time shop.OpeningTime = newOpeningTime; //Updates empty warehouse for the shop shop.Warehouses = new List <Warehouse>().ToArray(); //Sends the new shop for the update with the shopId proxy.UpdateShop(shop); //Update the datatabel FillDataGridShop(); } }
/// <summary> /// Gets all the text from the textfields and datatable, and sends that to the WCF that creates a new Shop /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddShop_Click(object sender, RoutedEventArgs e) { var proxy = new BestilNemtServiceClient(); var drv = (DataRowView)ChainList.SelectedItem; if (ShopNameField.Text.Equals("")) { MessageBox.Show("Du mangler giv det et navn"); } if (ShopAddressField.Text.Equals("")) { MessageBox.Show("Du mangler give butikken et navn"); } if (ShopCVRField.Text.Equals("")) { MessageBox.Show("Du mangler Skrive cvr Nummer"); } else { var shop = new Shop { Chain = proxy.GetChain(int.Parse(drv["chainId"].ToString())), Name = ShopNameField.Text, Address = ShopAddressField.Text, Cvr = ShopCVRField.Text }; //Get the chain id form the ChainDataTable, and get the chain from the prooxy //Replace the the new lines with semicolons because of the database var openingTimeRaw = ShopOpeningTimesField.Text; var newOpeningTime = openingTimeRaw.Replace("\r\n", ";"); shop.OpeningTime = newOpeningTime; shop.Warehouses = new List <Warehouse>().ToArray(); proxy.AddShop(shop); FillDataGridShop(); ClearAllShopTextFields(); } }