private static void CreateChair(ProductMaterial material, Color color, ProductSize size) { var factory = HomeAndKitchenFactory.GetConcreteFactory(material); var chair = factory.CreateChair(color, size); PrintProductDetails(chair.Color, chair.Material, chair.Size); }
/// <summary> /// Deletes an instance of Restriction from a Product's Material. /// </summary> /// <param name="deleteRestrictionFromProductMaterialMV">DeleteRestrictionFromProductMaterialModelView containing the Product's, the Materials's and the Restriction's persistence identifiers.</param> /// <exception cref="ResourceNotFoundException">Thrown when the Product, the Material or the Restriction could not be found.</exception> public void deleteRestrictionFromProductMaterial(DeleteProductMaterialRestrictionModelView deleteRestrictionFromProductMaterialMV) { ProductRepository productRepository = PersistenceContext.repositories().createProductRepository(); Product product = productRepository.find(deleteRestrictionFromProductMaterialMV.productId); if (product == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_PRODUCT_BY_ID, deleteRestrictionFromProductMaterialMV.productId)); } ProductMaterial productMaterial = product.productMaterials. Where(pm => pm.materialId == deleteRestrictionFromProductMaterialMV.materialId).SingleOrDefault(); if (productMaterial == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_MATERIAL_BY_ID, deleteRestrictionFromProductMaterialMV.materialId)); } Restriction restriction = productMaterial.restrictions.Where(r => r.Id == deleteRestrictionFromProductMaterialMV.restrictionId).SingleOrDefault(); if (restriction == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_RESTRICTION_BY_ID, deleteRestrictionFromProductMaterialMV.restrictionId)); } productMaterial.restrictions.Remove(restriction); product = productRepository.update(product); }
private static void CreateTable(ProductMaterial material, Color color, ProductSize size) { var factory = HomeAndKitchenFactory.GetConcreteFactory(material); var table = factory.CreateTable(color, size); PrintProductDetails(table.Color, table.Material, table.Size); }
public Sprite GetMaterialSprite(ProductMaterial material) { if (material == ProductMaterial.Wood) { return(MaterialIconSprites[0]); } if (material == ProductMaterial.Rubber) { return(MaterialIconSprites[1]); } if (material == ProductMaterial.Plastic) { return(MaterialIconSprites[2]); } if (material == ProductMaterial.Non_ferrous_metal) { return(MaterialIconSprites[3]); } if (material == ProductMaterial.Ferrous_metal) { return(MaterialIconSprites[4]); } return(null); }
/// <summary> /// Finds a Product's Material's Collection of Restriction. /// </summary> /// <param name="productMaterialModelView">GetProductMaterialModelView with the Product and Material persistence identifiers.</param> /// <returns>An instance of GetAllRestrictionsModelView containing the information of all the Materials's restrictions.</returns> /// <exception cref="ResourceNotFoundException">Thrown when either the Product or the Material could not be found.</exception> public GetAllRestrictionsModelView findMaterialRestrictions(FindProductMaterialModelView productMaterialModelView) { Product product = PersistenceContext.repositories().createProductRepository().find(productMaterialModelView.productId); if (product == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_PRODUCT_BY_ID, productMaterialModelView.productId)); } ProductMaterial productMaterial = product.productMaterials .Where(pm => pm.materialId == productMaterialModelView.materialId).SingleOrDefault(); if (productMaterial == null) { throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_MATERIAL_BY_ID, productMaterialModelView.materialId)); } //if no restrictions are found, throw an exception so that a 404 code is sent if (!productMaterial.restrictions.Any()) { throw new ResourceNotFoundException(ERROR_UNABLE_TO_FIND_RESTRICTIONS); } return(RestrictionModelViewService.fromCollection(productMaterial.restrictions)); }
public void ensureHasMaterialFails() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Assert.False(pm.hasMaterial(PREDEFINED_MATERIAL)); }
public void ensureGetProductWorks() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2, new List <Restriction>()); Assert.True(pm.product.Equals(p)); }
public void ensureHasMaterialSucceeds() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2, new List <Restriction>()); Assert.True(pm.hasMaterial(PREDEFINED_MATERIAL2)); }
public void ensureHasRestrictionReturnsFalseIfRestrictionIsNull() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Assert.False(pm.hasRestriction(null)); }
public (Color?newColor, ProductMaterial?newMaterial) OpenNewParameter() { if (Random.Range(0, 100) < 50 && _availableParameters.Colors.Count != _allParameters.Colors.Count) { Color newColor = _availableParameters.GetRandomColor(); while (_availableParameters.Colors.Contains(newColor)) { newColor = _allParameters.GetRandomColor(); } _availableParameters.MergeColors(new List <Color> { newColor }); return(newColor, null); } else if (_allParameters.Materials.Count != _allParameters.Materials.Count) { ProductMaterial newMaterial = ProductMaterial.None; while (newMaterial == ProductMaterial.None || _availableParameters.Materials.Contains(newMaterial)) { newMaterial = _allParameters.GetRandomMaterial(); } _availableParameters.MergeMaterials(new List <ProductMaterial>() { newMaterial }); return(null, newMaterial); } return(null, null); }
internal async Task <Product> RemoveProductMaterial(int id, int idm) { var product = await context.Product.FindAsync(id); var material = await context.Material.FindAsync(idm); ProductMaterial pms = null; if (product == null || material == null) { return(null); } foreach (ProductMaterial pm in product.ProductMaterials) { if (pm.MaterialId == idm) { pms = pm; } } if (pms == null) { return(null); } context.ProductMaterial.Remove(pms); await context.SaveChangesAsync(); return(product); }
public void ensureAddRestrictionThrowsExceptionIfRestrictionIsNull() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Action addNullRestrictionAction = () => pm.addRestriction(null); Assert.Throws <ArgumentException>(addNullRestrictionAction); }
public void ensureHasRestrictionrReturnsFalseIfRestrictionWasNotAdded() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Restriction rest = new Restriction("restriction", new SameMaterialAndFinishAlgorithm()); Assert.False(pm.hasRestriction(rest)); }
public IActionResult EditProductMaterialPost(ProductMaterial model) { if (ModelState.IsValid) { _workshopRepository.UpdateProductMaterial(model); return(RedirectToAction(nameof(Edit), new { id = model.WSProductId })); } return(View(nameof(EditProductMaterial), model)); }
public void ensureRemovingDuplicateRestrictionThrowsException() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Restriction rest = new Restriction("restriction", new SameMaterialAndFinishAlgorithm()); Action addNullRestrictionCreation = () => pm.removeRestriction(rest); Assert.Throws <ArgumentException>(addNullRestrictionCreation); }
/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> public void MaterialAdd(ProductMaterial entity) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); if (org != null) { entity.Org_ID = org.Org_ID; entity.Org_Name = org.Org_Name; } Gateway.Default.Save <ProductMaterial>(entity); }
public static HomeAndKitchenFactory GetConcreteFactory(ProductMaterial material) { switch (material) { case ProductMaterial.Wood: return(new WoodFactory()); case ProductMaterial.Metal: return(new MetalFactory()); default: throw new ArgumentException("Please provide a valid product material."); } }
public void initData(UnityProductModel model, ProductMaterial mat, string GameObjectName) { this.SwatchUrl = mat.swatchURL2x; gameObject.transform.name = GameObjectName; this.productMaterial = mat; this.unityProductModel = model; if ((model.activeUnityProductMaterial.name == mat.name) && (checkbox != null)) { checkbox.startsChecked = true; } }
public bool ProductMaterialExists(ProductMaterial productMaterial) { try { return(_ctx.ProductMaterials.Any(c => c.ProductMaterialName == productMaterial.ProductMaterialName && c.ProductMaterialId != productMaterial.ProductMaterialId)); } catch (Exception ex) { _logger.LogError($"Failed in ProductMaterialExists: {ex}"); return(false); } }
public void ensureAddRestrictionSucceeds() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Restriction rest = new Restriction("restriction", new SameMaterialAndFinishAlgorithm()); Action addValidRestrictionAction = () => pm.addRestriction(rest); Exception exception = Record.Exception(addValidRestrictionAction); Assert.Null(exception); Assert.True(pm.hasRestriction(rest)); }
public bool DelMaterialProductRelation(ProductMaterial pmr) { try { string sql = "DELETE FROM qiaotai.产品原料关系 WHERE 原料编号='" + pmr.MaterialId + "' AND 产品编号='" + pmr.ProductId + "';"; MySqlCommand cmd = new MySqlCommand(sql, this.Connection); this.Connection.Open(); cmd.ExecuteNonQuery(); this.Connection.Close(); return(true); } catch (Exception ex) { this.Connection.Close(); throw ex; } }
public bool AddMaterialProductRelation(ProductMaterial pmr) { try { string sql = "INSERT INTO qiaotai.产品原料关系(原料编号,产品编号,原料数量) VALUES ('" + pmr.MaterialId + "','" + pmr.ProductId + "','" + pmr.MaterialCount + "');"; MySqlCommand cmd = new MySqlCommand(sql, this.Connection); this.Connection.Open(); cmd.ExecuteNonQuery(); this.Connection.Close(); return(true); } catch (Exception ex) { this.Connection.Close(); throw ex; } }
public int AddMaterialToProduct(ProductMaterial model) { int result = -1; if (_dbContext.ProductMaterials .Where(pm => pm.WSMaterialId == model.WSMaterialId && pm.WSProductId == model.WSProductId).Count() > 0) { return(result); } _dbContext.ProductMaterials.Add(model); result = _dbContext.SaveChanges(); return(result); }
public bool SaveMaterial(ProductMaterial material) { try { _db.ProductMaterials.Add(material); _db.SaveChanges(); return(true); } catch { return(false); } }
public void ensureRemovePreviouslyAddedRestrictionDoesNotThrowException() { Product p = new Product("#666", "der alte würfelt nicht", "product666.glb", PREDEFEFINED_CATEGORY, PREDEFINED_MATERIALS, PREDEFINED_MEASUREMENTS); ProductMaterial pm = new ProductMaterial(p, PREDEFINED_MATERIAL2); Restriction rest = new Restriction("restriction", new SameMaterialAndFinishAlgorithm()); pm.addRestriction(rest); Action removeValidRestrictionAction = () => pm.removeRestriction(rest); Exception exception = Record.Exception(removeValidRestrictionAction); Assert.Null(exception); }
private void btnAdd_Click(object sender, EventArgs e) { Model.Material material = searchLookUpEdit1.EditValue as Model.Material; if (material == null) { return; } material.MaterialQuantity = Convert.ToInt32(txtQuantity.Text); material.ProductId = m_Product.ProductId; IList <Model.Material> lstMaterial = gridControl1.DataSource as IList <Model.Material>; ProductMaterial productmaterial = null; Model.Material exists = null; try { using (IUnitOfWork uow = new UnitOfWork()) { if (lstMaterial != null) { exists = lstMaterial.Where(p => p.MaterialId == material.MaterialId && p.ProductId == material.ProductId).FirstOrDefault(); } if (exists != null) { exists.MaterialQuantity += material.MaterialQuantity; productmaterial = new ProductMaterial(); productmaterial.ProductId = m_Product.ProductId; productmaterial.MaterialId = exists.MaterialId; productmaterial.MaterialQuantity = exists.MaterialQuantity; uow.MaterialRepository.UpdateProductMaterial(productmaterial); } else { productmaterial = new ProductMaterial(); productmaterial.ProductId = m_Product.ProductId; productmaterial.MaterialId = material.MaterialId; productmaterial.MaterialQuantity = material.MaterialQuantity; uow.MaterialRepository.AddProductMaterial(productmaterial); } uow.Commit(); } gridUtility.AddNewRow <Model.Material>(material); labelNotify1.SetText(UI.success, ToolBoxCS.LabelNotify.EnumStatus.Failed); } catch { labelNotify1.SetText(UI.failed, ToolBoxCS.LabelNotify.EnumStatus.Failed); } }
/// <summary> /// Converts an instance of ProductMaterial into an instance of GetBasicProductMaterialModelView. /// </summary> /// <param name="productMaterial">Instance of ProductMaterial.</param> /// <returns>Instance of GetBasicProductMaterialModelView.</returns> /// <exception cref="System.ArgumentException">Thrown when the provided instance of ProductMaterial is null.</exception> public static GetBasicProductMaterialModelView fromEntityAsBasic(ProductMaterial productMaterial) { if (productMaterial == null) { throw new ArgumentNullException(ERROR_NULL_PRODUCT_MATERIAL); } GetBasicProductMaterialModelView basicProductMaterialModelView = new GetBasicProductMaterialModelView(); basicProductMaterialModelView.id = productMaterial.materialId; basicProductMaterialModelView.reference = productMaterial.material.reference; basicProductMaterialModelView.designation = productMaterial.material.designation; basicProductMaterialModelView.imageFilename = productMaterial.material.image; return(basicProductMaterialModelView); }
public IActionResult AddMaterial([FromForm] ProductMaterial model) { if (ModelState.IsValid) { int isAdded = _workshopRepository.AddMaterialToProduct(model); return(RedirectToAction(nameof(Edit), new { id = model.WSProductId })); } ProductMaterialCreationViewModel model1 = new ProductMaterialCreationViewModel() { ProductMaterial = model, Materials = _workshopRepository.GetAllMaterials(), productId = model.WSProductId }; return(View(model1)); }
private void button4_Click(object sender, EventArgs e) { ProductMaterial pmt = new ProductMaterial(); pmt.MaterialId = textBox原料.Text; pmt.ProductId = textBox产品.Text; pmt.MaterialCount = Convert.ToInt16(textBox原料数量.Text); if (pm.DelMaterialProductRelation(pmt)) { MessageBox.Show("删除成功"); dataGrid产品原料关系.Rows.Remove(dataGrid产品原料关系.CurrentRow); } else { MessageBox.Show("删除失败!"); } }
public ProductMaterial CreateProductMaterial(ProductMaterial addressMaterial, int userId = -1) { try { var addressMaterialEntityEntry = _ctx.ProductMaterials.Add(addressMaterial); if (!Save(userId)) { return(null); } return(addressMaterialEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in CreateProductMaterial: {ex}"); return(null); } }
public void AddToProductMaterials(ProductMaterial productMaterial) { base.AddObject("ProductMaterials", productMaterial); }
public static ProductMaterial CreateProductMaterial(long materialID, int materialNameID, long productID) { ProductMaterial productMaterial = new ProductMaterial(); productMaterial.MaterialID = materialID; productMaterial.MaterialNameID = materialNameID; productMaterial.ProductID = productID; return productMaterial; }