Esempio n. 1
0
        public IActionResult Post([FromBody] Dto.COperationInputDto itemDto)
        {
            try
            {
                if (null == itemDto)
                {
                    return(StatusCode(null, 400, "the request does not contain valid data"));
                }

                var item = new COperation {
                    operand1 = itemDto.operand1, operand2 = itemDto.operand2, action = itemDto.action
                };

                if (double.IsNaN(item.result))
                {
                    return(StatusCode(new Dto.CResultDto {
                        Result = item.result
                    }, 400, "the request does not contain valid data (incorrect mathematical operation?)"));
                }

                _oRepo.Add(item);
                // По ТЗ <<Result>> в данном ответе с заглавной
                return(StatusCode(new Dto.CResultDto {
                    Result = item.result
                }));                                                                            // 200 Ok
            }
            catch (Exception ex)
            {
                return(StatusCode(null, 500, "POST fail with exception", ex));
            }
        }
Esempio n. 2
0
        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"));
        }