public void RemoveItemFromDb(object ingredient) { ActiveIngredient activeIngredient = ingredient as ActiveIngredient; Ingredients.Remove(activeIngredient); addDrugM.Ingredients.Remove(activeIngredient); }
public void DeleteActiveIngredient(ActiveIngredient active) { using (var db = new DrConsoleDB()) { db.Entry(active).State = EntityState.Deleted; db.SaveChanges(); } }
public void AddActiveIngredient(ActiveIngredient active) { using (var db = new DrConsoleDB()) { db.ActiveIngredientsDB.Add(active); db.SaveChanges(); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void AddIngredientToDrug() { IngredientToAdd.DrugIdCode = Drug.IdCode; Ingredients.Add(IngredientToAdd); addDrugM.Ingredients.Add(IngredientToAdd); IngredientToAdd = new ActiveIngredient(); }
internal void RemoveIngredient(ActiveIngredient activeIngredient) { try { bl.DeleteActiveIngredient(activeIngredient); } catch (ArgumentException) { throw; } catch (Exception ex) { throw; } }
internal void AddIngredient(ActiveIngredient ingredientToAdd) { try { bl.AddActiveIngredient(ingredientToAdd); } catch (ArgumentException) { throw; } catch (Exception ex) { throw; } }
public void DeleteActiveIngredient(ActiveIngredient ingredient) { try { dal.DeleteActiveIngredient(ingredient); } catch (ArgumentException) { throw; } catch (Exception ex) { throw; } }
internal bool UpdateItem() { string fullName = EditorDetails.FullName; string shortName = EditorDetails.ShortName; double inventoryAmount = EditorDetails.InventoryAmount; MeasurementUnit unit = EditorDetails.MeasurementUnit; double costPerUnit = EditorDetails.CostPerUnit; double? parQuantity = EditorDetails.ParQuantity; // Is there an ActiveItem? if (ActiveIngredient == null) { ActiveIngredient = Ingredient.Add(fullName, shortName, inventoryAmount, unit, costPerUnit, parQuantity); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } else { if (Math.Abs(ActiveIngredient.InventoryAmount - inventoryAmount) > double.Epsilon) { double originalAmount = UnitConversion.Convert(ActiveIngredient.InventoryAmount, ActiveIngredient.MeasurementUnit, unit); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, originalAmount, inventoryAmount, unit); } if (ActiveIngredient.MeasurementUnit != unit) { IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id, -1, -1, ActiveIngredient.MeasurementUnit, (int)unit); } if (EditorDetails.IsAdjustedByRecipe) { ProcessInventoryChangesForPrepIngredients( ActiveIngredient.InventoryAmount, inventoryAmount); } // Update the category values for the ActiveItem ActiveIngredient.SetFullName(fullName); ActiveIngredient.SetShortName(shortName); ActiveIngredient.SetInventoryAmount(inventoryAmount); ActiveIngredient.SetMeasurementUnit(unit); ActiveIngredient.SetCostPerUnit(costPerUnit); ActiveIngredient.SetParQuantity(parQuantity); // Update the database ActiveIngredient.Update(); EditorPreparation.Update(ActiveIngredient.Id); ActiveIngredient = Ingredient.Get(ActiveIngredient.Id); } return(true); }
public ActiveIngredient GetActiveIngredientById(int id, string lang) { ActiveIngredient activeingredient = databasePlaceholder.Get(id, lang); if (activeingredient == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(activeingredient); }
public void AddIngredientToDrug() { try { Ingredients.Add(IngredientToAdd); updateDrugM.AddIngredient(IngredientToAdd); IngredientToAdd = new ActiveIngredient(); } catch (ArgumentException ex) { containingVm.ShowMessage(ex.Message); } catch (Exception ex) { containingVm.ShowMessage(ex.Message); } }
public void RemoveItemFromDb(object ingredient) { ActiveIngredient activeIngredient = ingredient as ActiveIngredient; try { Ingredients.Remove(activeIngredient); updateDrugM.RemoveIngredient(activeIngredient); } catch (ArgumentException ex) { containingVm.ShowMessage(ex.Message); } catch (Exception ex) { containingVm.ShowMessage(ex.Message); } }
private void InitializeFields() { int oldCount = listBoxItemIngredients.Items.Count; listBoxAvailableIngredients.Items.Clear(); listBoxItemIngredients.Items.Clear(); List <Ingredient> ingredients = new List <Ingredient>(Ingredient.GetAll()); if (ActiveIngredient != null) { foreach (IngredientSet setIngredient in IngredientSet.GetAll(ActiveIngredient.Id)) { bool added, changed, removed; IngredientSet current = GetIngredientSet(setIngredient.Id, out added, out changed, out removed); if (!removed) { Ingredient ingredient = Ingredient.Find(ingredients, setIngredient.IngredientId); AddIngredientSetToListBox( (changed ? current : setIngredient), ingredient); ingredients.Remove(ingredient); } } } // Note: Added ones have an ExtendedIngredientId of zero so GetAll (above) will not find them foreach (IngredientSet setIngredient in _ingredientSetsAdded) { Ingredient ingredient = Ingredient.Find(ingredients, setIngredient.IngredientId); AddIngredientSetToListBox(setIngredient, ingredient); ingredients.Remove(ingredient); } if (ActiveIngredient != null) { foreach (Ingredient ingredient in ingredients) { if ((ingredient.Id == ActiveIngredient.Id) || ActiveIngredient.ContainsIngredient(ingredient.Id)) { continue; } listBoxAvailableIngredients.Items.Add( new FormattedListBoxItem(ingredient.Id, ingredient.FullName, true)); } } SetReadOnly(); SetupButtons(); ProcessEvents(oldCount); }
public AddDrugViewModel(AdminShellViewModel containingVm) { addDrugM = new AddDrugModel(); this.containingVm = containingVm; UpdateDbCommand = new AddToDbCommand(this); IsNewDrug = true; BackCommand = new BackCommand(this); IngredientToAdd = new ActiveIngredient(); Ingredients = new ObservableCollection <ActiveIngredient>(); AddIngredientCommand = new AddIngredientToDrugCommand(this); DeleteIngredientCommand = new DeleteItemCommand(this); FileDialogCommand = new OpenFileDialogCommand(this); }
public UpdateDrugViewModel(AdminShellViewModel containingVm, Drug drugToUpdate) { updateDrugM = new UpdateDrugModel(drugToUpdate); this.containingVm = containingVm; UpdateDbCommand = new UpdateInDbCommand(this); IsNewDrug = false; BackCommand = new BackCommand(this); IngredientToAdd = new ActiveIngredient(); Ingredients = new ObservableCollection <ActiveIngredient>(updateDrugM.Ingredients); AddIngredientCommand = new AddIngredientToDrugCommand(this); DeleteIngredientCommand = new DeleteItemCommand(this); FileDialogCommand = new OpenFileDialogCommand(this); ImageUrl = Drug.ImageUrl; }
private Ingredient LoadProductRelation(XmlNode productRelationNode, ProductMix productMix) { var productId = productRelationNode.GetXmlNodeValue("@A"); var productQuantity = productRelationNode.GetXmlNodeValue("@B"); if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(productQuantity)) { return(null); } long quantity; if (!long.TryParse(productQuantity, NumberStyles.Integer, CultureInfo.InvariantCulture, out quantity) || quantity < 0) { return(null); } Product product; if (_taskDocument.Products.TryGetValue(productId, out product) == false) { return(null); } var unit = _taskDocument.UnitsByItemId.FindById(productId); var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity)); var ingredient = new ActiveIngredient { Description = product.Description, }; var productComponent = new ProductComponent { IngredientId = product.Id.ReferenceId, Quantity = new NumericRepresentationValue(null, numericValue.UnitOfMeasure, numericValue) }; if (productMix.ProductComponents == null) { productMix.ProductComponents = new List <ProductComponent>(); } productMix.ProductComponents.Add(productComponent); return(ingredient); }
public void DeleteActiveIngredient(ActiveIngredient ingredient) { try { if (ctx.ActiveIngredients.Find(ingredient.ID) == null) { throw new ArgumentException("Active Ingredient not exists"); } ctx.ActiveIngredients.Remove(ctx.ActiveIngredients.Find(ingredient.ID)); ctx.SaveChanges(); } catch (ArgumentException) { throw; } catch (Exception ex) { throw new Exception("Error - Delete Active Ingredient "); } }
public void AddActiveIngredient(ActiveIngredient ingredient) { try { if (ctx.ActiveIngredients.Find(ingredient.ID) != null) { throw new ArgumentException("Active Ingredient Already exists"); } ctx.ActiveIngredients.Add(ingredient); ctx.SaveChanges(); } catch (ArgumentException) { throw; } catch (Exception ex) { throw new Exception("Error add Active Ingredient"); } }
private async Task UpdateActiveIngredientsDB() { await Task.Run(() => { XmlReader reader = XmlTextReader.Create("ActiveIngerdient/ActiveIngrdedientsDB.xml"); List <ActiveIngredient> xmls = new List <ActiveIngredient>(); int num = 0; while (!reader.EOF && num <= 30) { if (reader.Name != "minConcept") { reader.ReadToFollowing("minConcept"); } if (!reader.EOF) { XElement xml = (XElement)XElement.ReadFrom(reader); ActiveIngredient item = new ActiveIngredient() { Name = (string)xml.Element("name"), Rxcui = (string)xml.Element("rxcui") }; try { AddActiveIngredient(item); num++; } catch { } } } //System.Xml.XmlDocument root = new System.Xml.XmlDocument(); //root.Load("ActiveIngerdient/ActiveIngrdedientsDB.xml"); //string content = root.InnerXml; //XmlNodeList nodes = root.DocumentElement.SelectNodes("/minConceptGroup/minConcept"); //foreach (XmlNode node in nodes) //{ // String name = node.SelectSingleNode("name").InnerText; // String rxcui = node.SelectSingleNode("rxcui").InnerText; // AddActiveIngredient(new ActiveIngredient(name, rxcui)); //} }); }
public ActionResult CreateIngredient(string model) { var ingredientFromDb = _uow.ActiveIngredientRepository.Get(s => s.Name == model) .FirstOrDefault(); if (ingredientFromDb != null) { return(BadRequest("Such ingredient already exists")); } var ingredient = new ActiveIngredient { Name = model }; _uow.ActiveIngredientRepository.Add(ingredient); if (_uow.Complete()) { return(Ok()); } return(BadRequest("Problem creating Ingredient")); }
public Product ImportProduct(ISOProduct isoProduct) { //First check if we've already created a matching seed product from the crop type Product product = DataModel.Catalog.Products.FirstOrDefault(p => p.ProductType == ProductTypeEnum.Variety && p.Description == isoProduct.ProductDesignator); //If not, create a new product if (product == null) { //Type switch (isoProduct.ProductType) { case ISOProductType.Mixture: case ISOProductType.TemporaryMixture: product = new MixProduct(); product.ProductType = ProductTypeEnum.Mix; break; default: product = new GenericProduct(); product.ProductType = ProductTypeEnum.Generic; break; } } //ID if (!ImportIDs(product.Id, isoProduct.ProductId)) { //Replace the CVT id with the PDT id in the mapping TaskDataMapper.InstanceIDMap.ReplaceISOID(product.Id.ReferenceId, isoProduct.ProductId); } //Description product.Description = isoProduct.ProductDesignator; //Mixes if (isoProduct.ProductRelations.Any()) { if (product.ProductComponents == null) { product.ProductComponents = new List <ProductComponent>(); } foreach (ISOProductRelation prn in isoProduct.ProductRelations) { //Find the product referenced by the relation ISOProduct isoComponent = ISOTaskData.ChildElements.OfType <ISOProduct>().FirstOrDefault(p => p.ProductId == prn.ProductIdRef); //Find or create the active ingredient to match the component Ingredient ingredient = DataModel.Catalog.Ingredients.FirstOrDefault(i => i.Id.FindIsoId() == isoComponent.ProductId); if (ingredient == null) { ingredient = new ActiveIngredient(); ingredient.Description = isoComponent.ProductDesignator; DataModel.Catalog.Ingredients.Add(ingredient); } //Create a component for this ingredient ProductComponent component = new ProductComponent() { IngredientId = ingredient.Id.ReferenceId }; if (!string.IsNullOrEmpty(isoComponent.QuantityDDI)) { component.Quantity = prn.QuantityValue.AsNumericRepresentationValue(isoComponent.QuantityDDI, RepresentationMapper); } product.ProductComponents.Add(component); } //Total Mix quantity if (isoProduct.MixtureRecipeQuantity.HasValue) { MixProduct mixProduct = product as MixProduct; mixProduct.TotalQuantity = isoProduct.MixtureRecipeQuantity.Value.AsNumericRepresentationValue(isoProduct.QuantityDDI, RepresentationMapper); } } //Density if (isoProduct.DensityMassPerCount.HasValue) { product.Density = isoProduct.DensityMassPerCount.Value.AsNumericRepresentationValue("007A", RepresentationMapper); } else if (isoProduct.DensityMassPerVolume.HasValue) { product.Density = isoProduct.DensityMassPerVolume.Value.AsNumericRepresentationValue("0079", RepresentationMapper); } else if (isoProduct.DensityVolumePerCount.HasValue) { product.Density = isoProduct.DensityVolumePerCount.Value.AsNumericRepresentationValue("007B", RepresentationMapper); } return(product); }