public async Task <ActionResult> Delete(OperationTypeViewModel vm)
        {
            OperationTypeDto toDelete = Mapper.Map <OperationTypeViewModel, OperationTypeDto>(vm);
            await _operationTypeRepo.Delete(toDelete.Id);

            return(RedirectToAction("Index"));
        }
        private void BtnSaveCategory_Click(object sender, RoutedEventArgs e)
        {
            OperationTypeDto operationTypeDto = new OperationTypeDto();

            operationTypeDto.Name = tbCategoryName.Text;
            if (rbExpense.IsChecked == true)
            {
                operationTypeDto.IsCredit = false;
            }
            if (rbIncome.IsChecked == true)
            {
                operationTypeDto.IsCredit = true;
            }

            if (Id == null)
            {
                _operationTypeRepo.Add(operationTypeDto);
            }
            else
            {
                operationTypeDto.Id = Id.Value;
                _operationTypeRepo.Update(operationTypeDto);
            }

            this.Close();
        }
        public async Task <ActionResult> Details(int?id)
        {
            if (id != null)
            {
                OperationTypeDto toGet = await _operationTypeRepo.Get(id.Value);

                if (toGet != null)
                {
                    OperationTypeViewModel vm = Mapper.Map <OperationTypeDto, OperationTypeViewModel>(toGet);
                    return(View(vm));
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        private void BtnDeleteCategory_Click(object sender, RoutedEventArgs e)
        {
            OperationTypeDto category = GetClickedCategory(sender);

            try
            {
                _operationTypeRepo.Delete(category.Id);
            }
            catch
            {
                MessageBox.Show("Unable to delete category. It has been used for other transactions");
            }

            InitializeCategories();
        }
Exemplo n.º 5
0
        private OperationTypeDto GetClickedCategory(object sender)
        {
            //get button parent until we reach the user control (Editable Item Control)
            DependencyObject ucParent = ((Button)sender).Parent;

            while (!(ucParent is UserControl))
            {
                ucParent = LogicalTreeHelper.GetParent(ucParent);
            }

            // cast to specific type from UserControl
            EditableItemControl userControl = (EditableItemControl)ucParent;

            //Get from Db the account with the id of the UserControl
            OperationTypeDto category = _operationTypeRepo.Get(userControl.Id);

            return(category);
        }
        public async Task <ActionResult> Edit(OperationTypeViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            OperationTypeDto dto = Mapper.Map <OperationTypeViewModel, OperationTypeDto>(vm);

            if (vm.Id == 0)
            {
                await _operationTypeRepo.Add(dto);
            }
            else
            {
                await _operationTypeRepo.Update(dto);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        private void BtnEditCategory_Click(object sender, RoutedEventArgs e)
        {
            OperationTypeDto category = GetClickedCategory(sender);

            CategoryWindow categoryWindow = new CategoryWindow();

            categoryWindow.Id = category.Id;
            categoryWindow.tbCategoryName.Text = category.Name;

            if (category.IsCredit)
            {
                categoryWindow.rbIncome.IsChecked = true;
            }
            else
            {
                categoryWindow.rbExpense.IsChecked = true;
            }

            categoryWindow.Show();
            categoryWindow.Closing += CategoryWindow_Closing;
        }