//POST: api/Operation
        public async Task <IActionResult> AddNewOperation(OperationDTO model)
        {
            try
            {
                string userId = User.Claims.First(c => c.Type == "Id").Value;
                model.UserId = userId;

                await operationService.AddOperation(model);

                return(Ok());
            }
            catch (ArgumentOutOfRangeException)
            {
                return(BadRequest(ErrorMessages.InvalidProductAmount));
            }
            catch (ArgumentException)
            {
                return(BadRequest(ErrorMessages.AmountNotEnough));
            }
            catch
            {
                return(BadRequest(ErrorMessages.InvalidOperation));
            }
        }
 public async Task <IHttpActionResult> AddOperation()
 {
     return(Ok(await _operationService.AddOperation()));
 }
        private void Done_Button_Click(object sender, RoutedEventArgs e)
        {
            Operation operation = new Operation();

            try
            {
                foreach (var item in context.Categories)
                {
                    if (categoryName == item.Name)
                    {
                        operation.CategoryId = item.ID;
                    }
                }
                if (CardTabItem.IsSelected)
                {
                    operation.WayOfPayId = 1;
                    operation.Summ       = Double.Parse(tbSumm.Text);
                    operation.WayOfPayId = 1;
                    foreach (var item in context.Users)
                    {
                        if (item.Login == login && item.Password == password)
                        {
                            item.CardBalance -= Double.Parse(tbSumm.Text);
                        }
                    }
                    foreach (var item in context.Categories)
                    {
                        if (item.Name == categoryName)
                        {
                            item.Summ += Double.Parse(tbSumm.Text);
                        }
                    }
                }
                else
                {
                    operation.WayOfPayId = 0;
                    operation.Summ       = Double.Parse(tbSumm2.Text);
                    operation.WayOfPayId = 2;
                    foreach (var item in context.Users)
                    {
                        if (item.Login == login && item.Password == password)
                        {
                            item.CashBalance -= Double.Parse(tbSumm2.Text);
                        }
                    }
                    foreach (var item in context.Categories)
                    {
                        if (item.Name == categoryName)
                        {
                            item.Summ += Double.Parse(tbSumm2.Text);
                        }
                    }
                    int result = operationService.AddOperation(new OperationAddModel()
                    {
                        CategoryId = operation.CategoryId,
                        WayOfPayId = operation.WayOfPayId,
                        Summ       = operation.Summ

                                     // Покашо не зроблено IsProfit
                    });
                    context.SaveChanges();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }