private OperationDto GetClickedOperation(object sender) { DependencyObject parent = ((Button)sender).Parent; while (!(parent is EditableTransactionControl)) { parent = LogicalTreeHelper.GetParent(parent); } int opId = ((EditableTransactionControl)parent).IdOperation; OperationDto operationDto = _operationRepo.Get(opId); return(operationDto); ////get button parent until we reach the user control (Editable Transaction Control) //DependencyObject ucParent = ((Button)sender).Parent; //while (!(ucParent is UserControl)) //{ // ucParent = LogicalTreeHelper.GetParent(ucParent); //} //// cast to specific type from UserControl //EditableTransactionControl userControl = (EditableTransactionControl)ucParent; ////Get from Db the account with the id of the UserControl //OperationDto operationDto = _operationRepo.Get(userControl.IdOperation); //return operationDto; }
public async Task <ActionResult> Edit(int?id) { OperationViewModel vm = new OperationViewModel(); if (id != null) { OperationDto toEdit = await _operationRepo.Get(id.Value); if (toEdit != null) { vm = Mapper.Map <OperationDto, OperationViewModel>(toEdit); } } await AddAccountsAndCategories(vm); return(View(vm)); }