public Operation GetItemFromTransferItem(OperationTransfer operationTransfer) { if (operationTransfer != null) { var operation = new Operation() { Id = operationTransfer.Id }; operation.CurrentTypeOperation = new TypeOperation() { Id = operationTransfer.CurrentTypeOperation.Id }; operation.TreatmentId = operationTransfer.TreatmentId; if (operationTransfer.Medicines.Any()) { operation.Medicines = new List <Medicine>(); foreach (var id in operationTransfer.Medicines) { var medicine = medicineService.GetItemById(id); operation.Medicines.Add(medicine); } } return(operation); } else { throw new ArgumentException("The tranfer object is null"); } }
public OperationTransfer GetTransferItemById(int id) { var operation = GetItemById(id); if (operation != null) { var currentMedicines = new List <int>(); if (operation.Medicines != null && operation.Medicines.Any()) { currentMedicines = operation.Medicines.Select(x => x.Id).ToList(); } var operationTransfer = new OperationTransfer() { Id = operation.Id, CurrentTypeOperation = operation.CurrentTypeOperation, TreatmentId = operation.TreatmentId, Medicines = currentMedicines }; return(operationTransfer); } else { throw new ArgumentException("The operation object is null"); } }
public ContentResult Update(OperationTransfer operationTransfer) { try { var operation = operationService.GetItemFromTransferItem(operationTransfer); operationService.Update(operation); operationService.Save(); return(Content("<p>The operation was updated successfully!</p>")); } catch (ArgumentException e) { return(Content($"<p>The operation wasn't updated! {e.Message}</p>")); } catch (Exception e) { return(Content($"<p>{e.Message}</p>")); } }
public ContentResult CreateOperation(OperationTransfer operationTransfer) { var operation = new Operation(); operation.CurrentTypeOperation = new TypeOperation() { Id = operationTransfer.CurrentTypeOperation.Id }; operation.TreatmentId = operationTransfer.TreatmentId; if (operationTransfer.Medicines.Any()) { operation.Medicines = new List <Medicine>(); foreach (var id in operationTransfer.Medicines) { var medicine = medicineService.GetItemById(id); operation.Medicines.Add(medicine); } } operationService.Add(operation); operationService.Save(); return(Content("<p>The operation was created successfully!</p>")); }