private void AddCookiesFromCupboard() { var viewModel = new AddCookiesFromCupboardDialogViewModel(); var result = _dialogService.ShowDialog(this, viewModel); if (!result.HasValue || !result.Value) { return; } var dto = new AddCookiesFromCupboardDto() { DateReceived = viewModel.DateReceived, DoSiSos = viewModel.DoSiSos, Savannah = viewModel.Savannah, Samoas = viewModel.Samoas, Smors = viewModel.Smors, Tagalongs = viewModel.Tagalongs, ThinMints = viewModel.ThinMints, ToffeeTastic = viewModel.ToffeeTastic, Trefoils = viewModel.Trefoils, TroopInventoryId = Id }; _api.AddCookiesFromCupboard(dto); var inventory = _api.GetTroopInventoryById(Id); UpdateInventory(inventory); }
//TODO refactor to take view model and id public void AddCookiesFromCupboard(AddCookiesFromCupboardDto data) { using (var uow = UnitOfWork) { IEnumerable <CookieQuantity> cookies = new[] { new CookieQuantity(data.DoSiSos, Cookie.DosiSo), new CookieQuantity(data.Samoas, Cookie.Samoas), new CookieQuantity(data.Savannah, Cookie.Savannah), new CookieQuantity(data.Smors, Cookie.Smors), new CookieQuantity(data.Tagalongs, Cookie.Tagalongs), new CookieQuantity(data.ThinMints, Cookie.ThinMints), new CookieQuantity(data.ToffeeTastic, Cookie.ToffeeTastic), new CookieQuantity(data.Trefoils, Cookie.Trefoils), }; DateTime dateReceived = data.DateReceived; int troopInventoryId = data.TroopInventoryId; var command = new AddCookiesFromCupboardCommand(cookies, dateReceived, troopInventoryId); var handler = new AddCookiesFromCupboardCommandHandler(uow); var result = handler.Handle(command); } }