public ActionResult Edit(EditTapViewModel model) { if (!ModelState.IsValid) return View(model); var tap = _tapOrchestrator.GetTapById(model.Id); if (string.IsNullOrEmpty(model.KegId)) { if (tap.HasKeg) { _tapOrchestrator.RemoveKegFromTap(tap.Id); } } else if (!tap.HasKeg) { // Add New _tapOrchestrator.TapKeg(tap.Id, model.KegId); } else if(!tap.KegId.Equals(model.KegId)) { // Remove old, add new _tapOrchestrator.RemoveKegFromTap(tap.Id); _tapOrchestrator.TapKeg(tap.Id, model.KegId); } return RedirectToAction("Index"); }
public ActionResult Edit(string id) { var kegs = _kegOrchestrator.GetKegs(false).ToList(); var tap = _tapOrchestrator.GetTapById(id); var kegModels = kegs.Select(k => AutoMapper.Mapper.Map<Keg, KegModel>(k)).ToList(); foreach (var keg in kegs) { var beer = _beerOrchestrator.GetById(keg.BeerId); var km = kegModels.FirstOrDefault(k => k.Id == keg.Id); if (null != km) km.BeerName = beer.Name; } var vm = new EditTapViewModel(kegModels, tap.KegId); return View(vm); }