private async void ExecuteAddItemCommand() { var errorList = ValidateInputParameters(); if (errorList.Count > 0) { MessageBox.Show("Error encountered in adding new item.\n" + string.Join(Environment.NewLine, errorList)); return; } var item = new ItemDbModel() { Barcode = Barcode, BrandName = BrandName, DosageForm = DosageForm, DosageStrength = DosageStrength, GenericName = GenericName, Manufacturer = Manufacturer, Price = (int)(UnitPrice * 100), TherapeuticClassId = SelectedTherapeuticClass.TherapeuticClassId }; var resultsChanged = await _itemProcessor.AddItem(item); if (resultsChanged == 0) { throw new Exception("Failed to add item"); } var newItem = (await _itemProcessor.GetItems(item.GenericName, item.BrandName, item.Manufacturer, item.Barcode, SelectedTherapeuticClass)).FirstOrDefault(); var inventoryItem = new InventoryDbModel() { ItemId = newItem.ItemId, BatchNumber = BatchNumber, LotNumber = LotNumber, ExpiryDate = ExpiryDate.Date, ManufacturingDate = ManufacturingDate.Date, Quantity = Quantity }; resultsChanged = await _inventoryProcessor.AddInventoryItem(inventoryItem); DisplayAddItemResult(resultsChanged > 0); InitializeValues(); }
public async Task <ActionResult> AddItem([FromBody] Items model) { var error = new List <Microsoft.AspNetCore.Mvc.ModelBinding.ModelError>(); if (ModelState.IsValid) { var data = await _itemProcessor.AddItem(_unitOfWork, model); _data = JsonConvert.SerializeObject(data); } else { error = ModelState.Where(a => a.Value.Errors.Count > 0).SelectMany(x => x.Value.Errors).ToList(); } _response = MultiPurpose.ReturnResponse(_data, error); return(Ok(_response)); }