/// <summary> /// Used to update a product /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateProduct_Click(object sender, RoutedEventArgs e) { var proxy = new BestilNemtServiceClient(); //Create an empty product var product = new Product(); if (ProductId.Text.Equals("")) { MessageBox.Show("Du skal have indlæst et produkt"); } else { //Parse the textfield from a string to an int product.Id = int.Parse(ProductId.Text); //Gets the rest of the textfields and adds them to the local product product.Name = ProductName.Text; product.Price = decimal.Parse(ProductPrice.Text); product.Category = ProductCategory.Text; product.Description = ProductDescription.Text; product.ImgPath = ProductImgPath.Text; //Sends the local product with the ID to update the specific product proxy.UpdateProduct(product); //Updates the datatable FillDataGridProducts(); ClearProductTextField(); } }
/// <summary> /// This method is used to login /// </summary> /// <param name="login"></param> /// <returns> /// View of Homepage if not logged in, else Home of Login /// </returns> public ActionResult Signdo(Login login) { var proxy = new BestilNemtServiceClient(); // If There is no login object, redirect to frontpage if (login == null) { return(RedirectToAction("Index", "Home")); } // Login with the login object, return null if login failed, else a login object with a personId login = proxy.Login(login); // Login is now null if the username and password not match if (login == null) { return(Content("<script language='javascript' type='text/javascript'>alert('Brugernavn eller Adganskode er forkert'); window.location.replace('http://localhost:50483/Login/SignIn');</script>")); } // Save the new login object to session Session["Login"] = login; // Save the person to the cart var personId = login.PersonId; // Get the Cart from Session var cart = (Cart)Session["ShoppingCart"]; // If the personId somehow is 0 and not set now, redirect to Login Home if (personId == 0) { return(RedirectToAction("Index", !string.IsNullOrEmpty(login.Username) ? "Home" : "Login")); } // Set the personId to the Cart cart.PersonId = personId; // Save the cart to the Session Session["ShoppingCart"] = cart; // Redirect to Home if Username is null or empty, else to Login return(RedirectToAction("Index", !string.IsNullOrEmpty(login.Username) ? "Home" : "Login")); }
/// <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))); } }
public ActionResult CheckOut() { var proxy = new BestilNemtServiceClient(); try { // Checks for partorder is empty in cart if (ShoppingCart.PartOrders.Capacity == 0) { return(Content("<script language='javascript' type='text/javascript'>alert('Du mangler at tilføje vare til din kurv'); window.location.replace('http://localhost:50483/Cart/GetCart/0');</script>")); } // If there is partorder on cart, you will continue to checkout var fl = proxy.AddCartWithPartOrders((Cart)Session["ShoppingCart"]); if (fl == 1) { return(View()); } // if product is already taken, before you checkout, and the wanted amount is not abliable return(Content("<script language='javascript' type='text/javascript'>alert('Du er for langsomt. Varen er blevet købt. Øv-Øv'); window.location.replace('http://localhost:50483/Cart/GetCart/0');</script>")); } // if product is already is taken, before you checkout, and the wanted amount is not abliable catch (System.Exception) { return(Content("<script language='javascript' type='text/javascript'>alert('Ønsket antal varer ikke på lager'); window.location.replace('http://localhost:50483/Cart/GetCart/0');</script>")); } }
/// <summary> /// Get a list of all products by a shop id /// The id is Shop id /// </summary> /// <param name="id"></param> /// <returns> /// View of all Products /// </returns> public ActionResult Product(int?id) { // Create a empty list of Products to return if something is not right, else fill it var products = new List <Product>(); // Get the shop from session var shopSes = (Shop)Session["Shop"]; // Get the cart from Session var cart = (Cart)Session["ShoppingCart"]; ViewBag.Cart = cart; var proxy = new BestilNemtServiceClient(); // If the id is null check if shop from session is also null, then return the view if (id == null) { // Check if shop from session is null if (shopSes == null) { // Return a view of empty list return(View(products)); } // Set the id to the id from the shop from session id = shopSes.Id; } // if the value of id is lower than or equal 0 return the empty list if (id.Value <= 0) { return(View(products)); } // Get the shop by the id var shop = proxy.GetShop(id.Value); // If the shop is null return the empty list if (shop == null) { return(View(products)); } // Get all Warehouses with with the shop id shop.Warehouses = proxy.GetAllWarehousesByShopId(id.Value); // If the shop from session is set if (shopSes != null) { // If the ids is different reset the cart if (shopSes.Id != shop.Id) { // Clear the cart from Session Session["ShoppingCart"] = null; } } // Save the shop to session Session["Shop"] = shop; // Get all products from the warehouses products = shop.Warehouses.Select(warehouse => warehouse.Product).ToList(); // Return the view with the list of products return(View(products)); }
public ActionResult AddProductToCart(ProductPartOrderViewModel partOrder) { // Get the login from session and check if a person is set, is not return a site with a javascript var login = (Login)Session["Login"]; if (login.PersonId == 0) { return(Content("<script language='javascript' type='text/javascript'>alert('Du skal være logget ind får at tilføje til kurv :)');</script>")); } // Get the cart from Session var cart = (Cart)Session["ShoppingCart"]; var proxy = new BestilNemtServiceClient(); // Get the product by a partOrder product id. var product = proxy.GetProduct(partOrder.Product.Id); // Make the PartOrder object var po = new PartOrder { Product = product, Amount = partOrder.Amount, PartPrice = product.Price * partOrder.Amount, Cart = cart }; // Get all PartOrders from cart var partOrders = cart.PartOrders; // There is a partOrder // isFound is used to check if a partOrder is allready added var isFound = false; // Loop for every partOrdeers foreach (var partOrderLoop in partOrders) { // If the product ids not match if (partOrderLoop.Product.Id != partOrder.Product.Id) { continue; } // Update the amount partOrderLoop.Amount = partOrder.Amount + partOrderLoop.Amount; // The PartOrder is found isFound = true; } // If the partOrder is not allready added, add it if (!isFound) { // Add the partOrder to the list partOrders.Add(po); } // Save the list of PartOrders to the cart cart.PartOrders = partOrders; // Update the session of Cart Session["ShoppingCart"] = cart; // Get the shop from session var shop = (Shop)Session["Shop"]; // Return the view to Product with the Shop id return(RedirectToAction("Product", new { id = shop.Id })); }
/// <summary> /// Get the data used to fill the DataGrid in the Butik tab, this is done with a custom SQL qurey that gets all the colums that we need /// </summary> public void FillDataGridShop() { var proxy = new BestilNemtServiceClient(); //Get the list of shops from database via wcf var dt = proxy.GetDataGridShop(); //Sets the datatable to correspond to the datatable in the GUI ShopList.ItemsSource = dt.DefaultView; }
/// <summary> /// Used to get the desired data of a chain, this is used so you can select it in a datatabel /// </summary> public void GetChainData() { var proxy = new BestilNemtServiceClient(); //Get the list of chains from database via wcf var dt = proxy.GetChainData(); //Sets the datatable to correspond to the datatable in the GUI ChainList.ItemsSource = dt.DefaultView; }
/// <summary> /// Fills the main table on the product page, this uses a SQL query to get the desired coloums /// </summary> private void FillDataGridProducts() { var proxy = new BestilNemtServiceClient(); //Get data table with products info from wcf var dt = proxy.GetDataGridProducts(); //Sets the datatable to correspond to the datatable in the GUI ProductInformation.ItemsSource = dt.DefaultView; }
private void RemoveSaving_Click(object sender, RoutedEventArgs e) { var proxy = new BestilNemtServiceClient(); //take the id from the loaded product and saving var id = int.Parse(SavingIdField.Text); //send the id to the proxy, so the saving can be deleted proxy.DeleteSaving(id); ClearWareHouseFields(); }
/// <summary> /// This method show all receipts to the person logged in /// </summary> /// <returns> /// View list of Carts /// </returns> public ActionResult Receipt() { // Get the login from Session var login = (Login)Session["Login"]; // If the login has a PersonId use it, else set it to 0 var personId = login?.PersonId ?? 0; var proxy = new BestilNemtServiceClient(); // Get a list of all Carts related to the person var carts = proxy.GetAllCartsByPersonId(personId); return(View(carts)); }
/// <summary> /// Find an product, and then adding a new warehouse /// </summary> public void AddProductToWarehouse() { var proxy = new BestilNemtServiceClient(); //Finds the currentuser, by using our static class var currentUser = LoginManager.User; var id = currentUser.PersonId; //finds the corret admin var admin = proxy.GetAdmin(id); var shopIdAdmin = 0; shopIdAdmin = admin.ShopId; //finds the shop through admin Shop getShop = proxy.GetShop(shopIdAdmin); if (ProductId.Text.Equals("")) { MessageBox.Show("Du har glemt at indlæse i produkt"); } else { Warehouse warehouse = new Warehouse(); var productId = int.Parse(ProductId.Text); //Getting all warehouse with a shopID, and loop through it var warehouses = proxy.GetAllWarehousesByShopId(getShop.Id); foreach (var w in warehouses) { if (w.Product.Id == productId) { warehouse = w; } } //sets value in the textboxes warehouse.MinStock = int.Parse(minStock.Text); warehouse.Stock = int.Parse(Stock.Text); warehouse.Shop = getShop; warehouse.SavingId = null; warehouse.Product = proxy.GetProduct(productId); var warehouseId = proxy.AddWarehouse(warehouse); //If the warehouse couldn't be created, it shows a message telling the user //If the warehouse is create, then the user gets a message telling it succeced if (warehouseId == 0) { MessageBox.Show("Varehus findes allerede, opret et ny produkt"); } else { MessageBox.Show("Produktet er tilføjet til dit varehus"); } } }
/// <summary> /// Add a PartOrder to a Cart /// Use of PartOrders Cart object /// </summary> /// <param name="partOrder"></param> /// <returns> /// The View /// </returns> public ActionResult AddtoCart(PartOrder partOrder) { var proxy = new BestilNemtServiceClient(); // Check for partOrder != null and partOrder.Cart != null if (partOrder?.Cart != null) { // Call the Service provider proxy.AddPartOrder(partOrder); } // Return the View return(View()); }
/// <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> /// Creates a saving for a product in the warehouse /// </summary> public void CreateSaving() { var proxy = new BestilNemtServiceClient(); //gets the current admin var currentUser = LoginManager.User; var id = currentUser.PersonId; //Get admin var admin = proxy.GetAdmin(id); //Finds the login shop var shop = proxy.GetShop(admin.ShopId); //Create a local saving object var saving = new Saving(); //Takes the date selected and makes them a datetime, instead of strings var startDate = StartDate.SelectedDate; var endDate = EndDate.SelectedDate; //Sets the datetime to the local saving if (startDate != null) { saving.StartDate = startDate.Value; } if (endDate != null) { saving.EndDate = endDate.Value; } //Parses the textfield string to a doube to corresponnd to the database saving.SavingPercent = double.Parse(SavingPercent.Text); //Checks if the user has loaded in a product if (WarehouseIdField.Text == "") { MessageBox.Show("Du mangler at indlæse fra tabellen "); } else { var warehouse = proxy.GetWarehouse(int.Parse(WarehouseIdField.Text)); if (warehouse.SavingId != null) { saving.Id = warehouse.SavingId.Value; } //Adding saving with a warehouse proxy.AddSaving(saving, warehouse); //Setting savingId equals to warehouseId //Reloading the tabel agin FillProductWareHouse(); MessageBox.Show("Du har lavet en rabet på " + ProductName1.Text + " i " + shop.Name); } }
/// <summary> /// Removes a warehouse from the database, by calling the service /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RemoveWarehouseBtn_Click(object sender, RoutedEventArgs e) { BestilNemtServiceClient proxy = new BestilNemtServiceClient(); var wId = WarehouseIdField.Text; if (wId.Equals("")) { MessageBox.Show("Du mangler at markere indlæse et felt"); } else { proxy.DeleteWarehouse(int.Parse(wId)); FillProductWareHouse(); ClearWareHouseFields(); } }
/// <summary> /// Return a view of a specific product with a product id /// The id is a Product id /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult ProductPage(int?id) { // If no id is set redirect to frontpage if (id == null) { return(RedirectToAction("Index", "Home")); } var proxy = new BestilNemtServiceClient(); // Get the PartOrder with a product by a product id var pvm = new ProductPartOrderViewModel { Product = proxy.GetProduct(id.Value) }; // Return the view return(View(pvm)); }
/// <summary> /// Delete the selected shop in the datatable /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteShop_Click(object sender, RoutedEventArgs e) { var proxy = new BestilNemtServiceClient(); //checks tabel shopid is null if (ShopIdField.Text.Equals("")) { MessageBox.Show("Du mangler at indlæse et butik"); } else { var shopId = ShopIdField.Text; proxy.DeleteShop(int.Parse(shopId)); FillDataGridShop(); ClearAllShopTextFields(); } }
/// <summary> /// Deletes the curret loaded product /// This requires you to have used the LoadDataIntoTextFields_Click /// to load the id into the field /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteProduct_Click(object sender, RoutedEventArgs e) { var proxy = new BestilNemtServiceClient(); //checks for you have loadet, a product if (ProductId.Text.Equals("")) { MessageBox.Show("Indlæse venligst et produkt før du prøver at slette det"); } else { //Parse the textfield from a string to an int var id = int.Parse(ProductId.Text); //Contact the WCF to delete the ID, that it got from the textfield proxy.DeleteProduct(id); //Updates the datatable FillDataGridProducts(); ClearProductTextField(); } }
/// <summary> /// Fills the warehouse datatable with data /// </summary> public void FillProductWareHouse() { var proxy = new BestilNemtServiceClient(); //Creates a empty user, var currentUser = LoginManager.User; //Sets the shopId To be 0 //If the user is loged in, then it will get all the details of the person if (currentUser != null) { var id = currentUser.PersonId; var admin = proxy.GetAdmin(id); var shopIdAdmin = admin.ShopId; var dt = proxy.GetProductWareHouse(shopIdAdmin); //Sets the datatable to correspond to the datatable in the GUI ProductWarehouse.ItemsSource = dt.DefaultView; } else { MessageBox.Show("Du er ikke logget ind, hvordan åbenede du det her vindue?"); } }
public ActionResult Index() { var proxy = new BestilNemtServiceClient(); using (proxy) { proxy.Open(); // Get all Chains var chains = proxy.GetAllChains(); // Get all products with a saving var products = proxy.GetAllProductsWithSavings(); // Only have the products one time, comparing by id var productList = products.DistinctBy(product => product.Id).ToList(); // Get all sold products var soldProducts = proxy.GetAllSoldProducts(); // Only have the products one time, comparing by id var soldProductsList = soldProducts.DistinctBy(product => product.Id).ToList(); // Make a Tuple with the three lists, the tuple is used to get three list to the cshtml page var tuple = new Tuple <List <Chain>, List <Product>, List <Product> >(chains, soldProductsList, productList); // Return the Tuple return(View(tuple)); } }
public ActionResult CreateCustomer(Customer customer, Login login) { var proxy = new BestilNemtServiceClient(); // Set the Username to the email for the Customer login.Username = customer.Email; // Alert if the Customer name is null if (string.IsNullOrEmpty(customer.Name) || customer.Name.Length < 4) { return(Content("<script language='javascript' type='text/javascript'>alert('Du mangler at tilføje navn, navnet skal være fornavn og efternavn'); window.location.replace('http://localhost:50483/Login/CreateLogin');</script>")); } // Alert if the Customer address is null if (string.IsNullOrEmpty(customer.Address) || customer.Address.Length < 4) { return(Content("<script language='javascript' type='text/javascript'>alert('Du mangler at tilføje valid adresse'); window.location.replace('http://localhost:50483/Login/CreateLogin');</script>")); } // Alert if the Customer email is under 6 digit if (string.IsNullOrEmpty(customer.Email) || customer.Email.Length < 6) { return(Content("<script language='javascript' type='text/javascript'>alert('Email Min. 6 bogstaver'); window.location.replace('http://localhost:50483/Login/CreateLogin');</script>")); } var dateTime = Convert.ToDateTime(customer.Birthday); if (dateTime == new DateTime(0001, 01, 01, 00, 00, 00)) { return(Content("<script language='javascript' type='text/javascript'>alert('Dato ikke korrekt, skal skrives i følgende format: dd-mm-yyyy'); window.location.replace('http://localhost:50483/Login/CreateLogin');</script>")); } // Alert if the Customer password is under 6 digit if (string.IsNullOrEmpty(login.Password) || login.Password.Length < 6) { return(Content("<script language='javascript' type='text/javascript'>alert('Kodeord Min. 6 cifre'); window.location.replace('http://localhost:50483/Login/CreateLogin');</script>")); } // Add the Customer with the login object proxy.AddCustomerWithLogin(customer, login); // Reload to Index return(Content("<script language='javascript' type='text/javascript'>alert('Bruger tilføjet'); window.location.replace('http://localhost:50483');</script>")); }
/// <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(); } }
/// <summary> /// Used to add a new product to the database when the add button is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddProduct_Click(object sender, RoutedEventArgs e) { //Call the service and create an empty product var proxy = new BestilNemtServiceClient(); var product = new Product(); if (ProductName.Text.Equals("")) { MessageBox.Show("Du mangler at give produket et navn"); } if (ProductPrice.Text.Equals("")) { MessageBox.Show("Du mangler at sætte en ny pris"); } if (ProductCategory.Text.Equals("")) { MessageBox.Show("Du mangler skrive en kategori"); } if (ProductDescription.Text.Equals("")) { MessageBox.Show("Du skal have udfyldt beskrivelse"); } else { //Set the textbox text to correspond to the product attributes product.Name = ProductName.Text; product.Price = Convert.ToDecimal(ProductPrice.Text); product.Category = ProductCategory.Text; product.Description = ProductDescription.Text; product.ImgPath = ProductImgPath.Text; //sends the filled attributes to the service and adds a product to the database proxy.AddProduct(product); //Updates the product table FillDataGridProducts(); ClearProductTextField(); } }
/// <summary> /// Updates the amount on a product in a warehouse /// </summary> public void UpdateAmount() { var proxy = new BestilNemtServiceClient(); //getting the current User var currentUser = LoginManager.User; //Finds his PersonID var id = currentUser.PersonId; //With id we find the admin, and all admin has shopID var admin = proxy.GetAdmin(id); //Checks for value input if (admin.Id == 0) { MessageBox.Show("Du er ikke admin for en bestemt shop"); } if (ProductIdWareHouse.Text.Equals("")) { MessageBox.Show("Du har glemt at indlæs et produkt"); } if (NewAmount1.Text.Equals("")) { MessageBox.Show("Du har glemt at tilføje et antal"); } if (MinAmount.Text.Equals("")) { MessageBox.Show("Du mangler tilføje et minamount"); } else { //var newamount = Int32.TryParse(NewAmount1.Text); //var minamount = Int32.TryParse(MinAmount.Text); if (Convert.ToInt32(NewAmount1.Text) < Convert.ToInt32(MinAmount.Text)) { MessageBox.Show("Nye Antal kan ikke være mindre min. Antal"); } else { var shopIdAdmin = admin.ShopId; //we find the shop for the currentuser/admin var getShop = proxy.GetShop(shopIdAdmin); //Make a new instance of warehouse var warehouse = new Warehouse(); //Get the productID var productId = int.Parse(ProductIdWareHouse.Text); //GetAllWarehousebyShopid() is a list, so we make a foreach loop, and find the corret warehouse = //with right productID var warehouses = proxy.GetAllWarehousesByShopId(getShop.Id); foreach (var w in warehouses) { if (w.Product.Id == productId) { warehouse = w; } } //sets value for textbox warehouse.Stock = int.Parse(NewAmount1.Text); warehouse.MinStock = int.Parse(MinAmount.Text); warehouse.Shop = getShop; //we update warehouse with a new amount proxy.UpdateWarehouse(warehouse); FillProductWareHouse(); MessageBox.Show("Dit Antal er nu blevet opdateret"); } } }
public static void Setup(BestilNemtServiceClient proxy) { Proxy = proxy; }