public void Merge(Int32 materialIdToKeep, Int32[] materialIdToDelete) { foreach (var id in materialIdToDelete) { //Get all the ProductMaterial whith materialIdToDelete var _materialwithProductsDelete = _materialRepository.GetMaterialsWithProducts(id); var _productMaterialDelete = _materialwithProductsDelete.Select(p => p.ProductMaterials).ToList(); for (int i = 0; i < _productMaterialDelete.Count(); i++) { var collectionOfMaterial = _productMaterialDelete[i]; foreach (var prMaterial in collectionOfMaterial) { var _materialwithProductsToKeep = _materialRepository.GetMaterialsWithProducts(materialIdToKeep).FirstOrDefault(); var _actualProductMaterial = _materialwithProductsToKeep.ProductMaterials.FirstOrDefault(); //Need to update the quentity only and then delet the unused product details _actualProductMaterial.Quantity += prMaterial.Quantity; _materialRepository.UpdateProductMaterials(_actualProductMaterial); _materialRepository.DeleteProductMaterials(prMaterial.ProductMaterialId); _materialRepository.Delete(prMaterial.MaterialId); if (collectionOfMaterial.Count() <= 0) { break; } } } //} //Delete the Material (I would prefer to mark delte but this desing is like this so keep it as it is) } }
public IActionResult DeleteConfirmed(int id) { var material = materialsRepository.Get(id); materialsRepository.Delete(id); return(RedirectToAction("Index")); }
public void Delete(Guid materialId) { _unitOfWork.BeginTransaction(); _materialRepository.Delete(materialId); _unitOfWork.Commit(); }
public async Task <IActionResult> DeleteMaterial(int id) { if (await _repository.Exists(id)) { await _repository.Delete(id); return(Ok()); } return(NotFound()); }
public void DeleteMaterial(int materialId) { var material = materialRepository.GetById(materialId); if (material.Active == false) { return; //throw exception aqui !!! } materialRepository.Delete(material); }
public void DeleteMaterial(int MaterialID) { try { _materialRepository.Delete(MaterialID); } catch { } }
public ActionResult DeleteMaterial(MyEventsIdentity identity, int materialId) { var material = _materialRepository.Get(materialId); int sessionId = material.SessionId; _authorizationService.ValidateSessionAuthorization(identity, sessionId); _materialRepository.Delete(materialId); return(RedirectToAction("Materials", new { sessionId = sessionId })); }
public void Merge(Int32 materialIdToKeep, Int32 materialIdToDelete) { var entityToUpdate = _materialRepository.GetById(materialIdToKeep); foreach (var entity in entityToUpdate.ProductMaterials) { entity.MaterialId = materialIdToKeep; } _materialRepository.UpdateAssociated(materialIdToDelete, entityToUpdate.ProductMaterials); _materialRepository.Delete(materialIdToDelete); }
public bool Delete(string id) { try { var model = _materialRepository.GetMaterialById(id); _materialRepository.Delete(model); _materialRepository.Save(requestContext); return(true); } catch (Exception) { return(false); } }
// ============ Methods to REMOVE something ============ /** * Method that will soft-delete the material with the passed reference OR return all the errors found when trying to do so. * * Validations performed: * 1. Validation of the passed material's reference (database); */ public ValidationOutput Remove(string reference) { //1. ValidationOutput validationOutput = new ValidationOutputNotFound(); if (!MaterialExists(reference)) { validationOutput.AddError("Referece of material", "No material with the reference '" + reference + "' exists in the system."); return(validationOutput); } Material materialToRemove = _materialRepository.GetByReference(reference); _materialRepository.Delete(materialToRemove); return(validationOutput); }
public void Delete(int materialId) { try { var where = $"MATERIAL_ID = {materialId}"; if (string.IsNullOrEmpty(MetodosGenericosService.DlookupOrcamentaria("MATERIAL_ID", "T_ORCA_MATERIAL", where))) { throw new Exception(); } MaterialRepository.Delete(materialId); } catch (Exception) { throw; } }
/// <summary> /// please note that I have changed void return type to bool to tell user if its merged or not. /// </summary> /// <param name="materialIdToKeep"></param> /// <param name="materialIdToDelete"></param> /// <returns></returns> public bool Merge(Int32 materialIdToKeep, Int32 materialIdToDelete) { bool result = false; try { //here we are passing materialtoDelete to get products by materialtodelete ICollection <Data.Entities.ProductMaterial> productMaterialModelList = _materialRepository.GetProductsByMaterialId(materialIdToDelete); //writing logic here foreach (var item in productMaterialModelList) { //product material to update quantity Data.Entities.ProductMaterial productMaterial = _materialRepository.GetProductMaterialByProductIdMaterialId(item.ProductId, materialIdToKeep); if (productMaterial != null) { productMaterial.Quantity = productMaterial.Quantity + item.Quantity; result = _materialRepository.UpdateProductMaterial(productMaterial); if (!result) { return(false); } result = true; } //if different product then don't update quantity else { item.MaterialId = materialIdToKeep; result = _materialRepository.UpdateProductMaterial(item); } } //delete material _materialRepository.Delete(materialIdToDelete); } catch (Exception ex) { //log ex } return(result); }
public void Delete(MaterialId id) { repository.Delete(id); }
public void Delete(int id) { ValidateMaterialAuthorization(id); _materialRepository.Delete(id); }
public async Task <bool> Delete(int id) { return(await _repository.Delete(id)); }
public Material Delete(int id) { return(_materialRepository.Delete(id)); }
public void DeleteMaterial(Material model) { materialRepository.Delete(model); }