// Método que actualiza productos private void button1_Click(object sender, EventArgs e) { if (ValidateFieldUpdate()) { Product product = new Product { ProductName = this.txtProductName.Text, ProductDescription = this.txtProductDescripcion.Text, ProductId = new Guid(this.lbId.Text), Price = Convert.ToDecimal(this.txtPrecioProducto.Text), Earns = Convert.ToDouble(this.txtEarns.Text), SubcategoryId = new Guid(this.comboProduct.SelectedValue.ToString()) }; bool isUpdated = BusinessProduct.UpdateProduct(product); if (isUpdated) { RefreshDataGridView(); CleanFields(); MessageBox.Show("Producto actualizado correctamente"); } else { MessageBox.Show("Ha ocurrido un error actualizando los campos del producto"); } } }
public void Product_Has_Been_Deleteded_Test() { var product = _context.Products.Where(x => x.ProductName == "test").FirstOrDefault(); var deleted = BusinessProduct.DeleteProduct(product.ProductId); Assert.AreEqual(deleted, true); }
// Método para insertar un producto private void btInsertProduct_Click(object sender, EventArgs e) { bool isValid = ValidateField(); if (isValid) { Product product = new Product { ProductName = this.txtInsertProduct.Text, ProductDescription = this.txtInsertPDescription.Text, ProductId = Guid.NewGuid(), Price = Convert.ToDecimal(this.txtInsertPrize.Text), Earns = Convert.ToDouble(this.txtInsertEarns.Text), SubcategoryId = new Guid(this.comboInsertSubcategory.SelectedValue.ToString()) }; bool hasBeenInserted = BusinessProduct.InsertProduct(product); if (hasBeenInserted) { RefreshDataGridView(); MessageBox.Show("Producto insertado correctamente"); this.txtInsertProduct.Text = String.Empty; this.txtInsertPDescription.Text = String.Empty; this.txtInsertPrize.Text = String.Empty; this.txtInsertEarns.Text = String.Empty; } else { MessageBox.Show("Error al insertar producto"); } } }
public void LinkProduct(int idConnector, string productName) { UnitOfWork repository = UnitOfWork.GetInstance(); Connector connector = repository.ConnectorRepository.GetById(idConnector); if (connector == null) { throw new ArgumentException("The connector isn't exist"); } if (connector.InUse) { throw new Exception("The connector is being used by other HomeDevice or product"); } Type product = BusinessProduct.GetProductType(productName); if (!connector.IsCapable(product)) { throw new Exception("The product is not capable with this connector"); } connector.LinkHomeDevice(product); repository.Commit(); }
public void TestBusinessLocationDecrementStock(int id, string address, string city, string zipcode, string state, int productId, string productName, decimal productPrice, int productStock) { BusinessLocation location = new BusinessLocation(); location.Id = id; location.Address = address; location.City = city; location.Zipcode = zipcode; location.State = state; BusinessProduct product = new BusinessProduct() { Id = productId, Name = productName, Price = productPrice }; location.AddProduct(product, productStock); int quantity = 1; location.DecrementStock(product, quantity); Assert.Equal(location.inventory[product], productStock - 1); }
public void TestBusinessLocationDecrementStockWhenProductNotInStock(int id, string address, string city, string zipcode, string state, int productId, string productName, decimal productPrice, int productStock) { BusinessLocation location = new BusinessLocation(); location.Id = id; location.Address = address; location.City = city; location.Zipcode = zipcode; location.State = state; BusinessProduct product = new BusinessProduct() { Id = productId, Name = productName, Price = productPrice }; location.AddProduct(product, productStock); BusinessProduct productNotInStock = new BusinessProduct() { Id = productId + 1, Name = productName + "a", Price = productPrice + 1 }; int quantity = 10; Assert.Throws <BusinessLocationException>(() => location.DecrementStock(productNotInStock, quantity)); }
public ActionResult ReturnBookImpl(string id, string customerId) { BusinessProduct.ReturnBook(id); RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); routeValueDictionary.Add("id", customerId); return(RedirectToAction("CustomerDetails", "Customer", routeValueDictionary)); }
public void Product_Has_Been_Updated_Test() { var product = _context.Products.Where(x => x.ProductName == "test").FirstOrDefault(); product.ProductDescription = "testUpdated"; var update = BusinessProduct.UpdateProduct(product); Assert.AreEqual(update, true); }
public bool CanModifyBalance(BusinessProduct businessProduct, decimal amount) { if (businessProduct != null) { return((amount >= businessProduct.MonthlyCyclePayment) ? true : false); } else { return(false); } }
public void Search_Product_Test() { string word = "t"; bool wordContais = false; var product = BusinessProduct.SearchProducts(word); if (product.Any()) { wordContais = true; } Assert.AreEqual(wordContais, true); }
//Método para Refrescar la información de la tabla private void RefreshDataGridView() { List <Product> products = BusinessProduct.GetAllProducts().ToList(); this.dtgridProduct.DataSource = products; for (int i = 0; i < dtgridProduct.Rows.Count; i++) { dtgridProduct.Rows[i].Cells["SubcategoryName"].Value = products[i].Subcategory.SubcategoryName; } DisabledFields(); }
public ActionResult LendBook() { if (!ModelState.IsValid) { return(View("LendBook")); } var model = new LendBookModel(); model.Products = BusinessProduct.GetProducts(); model.Contacts = BusinessContact.GetContacts(); return(View("LendBook", model)); }
public void TestBusinessProductSettersAndGetters(int id, string name, decimal price, int expectedId, string expectedName, decimal expectedPrice) { BusinessProduct product = new BusinessProduct(); product.Id = id; product.Name = name; product.Price = price; Assert.Equal(expectedId, product.Id); Assert.Equal(expectedName, product.Name); Assert.Equal(expectedPrice, product.Price); }
public ActionResult Index() { Products.Instance.Clear(); Products.Instance.AddRange(BusinessProduct.Load()); var model = new List <ProductViewModel>(); foreach (var p in Products.Instance) { model.Add(new ProductViewModel(p)); } return(View(model)); }
public ActionResult LendBook(LendBookModel e) { if (!ModelState.IsValid) { return(View("LendBook")); } BusinessProduct.LendBook(e.SelectedProductId, e.SelectedCustomerId); RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); routeValueDictionary.Add("id", e.SelectedCustomerId); return(RedirectToAction("CustomerDetails", "Customer", routeValueDictionary)); }
public ActionResult AddBook([Bind(Include = "Id,Name,Genre")] ProductEditModel e) { if (!ModelState.IsValid) { return(View("AddBook", e)); } var book = new ProductInstance { Product = new Products() }; book.UniqueId = GetRandom.String(); e.Update(book); BusinessProduct.SaveProductInstance(book); return(RedirectToAction("Index")); }
public ActionResult EditProduct([Bind(Include = "Id,Name,Genre")] ProductEditModel p) { if (!ModelState.IsValid) { return(View("EditProduct", p)); } var book = Products.Instance.Find(x => x.IsThisUniqueId(p.Id)); if (book == null) { return(HttpNotFound()); } p.Update(book); BusinessProduct.UpdateProductInstance(book); return(RedirectToAction("Index")); }
public void Update(BusinessProduct businessProduct, string userId) { try { var bProduct = _context.BusinessProduct.Include("PaymentCycleType").Include(e => e.BproductType).Where(x => x.PaccountId == businessProduct.PaccountId && x.UserId == userId).First(); bProduct.Balance = businessProduct.Balance; bProduct.MonthlyCyclePayment = businessProduct.MonthlyCyclePayment; bProduct.MinimumPayment = businessProduct.MinimumPayment; bProduct.CanBeModified = businessProduct.CanBeModified; _context.BusinessProduct.Update(bProduct); } catch (AppException ex) { throw new AppException("Product updation not successful", ex.Message); } }
public void Product_Has_Been_Inserted_Test() { var sub = _context.Products.FirstOrDefault(); Product product = new Product { ProductId = Guid.NewGuid(), Earns = 5.0, Price = 50, ProductDescription = "test!", ProductName = "test", Quantity = 1, SubcategoryId = sub.SubcategoryId }; var insert = BusinessProduct.InsertProduct(product); Assert.AreEqual(insert, true); }
public IEnumerable <ConnectorDTO> GetConnectorsCapableProduct(int idNode, string productName) { UnitOfWork repository = UnitOfWork.GetInstance(); Node node = repository.NodeRespository.GetById(idNode); if (node == null) { throw new ArgumentException("Node doesn't exist"); } Type product = BusinessProduct.GetProductType(productName); var connectors = node.Connectors.Where(c => !c.InUse && c.IsCapable(product)); return(Mapper.Map <IEnumerable <ConnectorDTO> >(connectors)); }
public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var book = Products.Instance.Find(x => x.IsThisUniqueId(id)); if (book == null) { return(HttpNotFound()); } if (book.Product != null) { BusinessProduct.DeleteProductInstance(book); } return(RedirectToAction("Index")); }
public BusinessProduct Create(BusinessProduct bProduct) { // validation if (bProduct == null) { throw new AppException("No Product"); } if (_context.UserAccount.Any(x => x.AccountId == bProduct.PaccountId)) { throw new AppException("AccountId \"" + bProduct.PaccountId + "\" is already taken"); } _context.BusinessProduct.Add(bProduct); _context.SaveChanges(); return(bProduct); }
// Método que añade producto a la lista private void AddProductoToList(object sender, DataGridViewCellEventArgs e) { var rows = this.dataGridView1.CurrentRow; if (rows == null) { return; } var product = BusinessProduct.GetProductById(new Guid(rows.Cells["ProductId"].Value.ToString())); if (_buys == null) { this._sells.AddProduct(product); } else { this._buys.AddProduct(product); } this.Hide(); }
/// <summary> /// Retrieves the product with the given id /// </summary> /// <param name="productId">The id of the product</param> /// <returns>The BusinessProduct with the given id</returns> public static BusinessProduct GetProductWithId(int productId) { Log.Information($"Called the Data Access method to get the product with product id {productId}"); using var context = new TThreeTeasContext(SQLOptions.options); Product product = context.Product.Where(p => p.Id == productId).FirstOrDefault(); if (product is null) { return(null); } BusinessProduct bProduct = new BusinessProduct() { Id = product.Id, Name = product.Name, Price = product.Price }; return(bProduct); }
/// <summary> /// Retrieves the BusinessOrder with the given order id /// </summary> /// <param name="orderId">The id of the order</param> /// <returns>The BusinessOrder object with the given order id</returns> public static BusinessOrder GetOrderWithId(int orderId) { Log.Information($"Called the Data Access method to get the order with order id {orderId}"); using var context = new TThreeTeasContext(SQLOptions.options); Orders order = context.Orders.FirstOrDefault(o => o.Id == orderId); if (order is null) { return(null); } BusinessLocation bLocation = LocationData.GetLocationWithId(order.LocationId); BusinessCustomer bCustomer = CustomerData.GetCustomerWithId(order.CustomerId); BusinessOrder bOrder = new BusinessOrder { Id = order.Id, StoreLocation = bLocation, Customer = bCustomer, OrderTime = order.OrderTime }; Dictionary <BusinessProduct, int> lineItems = new Dictionary <BusinessProduct, int>(); foreach (LineItem item in context.LineItem.Where(l => l.OrdersId == order.Id).ToList()) { Product product = context.Product.Where(p => p.Id == item.ProductId).FirstOrDefault(); BusinessProduct bProduct = new BusinessProduct() { Id = product.Id, Name = product.Name, Price = product.Price }; lineItems.Add(bProduct, item.Quantity); } bOrder.AddLineItems(lineItems); return(bOrder); }
public ActionResult CustomerDetails(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Contacts.Instance.Clear(); Contacts.Instance.AddRange(BusinessContact.Load()); var contact = Contacts.Instance.Find(x => x.IsThisUniqueId(id)); if (contact == null) { return(HttpNotFound()); } ContactDetailsModel model = new ContactDetailsModel(contact); model.LendedBooks = BusinessProduct.GetCustomerLendedBooks(id); if (contact.Contact != null) { return(View("CustomerDetails", model)); } return(View("Index")); }
public void TestBusinessLocationAddProduct(int id, string address, string city, string zipcode, string state, int productId, string productName, decimal productPrice, int productStock) { BusinessLocation location = new BusinessLocation(); location.Id = id; location.Address = address; location.City = city; location.Zipcode = zipcode; location.State = state; BusinessProduct product = new BusinessProduct() { Id = productId, Name = productName, Price = productPrice }; location.AddProduct(product, productStock); Assert.True(location.inventory.ContainsKey(product)); Assert.Equal(location.inventory[product], productStock); }
/// <summary> /// Retrieves the location with the given location id. /// </summary> /// <param name="locationId">The id of the location</param> /// <returns> /// The BusinessLocation object that maps to the location with the given location id /// </returns> public static BusinessLocation GetLocationWithId(int locationId) { Log.Information($"Called the Data Access method to get the location with location id {locationId}"); using var context = new TThreeTeasContext(SQLOptions.options); Location location = context.Location.Where(l => l.Id == locationId).FirstOrDefault(); if (location is null) { return(null); } BusinessLocation bLocation = new BusinessLocation() { Id = location.Id, Address = location.Address, City = location.City, Zipcode = location.Zipcode, State = location.State }; List <Inventory> inventories = context.Inventory.Where(i => i.LocationId == location.Id).ToList(); foreach (Inventory inventory in inventories) { Product product = context.Product.Where(p => p.Id == inventory.ProductId).FirstOrDefault(); BusinessProduct bProduct = new BusinessProduct() { Id = product.Id, Name = product.Name, Price = product.Price }; bLocation.AddProduct(bProduct, inventory.Stock); } return(bLocation); }
// Método que elimina un producto private void button3_Click(object sender, EventArgs e) { var rows = this.dtgridProduct.CurrentRow; if (rows != null) { var isDeleted = BusinessProduct.DeleteProduct(new Guid(rows.Cells["ProductId"].Value.ToString())); if (isDeleted) { RefreshDataGridView(); CleanFields(); MessageBox.Show("Producto borrado correctamente"); } else { MessageBox.Show("Error borrando producto"); } } else { MessageBox.Show("Debe seleccionar una fila que borrar"); } }
private void Stocks_Load(object sender, EventArgs e) { this.dataGridView1.DataSource = BusinessProduct.GetAllProducts().ToList(); }