private void BtnSaveOperation_Click(object sender, RoutedEventArgs e) { if (this.Id != 0) { OperationDto editOperation = new OperationDto() { Id = this.Id, IdAccount = ((ComboItem)cbAccount.SelectedItem).Id, IdOperationType = ((ComboItem)cbCategory.SelectedItem).Id, Date = (DateTime)datePicker.SelectedDate, Description = tbDescription.Text, }; if (decimal.TryParse(tbAmmount.Text, out decimal result)) { editOperation.Ammount = result; } else { MessageBox.Show("Please insert a valid number for the Ammount"); return; } _operationRepo.Update(editOperation); MessageBox.Show("Operation updated succesfully"); } else { OperationDto newOperationDto = new OperationDto() { IdAccount = ((ComboItem)cbAccount.SelectedItem).Id, IdOperationType = ((ComboItem)cbCategory.SelectedItem).Id, Date = (DateTime)datePicker.SelectedDate, Description = tbDescription.Text, }; if (decimal.TryParse(tbAmmount.Text, out decimal result)) { newOperationDto.Ammount = result; } else { MessageBox.Show("Please insert a valid number for the Ammount"); return; } _operationRepo.Add(newOperationDto); MessageBox.Show("Operation added succesfully"); } this.Close(); }
public async Task <ActionResult> Edit(OperationViewModel vm) { if (!ModelState.IsValid) { await AddAccountsAndCategories(vm); return(View(vm)); } OperationDto dto = Mapper.Map <OperationViewModel, OperationDto>(vm); if (vm.Id == 0) { await _operationRepo.Add(dto); } else { await _operationRepo.Update(dto); } return(RedirectToAction("Index")); }