//Not necessary - can be deleted???? public softwareViewModel AddSupplierToSoftware(long productID, long supplierID, string refSupplier, string productNameSupplier, double price) { //Software software = null; if (productID == 0) { ////Create one new Software + Add to DB + Get ProductID //software = new Software(); //software.ProductID = productID; //message that you need first to fill a product } // Add supplier to Software + add to DB ProductSupplier productSupplier = new ProductSupplier(); productSupplier.ProductID = productID; productSupplier.SupplierID = supplierID; productSupplier.RefSupplier = refSupplier; productSupplier.ProductNameSupplier = productNameSupplier; productSupplier.Price = price; softwareViewModel softwareViewModel = new softwareViewModel(); //softwareViewModel.software = software; softwareViewModel.productSuppliers.Add(productSupplier); return(softwareViewModel); }
public async Task <IActionResult> Create(int[] SelectedSuppliers, [Bind("ProductID,SKU,ProductName,ProductPrice,ProductDescription")] Product product) { if (ModelState.IsValid) { //Generate the next SKU number product.SKU = GenerateSKU.GetNextSKU(_context); _context.Add(product); await _context.SaveChangesAsync(); //add connections to suppliers //first, find the product you just added Product dbProduct = _context.Products.FirstOrDefault(c => c.SKU == product.SKU); //loop through selected suppliers and add them foreach (int i in SelectedSuppliers) { Supplier dbSup = _context.Suppliers.Find(i); ProductSupplier cd = new ProductSupplier(); cd.Product = dbProduct; cd.Supplier = dbSup; _context.ProductSuppliers.Add(cd); _context.SaveChanges(); } return(RedirectToAction(nameof(Index))); } //repopulate the Viewbag ViewBag.AllSuppliers = GetAllSuppliers(); return(View(product)); }
private void btnAdd_Click(object sender, EventArgs e) { if (Package == null) { throw new MissingMemberException("Package is not assigned"); } ProductSupplier prodSup = GetProductSupplier(); if (prodSup == null) { MessageBox.Show("Product/Supplier not found in database", "ERROR"); return; } // Add ProductPackageSupplier to database PackageProdSupplier pkgProdSup = new PackageProdSupplier { PackageID = Package.ID, ProdSuppID = prodSup.ProductSupplierId }; PackageProdSuppDB.Insert(pkgProdSup); //Return this.DialogResult = DialogResult.OK; this.Close(); }
//save new product-supplier into database private void btnProdSupplierSave_Click(object sender, EventArgs e) { if (cboProductSupplierAdd.SelectedValue != null) { ProductSupplier ps = new ProductSupplier { ProductId = currentProduct.ProductId, SupplierId = Convert.ToInt32(cboProductSupplierAdd.SelectedValue) }; int addedProdSupplierId = ProductSupplierDB.AddProductSupplier(ps); if (addedProdSupplierId != 0) { //refresh suppliers part of form SetUpFrmControls(); LoadProductSuppliers(currentProduct.ProductId); } else { MessageBox.Show("A problem occured adding this item to the database. Please try again."); } } else { MessageBox.Show("Please select a supplier from the drop-down list to add.", "Data entry error"); } }
public IActionResult Create([Bind("ProductID,ProductName,ProductDescription,ProductPrice")] Product product, int[] SelectedDepartments) { if (ModelState.IsValid) { _context.Add(product); _context.SaveChanges(); //add navigational data //find the course with the same course number as the one we just created Product dbProduct = _context.Products.FirstOrDefault(c => c.ProductID == product.ProductID); //loop through the selected departments foreach (int d in SelectedDepartments) { //find the department specified by the int Supplier supp = _context.Suppliers.Find(d); //create a new instance of the bridge table class ProductSupplier ps = new ProductSupplier(); ps.Product = dbProduct; ps.Supplier = supp; //add the new record to the database _context.ProductSuppliers.Add(ps); _context.SaveChanges(); } return(RedirectToAction(nameof(Index))); } //re-populate the Viewbag in case there is an error ViewBag.AllSuppliers = GetAllSuppliers(); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,SupplierID,ProductID")] ProductSupplier productSupplier) { if (id != productSupplier.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productSupplier); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductSupplierExists(productSupplier.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Product, "ID", "ID", productSupplier.ProductID); ViewData["SupplierID"] = new SelectList(_context.Supplier, "ID", "ID", productSupplier.SupplierID); return(View(productSupplier)); }
public async Task <bool> AddProductToSupplierAsync(int supplierID, int productID) { var supplier = await this.context.Suppliers .Include(s => s.Purchases) .Include(s => s.ProductsOfSupplier) .FirstOrDefaultAsync(x => x.SupplierID == supplierID) ?? throw new ArgumentException($"Can not find supplier with ID: {supplierID}."); if (supplier.ProductsOfSupplier == null) { supplier.ProductsOfSupplier = new List <ProductSupplier>(); } if (supplier.ProductsOfSupplier.Any(x => x.ProductID == productID)) { //return true; throw new ArgumentException($"Product with ID: {productID} already included for supplier with ID: {supplierID}."); } var product = (await this.context.Products.FindAsync(productID)) ?? throw new ArgumentException($"Can not find product with ID: {productID}."); var productSupplierToAdd = new ProductSupplier() { ProductID = productID, SupplierID = supplierID }; supplier.ProductsOfSupplier.Add(productSupplierToAdd); return((await this.context.SaveChangesAsync()) > 0 ? true : false); }
//clicks the button to remove one product from the suppliedProd listView private void btnRemoveSuppliedProd_Click(object sender, EventArgs e) { tabSupplierAccessMode = AccessMode.Edit; ProductSupplier removeSupProd = new ProductSupplier(); //get the selected Items ListView.SelectedListViewItemCollection selectedProds = lvSuppliedProds.SelectedItems; if (lvSuppliedProds.SelectedItems.Count > 0)//if there is selected item { //remove each product from the database foreach (ListViewItem item in selectedProds) { removeSupProd.ProductId = Convert.ToInt32(item.SubItems[0].Text); removeSupProd.SupplierId = Convert.ToInt32(txtSupplierId.Text); // delete the data from the Products_Suppliers table try { if (!(ProductSupplierDB.DeleteSupProd(removeSupProd))) { MessageBox.Show("Another user has updated or deleted that product.", "Database Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } refreshTabSuppliersListViews(); //refresh the ListViews } else { lblSupMessage.Text = "Note:Please select a product."; } }
public static void GetObjectListFromDB(out List <ProductSupplier> prodSup) { prodSup = new List <ProductSupplier>(); using (SqlConnection dbConnect = TravelExpertsDB.GetConnection()) { dbConnect.Open(); string query = "select * from products"; try { using (SqlCommand cmd = new SqlCommand(query, dbConnect)) { //run command and process results using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { ProductSupplier o = new ProductSupplier(); { ReadFromDB(reader, "ProductID", out int output); o.ProductID = output; } { ReadFromDB(reader, "ProductSupplierID", out int output); o.ProductSupplierID = output; } prodSup.Add(o); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } dbConnect.Close(); } }
//clicks the button to add one supplied product into the database and refresh the ListViews private void btnAddSuppliedProd_Click(object sender, EventArgs e) { tabSupplierAccessMode = AccessMode.Edit; ProductSupplier newSupProd = new ProductSupplier(); //get the selected Items ListView.SelectedListViewItemCollection selectedProds = lvUnsuppliedProducts.SelectedItems; if (lvUnsuppliedProducts.SelectedItems.Count > 0)//if there is selected item { //add the data of each item into the database foreach (ListViewItem item in selectedProds) { newSupProd.ProductId = Convert.ToInt32(item.SubItems[0].Text); newSupProd.SupplierId = Convert.ToInt32(txtSupplierId.Text); // add the data to the Products_Suppliers table and get the ProductsSupplierId try { newSupProd.ProductSupplierId = ProductSupplierDB.AddSupProd(newSupProd); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } refreshTabSuppliersListViews(); //refresh the ListViews } else { lblSupMessage.Text = "Note:Please select a product"; } }
public ProductSupplierDto(ProductSupplier product) : base(product) { if (product != null) { Quantity = product.Quantity; } }
void GetProduct(Backend.Objects.Product product = null) { product = product ?? Product; //Get if (product is object && User is object && Store is object) { lblProductName.Text = product.Name; lblProductId.Text = product.Id; lblProductPrice.Text = string.Format("{0} {1}", Store.CurrencySign, product.RetailPrice.ToString()); lblProductBarcode.Text = product.Barcode; lblCurrentStock.Text = product.Stock.ToString(); // If is from Search Item then Get Supplier .. Since the couldn't be fetched in another query if (product.IsSearchItem) { product.Supplier = ProductSupplier.GetSupplier(product.Supplier.Id); product.Image = Backend.Database.Queries.Product.GetImage(product.ImageBlobId, product.Name, product.Color); //Update Product = product; } imgProductImage.Image = product.Image; lblProductSupplier.Text = product.Supplier.Name; lblProductSupplyPrice.Text = product.SupplyPrice.ToString(); lblProductPrice.Text = product.RetailPrice.ToString(); } else { Alert.Show("Error", $"Something wrong occured", Alert.AlertType.Error); } }
/// <summary> /// Add a product to the package /// </summary> /// <param name="productId"></param> /// <param name="supplierId"></param> private void AddProductToPackage(int productId, int supplierId) { try { //get the productsupplier from db ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplier(productId, supplierId); //create the PPS to be added to db PackageProductSupplier newPackagePS = new PackageProductSupplier() { ProductSupplierId = productSupplier.ProductSupplierID, PackageId = PackageSelected.PackageId }; if (!PackageValidator.IsPackageProductSupplierExisting(newPackagePS)) { //add packageproductsupplier to db PackageProductSupplierDB.Add(newPackagePS); GetBindedPackageProducts(PackageSelected.PackageId); } } catch (Exception e) { MessageBox.Show(e.Message, "Unable to add product", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IActionResult AddSupplier(string supplierSKU, string supplierName, string supplierAddress, string supplierEmail, string[] productList, string supplierNote) { int lastInsertedId = 0; // Supplier entry Suppliers supplier = new Suppliers() { SupplierSku = supplierSKU, SupplierName = supplierName, SupplierAddress = supplierAddress, SupplierEmail = supplierEmail, SupplierNote = supplierNote }; _context.Suppliers.Add(supplier); _context.SaveChanges(); lastInsertedId = supplier.SupplierId; // Product_Supplier entry (one to many) for (int i = 0; i < productList.Length; i++) { ProductSupplier productSupplier = new ProductSupplier() { ProductId = int.Parse(productList[i]), SupplierId = lastInsertedId }; _context.ProductSupplier.Add(productSupplier); _context.SaveChanges(); } return(RedirectToAction("NewSupplier", "Supplier", new { status = "Success" })); }
public ActionResult DeleteConfirmed(int id) { ProductSupplier productSupplier = db.ProductSuppliers.Find(id); db.ProductSuppliers.Remove(productSupplier); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult updateInventory(FormCollection formcollection, string itemNumber, string reason, string sessionId) { if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true) { using (var db = new InventoryDbContext()) { ProductCatalogue a = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault(); ProductSupplier ps = db.productSuppliers.Where(x => x.itemNumber == a.itemNumber).FirstOrDefault(); int adjqty = int.Parse(formcollection[itemNumber + "-adjqty"]); if (adjqty < 0) { if (System.Math.Abs(adjqty) > a.quantity) { return(RedirectToAction("StockList", "Store", new { sessionId, msg = "*Quantity cannot diminish to less than 0.*" })); } else { Voucher v = new Voucher(); v.quantityAdjusted = adjqty; v.status = "Pending"; v.voucherDate = DateTime.Now; v.itemNumber = itemNumber; v.itemName = a.description; v.price = ps.price * System.Math.Abs(v.quantityAdjusted); v.reason = reason; db.vouchers.Add(v); } } ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == itemNumber).FirstOrDefault(); StockMovement sm = new StockMovement(); if (adjqty < 0) { sm.movementDescription = "Manual Stock Adjustment"; } else { sm.movementDescription = "Delivery from supplier"; } sm.movementDate = DateTime.Now; sm.movementQuantity = adjqty; sm.movementBalance = adjqty + pc.quantity; sm.itemNumber = itemNumber; db.stockmovements.AddOrUpdate(sm); db.SaveChanges(); a.quantity = a.quantity + adjqty; db.SaveChanges(); return(RedirectToAction("StockList", new { sessionId })); } } else { return(RedirectToAction("Login", "Login")); } }
public ActionResult GetPackageDetails(int id, int productNumber, int supplierNumber) { using (FreeMarketEntities db = new FreeMarketEntities()) { ProductSupplier product = db.ProductSuppliers.Find(productNumber, supplierNumber, id); return(PartialView("_CartViewProductModalPrice", product)); } }
public async Task <ActionResult> DeleteConfirmed(Guid id) { ProductSupplier productsSuppliers = await db.ProductsSuppliers.FindAsync(id); db.ProductsSuppliers.Remove(productsSuppliers); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Others2(string sessionId) { if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true) { using (var db = new InventoryDbContext()) { List <Requisition> req = new List <Requisition>(); req = db.requisitions.ToList(); List <Requisition> requ = new List <Requisition>(); List <Department> dp = new List <Department>(); dp = db.departments.ToList(); ProductCatalogue pc = new ProductCatalogue(); List <double> total = new List <double>(); List <string> department = new List <string>(); ProductSupplier ps = new ProductSupplier(); double totalprice = 0; foreach (var dps in dp) { foreach (var reqs in req) { if (dps.id == reqs.department) { if (reqs.status == "approved" || reqs.status == "partial") { if (reqs.datecompleted != null && reqs.datecompleted.Value.Month == DateTime.Now.AddMonths(-1).Month&& reqs.datecompleted.Value.Year == DateTime.Now.Year) { requ.Add(reqs); } } } } foreach (var requs in requ) { foreach (var productReq in requs.productReqs) { pc = db.productCatalogues.Where(x => x.itemNumber == productReq.productitemnumber).FirstOrDefault(); ps = db.productSuppliers.Where(x => x.itemNumber == productReq.productitemnumber && x.preference == 1).FirstOrDefault(); totalprice = totalprice + pc.quantity * ps.price;//I can't find the supplier in Requisition and ProductReq model, so i can't get the price, just add one temperory¡£ } } total.Add(totalprice); department.Add(dps.departmentName); } ViewData["total"] = total; ViewData["department"] = department; User user = db.users.Where(x => x.sessionId == sessionId).First(); ViewData["staffname"] = user.employee.empName; ViewData["sessionId"] = sessionId; return(View()); } } else { return(RedirectToAction("Login", "Login")); } }
internal static EntityProductSupplier Map(ProductSupplier entity) { return(new EntityProductSupplier { ProductSupplierId = entity.ProductSupplierId, ProductSupplierGuid = entity.ProductSupplierGuid, ProductId = entity.ProductId, SupplierId = entity.SupplierId }); }
void GetDropDownValues() { if (IsDropDownUpdated) { product.Supplier.Id = ProductSupplier.GetIdByName(dpdSupplier.selectedValue); product.Brand.Id = ProductBrand.GetIdByName(dpdProductBrand.selectedValue); product.Type.Id = ProductType.GetIdByName(dpdProductType.selectedValue); product.Tax.Id = Tax.GetIdByName(dpdTax.selectedValue); } }
public ActionResult Edit([Bind(Include = "Id,ProductId,SupplierId,Date,PurchasePrice,OrderAmount,CreateDate,CreatedBy,UpdateDate,UpdatedBy")] ProductSupplier productSupplier) { if (ModelState.IsValid) { db.Entry(productSupplier).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Products, "Id", "ProductName", productSupplier.ProductId); ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "SupplierName", productSupplier.SupplierId); return(View(productSupplier)); }
public IHttpActionResult DeleteSupplier(ProductSupplier productSupplierObj) { try { return(Ok(_productManager.DeleteSupplier(productSupplierObj))); } catch (Exception ex) { //LoggerEx.HandleException(LoggingBoundaries.DomainLayer, ex, false); return(BadRequest()); } }
public IActionResult Post([FromBody] ProductSupplier model) { try { uow.ProductSupplierRepo.Add(model); uow.SaveChanges(); return(Created("/api/ProductSupplier", model)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <ActionResult> Edit([Bind(Include = "ProductSupplierId,Price,ProductId,SupplierId")] ProductSupplier productsSuppliers) { if (ModelState.IsValid) { db.Entry(productsSuppliers).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Name", productsSuppliers.ProductId); ViewBag.SupplierId = new SelectList(db.Suppliers, "SupplierId", "Name", productsSuppliers.SupplierId); return(View(productsSuppliers)); }
public async Task <IActionResult> Create([Bind("ID,SupplierID,ProductID")] ProductSupplier productSupplier) { if (ModelState.IsValid) { _context.Add(productSupplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Product, "ID", "ID", productSupplier.ProductID); ViewData["SupplierID"] = new SelectList(_context.Supplier, "ID", "ID", productSupplier.SupplierID); return(View(productSupplier)); }
public IActionResult Put([FromBody] ProductSupplier model) { try { uow.ProductSupplierRepo.Update(model); uow.SaveChanges(); return(Created("/api/ProductSupplier", model)); } catch { return(StatusCode(500)); } }
// GET: Admin/ProductSuppliers/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductSupplier productSupplier = db.ProductSuppliers.Find(id); if (productSupplier == null) { return(HttpNotFound()); } return(View(productSupplier)); }
// GET: ProductsSuppliers/Details/5 public async Task <ActionResult> Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductSupplier productsSuppliers = await db.ProductsSuppliers.FindAsync(id); if (productsSuppliers == null) { return(HttpNotFound()); } return(View(productsSuppliers)); }
// GET: ProductSuppliers/Details/5 public ActionResult Details(int?pid, int?sid) { if (sid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductSupplier ProductSupplier = db.ProductSupplier.Find(pid, sid); if (ProductSupplier == null) { return(HttpNotFound()); } return(View(ProductSupplier)); }
// Function to popoulate data grid ProductSupplier with Products supplied by a specific supplier public static List<ProductSupplier> GetProdSupplier(int supplierId) { List<ProductSupplier> productsuppliers = new List<ProductSupplier>(); SqlConnection connection = TravelExpertsDB.GetConnection(); // Define the select query to retrieve data from multiple tables /*string query = "SELECT ProductSupplierId, Products_Suppliers.ProductId, Products_Suppliers.SupplierId, ProdName, SupName " + "from Products_Suppliers INNER JOIN Products on Products_Suppliers.ProductId = Products.ProductId " + "INNER JOIN Suppliers on Products_Suppliers.SupplierId = Suppliers.SupplierId "; */ //"WHERE ProductSupplierId > -1"; string query = "SELECT Products_Suppliers.ProductId, ProdName " + "FROM Products INNER JOIN Products_Suppliers on Products_Suppliers.ProductId = Products.ProductId " + "INNER JOIN Suppliers on Products_Suppliers.SupplierId = Suppliers.SupplierId " + "WHERE Suppliers.SupplierId = @SupplierId"; SqlCommand command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@SupplierId", supplierId); try { // Open db connection and run query connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Read dataset fill Packages list while (reader.Read()) { ProductSupplier productsupplier = new ProductSupplier(); //productsupplier.ProductSupplierId = (int)reader["ProductSupplierId"]; productsupplier.ProductId = (int)reader["ProductId"]; //productsupplier.SupplierId = (int)reader["SupplierId"]; productsupplier.ProdName = reader["ProdName"].ToString(); //productsupplier.SupName = reader["SupName"].ToString(); productsuppliers.Add(productsupplier); } return productsuppliers; } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static ProductSupplier GetProductSupplier(int psid) { SqlConnection connection = TravelExpertsDB.GetConnection(); string selectStatement = "SELECT ProductSupplierId, Products_Suppliers.ProductId, Products_Suppliers.SupplierId, ProdName, SupName " + "from Products_Suppliers INNER JOIN Products on Products_Suppliers.ProductId = Products.ProductId " + "INNER JOIN Suppliers on Products_Suppliers.SupplierId = Suppliers.SupplierId " + "WHERE ProductSupplierId = @ProductSupplierId "; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.Parameters.AddWithValue("@ProductSupplierId", psid); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { ProductSupplier productsupplier = new ProductSupplier(); productsupplier.ProductSupplierId = (int)reader["ProductSupplierId"]; productsupplier.ProductId = (int)reader["ProductId"]; productsupplier.SupplierId = (int)reader["SupplierId"]; productsupplier.ProdName = reader["ProdName"].ToString(); productsupplier.SupName = reader["SupName"].ToString(); return productsupplier; } else { return null; } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static List<int> GetProductSupplierIds() { List<int> productsupplierids = new List<int>(); SqlConnection connection = TravelExpertsDB.GetConnection(); string query = "SELECT ProductSupplierId FROM Products_Suppliers"; SqlCommand command = new SqlCommand(query, connection); try { // Open db connection and run query connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Read dataset fill Packages list while (reader.Read()) { ProductSupplier productsupplier = new ProductSupplier(); productsupplier.ProductSupplierId = (int)reader["ProductSupplierId"]; productsupplierids.Add(productsupplier.ProductSupplierId); } return productsupplierids; } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }