public async Task <IActionResult> Edit(int id, [Bind("Id,Withdraw,Date,UserId")] Spending spending)
        {
            if (id != spending.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(spending);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SpendingExists(spending.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", spending.UserId);
            return(View(spending));
        }
        public void given_two_payments_that_trigger_high_spending_verify_correct_message_set()
        {
            var mockDateTimeProvider = new MockIDateTimeProvider();
            var mockCurrentDate      = mockDateTimeProvider.ToReturn(new DateTime(2020, 04, 03));
            var currentDate          = mockDateTimeProvider.getDateTime();

            var payments = new List <Payment>
            {
                new Payment
                {
                    Id = 1,
                    TransactionDate = currentDate,
                    Category        = Category.Food,
                    Amount          = 200.00m,
                },

                new Payment
                {
                    Id = 1,
                    TransactionDate = new DateTime(2020, 03, 03),
                    Category        = Category.Food,
                    Amount          = 50.00m,
                }
            };

            var mockPaymentRepository = new MockPaymentRepository().WithThese(payments);
            var sendNotification      = new SendNotification();
            var spending = new Spending(mockPaymentRepository, new DetermineHighSpending(mockCurrentDate), sendNotification);

            spending.Trigger(1);

            var expectedMessage = "Hi, you spent $150.00 more on Food Category";

            Assert.Equal(expectedMessage, sendNotification.Message);
        }
Beispiel #3
0
 public async Task TestFinancialSummaryEmptyBillsEmptyApartments()
 {
     ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext();
     SummaryService summaryService = new SummaryService(context);
     Spending spending1 = new Spending { Amount = 100, Text = "beer1", IsPayed = true };
     Spending spending2 = new Spending { Amount = 200, Text = "beer2", IsPayed = true };
     Spending spending3 = new Spending { Amount = 300, Text = "beer3", IsPayed = false };
     Spending spending4 = new Spending { Amount = 400, Text = "beer4", IsPayed = false };
     await context.Spendings.AddAsync(spending1);
     await context.Spendings.AddAsync(spending2);
     await context.Spendings.AddAsync(spending3);
     await context.Spendings.AddAsync(spending4);
     await context.SaveChangesAsync();
     FinancialSummaryDTO output = summaryService.FinancialSummary();
     Assert.Empty(output.GoodHomeowners);
     Assert.Empty(output.BadHomeowners);
     Assert.Equal(2, output.PaidSpendings.Count);
     Assert.Equal(100, output.PaidSpendings[1].Amount);
     Assert.Equal("beer1", output.PaidSpendings[1].Text);
     Assert.Equal(200, output.PaidSpendings[0].Amount);
     Assert.Equal("beer2", output.PaidSpendings[0].Text);
     Assert.Equal(2, output.UnpaidSpendings.Count);
     Assert.Equal(300, output.UnpaidSpendings[1].Amount);
     Assert.Equal("beer3", output.UnpaidSpendings[1].Text);
     Assert.Equal(400, output.UnpaidSpendings[0].Amount);
     Assert.Equal("beer4", output.UnpaidSpendings[0].Text);
     Assert.Equal(0, output.Paid);
     Assert.Equal(0, output.ToBePaid);
     Assert.Equal(300, output.Spend);
     Assert.Equal(700, output.ToBeSpend);
     Assert.Equal(-1000, output.CurrentBalance);
 }
        private void dgvSpendings_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = int.Parse(dgvSpendings.CurrentRow.Cells[0].Value.ToString());

            if (e.ColumnIndex == 5)
            {
                if (MessageBox.Show($"¿Seguro que desea eliminar {dgvSpendings.CurrentRow.Cells[1].Value}?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    Spending model = db.Spendings.Where(x => x.SpendingID == id).FirstOrDefault();
                    var      entry = db.Entry(model);
                    if (entry.State == EntityState.Unchanged)
                    {
                        db.Spendings.Remove(model);
                        db.SaveChanges();
                        Filldgv();
                    }
                }
            }

            if (e.ColumnIndex == 4)
            {
                Spending model = db.Spendings.Where(x => x.SpendingID == id).FirstOrDefault();
                Visible = false;
                frmAddSpending edit = new frmAddSpending(model);
                edit.ShowDialog();
                Filldgv();
                Visible = true;
            }
        }
Beispiel #5
0
        public async Task <IActionResult> PutSpending(int id, Spending spending)
        {
            try
            {
                if (id != spending.Id)
                {
                    return(BadRequest());
                }

                if (await _repository.Update(spending) == null)
                {
                    return(BadRequest());
                }

                await _repository.UpdateBalance(spending.BalanceId);

                return(NoContent());
            }
            catch (Exception)
            {
                if (!_repository.Exist(id))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Beispiel #6
0
        public Spending Add(Spending spending)
        {
            Spending newSpending = _context.Spendings.Add(spending);

            _context.SaveChanges();
            return(newSpending);
        }
Beispiel #7
0
        private async void ExecuteSaveAsync()
        {
            if (NewSpending.Statement == null || NewSpending.Amount == null)
            {
                return;
            }
            DateTime dt = DateTime.Now;

            _newSpending.RegistrationDate = dt;
            _newSpending = _spendingServ.AddSpending(_newSpending);
            spendings.Add(_spendingServ.GetLastSpending());
            Safe _safe = new Safe
            {
                Amount           = -_newSpending.Amount,
                CanDelete        = false,
                Date             = _newSpending.Date,
                Statement        = _newSpending.Statement,
                RegistrationDate = dt,
                Source           = 2
            };

            _safeServ.AddSafe(_safe);
            _statementSuggestions.Add(_newSpending.Statement);
            NewSpending      = new Spending();
            NewSpending.Date = DateTime.Now;
            await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
            {
                AffirmativeButtonText = "موافق",
                DialogMessageFontSize = 25,
                DialogTitleFontSize   = 30
            });
        }
Beispiel #8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,BalanceId,Category,Description,Amount,Date")] Spending spending)
        {
            if (id != spending.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (await _repository.Update(spending) != null)
                    {
                        return(RedirectToAction(nameof(Details), "Balance", new { id = spending.BalanceId }, null));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_repository.SpendingExists(spending.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(spending));
        }
Beispiel #9
0
        public async Task <Spending> Add(Spending spending, int userId)
        {
            try
            {
                if (spending == null)
                {
                    return(null);
                }

                var category = await GetSpendingCategory(spending.Category.Id);

                if (category == null)
                {
                    return(null);
                }

                spending.UserId   = userId;
                spending.Category = category;

                await _context.AddAsync(spending);

                await _context.SaveChangesAsync();

                return(spending);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #10
0
        public async Task <Balance> GetParentBalance(int spendingId)
        {
            try
            {
                Spending spending = await Get(spendingId);

                if (spending == null)
                {
                    return(null);
                }

                Balance balance = await _balanceRepo.Get(spending.BalanceId);

                if (balance == null)
                {
                    return(null);
                }

                return(balance);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #11
0
        public async Task TestGetAllSpendingsGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            SpendingService spendingService = new SpendingService(context);
            Spending        spending1       = new Spending
            {
                Amount  = 10,
                Text    = "beer1",
                IsPayed = true
            };
            Spending spending2 = new Spending
            {
                Amount  = 20,
                Text    = "beer2",
                IsPayed = false
            };
            await context.Spendings.AddAsync(spending2);

            await context.Spendings.AddAsync(spending1);

            await context.SaveChangesAsync();

            List <SpendingDTO> output = spendingService.GetAllSpendings();

            Assert.Equal(2, output.Count);
            Assert.True(context.Spendings.Any(x => x.Id == spending1.Id));
            Assert.Equal(20, output[0].Amount);
            Assert.Equal("beer2", output[0].Text);
            Assert.False(output[0].IsPayed);
            Assert.True(context.Spendings.Any(x => x.Id == spending2.Id));
            Assert.Equal(10, output[1].Amount);
            Assert.Equal("beer1", output[1].Text);
            Assert.True(output[1].IsPayed);
        }
        public async Task <Spending> UpdateSpending(Spending _updateSpending)
        {
            var model = new Spending {
                Name = _updateSpending.Name, Type = _updateSpending.Type, SpendingId = _updateSpending.SpendingId
            };
            var sendJson = JsonSerializer.Serialize <Spending>(model, null);

            using (var client = new HttpClient())
            {
                HttpResponseMessage result = await client.PutAsync(_serverURL + "/api/SpendingsList" + "/" + model.SpendingId, new StringContent(sendJson, Encoding.UTF8, "application/json"));

                if (result.IsSuccessStatusCode)
                {
                    var temp = await result.Content.ReadAsStringAsync();

                    var response = JsonSerializer.Deserialize <Spending>(await result.Content.ReadAsStringAsync(),
                                                                         new JsonSerializerOptions
                    {
                        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    });
                    return(response);
                }
                return(null);
            }
        }
Beispiel #13
0
        private void RefreshBox()
        {
            //loops through the User.Goals linked array and adds each element to the list boxes(JE)
            Goal_ListBox.Items.Clear();
            Cost_ListBox.Items.Clear();
            Spending.Items.Clear();
            Spending.Refresh();

            decimal goalAdded = 0;

            foreach (Goal g in User.Goals)
            {
                goalAdded += g.EstimatedGoalCost;
            }

            Spending.Items.Add("Current budget: " + "$" + User.SpendingFunds.ToString());
            Spending.Items.Add("Total of all your goals added: " + "$" + goalAdded.ToString());


            decimal Total = (User.SpendingFunds - goalAdded);

            if (Total > 0)
            {
                Spending.Items.Add("You are overbudget by: " + "$" + Total);
            }
            else
            {
                Spending.Items.Add("You are underbudget by: " + "$" + Total);
            }
            sortList();
        }
Beispiel #14
0
        public async Task TestEditSpedningGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            SpendingService spendingService = new SpendingService(context);
            Spending        spending        = new Spending
            {
                Amount  = 10,
                Text    = "beer",
                IsPayed = true
            };
            await context.Spendings.AddAsync(spending);

            await context.SaveChangesAsync();

            SpendingDTO model = new SpendingDTO
            {
                Amount  = 100,
                Text    = "alot of beer",
                IsPayed = false,
                Id      = spending.Id
            };
            bool output = await spendingService.EditSpending(model);

            Assert.True(output);
            Assert.Equal(100, context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().Amount);
            Assert.Equal("alot of beer", context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().Text);
            Assert.False(context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().IsPayed);
        }
Beispiel #15
0
        public async Task <IActionResult> Edit(Spending spending)
        {
            _db.Spendings.Update(spending);
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #16
0
 private async void ShowAddMethod()
 {
     NewSpending      = new Spending();
     NewSpending.Date = DateTime.Now;
     _spendingAddDialog.DataContext = this;
     await _currentWindow.ShowMetroDialogAsync(_spendingAddDialog);
 }
Beispiel #17
0
 public void AddSpending(Spending spending)
 {
     using (SalesDB db = new SalesDB())
     {
         db.Spendings.Add(spending);
         db.SaveChanges();
     }
 }
        //ПОДУМАЙ КАК ОБЬЕДЕНИТЬ ЭТИ ДВА МЕТОДА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        /// <summary>
        /// Добавить расход.
        /// </summary>
        /// <param name="spendingName">Название расхода.</param>
        /// <param name="amount">Объем расхода.</param>
        /// <param name="category">Категория расхода.</param>
        /// <param name="comment">Комментарий к расходу.</param>
        public void AddSpending(string spendingName, double amount, string category, string comment)
        {
            var spending = new Spending(spendingName, amount, category, comment);

            Spendings.Add(spending);
            this.CurrentAccount.AccountBalance -= amount;
            SaveData(spending);
        }
Beispiel #19
0
 private static SpendingDTO SpendingToDTO(Spending spending) =>
 new SpendingDTO
 {
     Id          = spending.Id,
     Description = spending.Description,
     Price       = spending.Price,
     Rating      = spending.Rating,
 };
        private void SpendingButton_Click(object sender, RoutedEventArgs e)
        {
            ChangeForegroundColor(1);

            Spending page = new Spending();

            navigationFrame.NavigationService.Navigate(page);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Spending spending = db.Spendings.Find(id);

            db.Spendings.Remove(spending);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #22
0
        public static void Initialize(PensionHelpContext context)
        {
            context.Database.EnsureCreated();

            if (context.Savings.Any())
            {
                return;
            }

            var savings = new Saving[]
            {
                new Saving {
                    Description = "Car",
                    MaxGoal     = 4000,
                    CurrentGoal = 760
                },

                new Saving {
                    Description = "Pension",
                    MaxGoal     = 100000,
                    CurrentGoal = 20000
                },
            };

            foreach (Saving s in savings)
            {
                context.Savings.Add(s);
            }

            context.SaveChanges();

            if (context.Spendings.Any())
            {
                return;
            }

            var spendings = new Spending[]
            {
                new Spending {
                    Description = "Netflix",
                    Price       = 11,
                    Rating      = 4,
                },

                new Spending {
                    Description = "Disney+",
                    Price       = 7,
                    Rating      = 3,
                },
            };

            foreach (Spending s in spendings)
            {
                context.Spendings.Add(s);
            }

            context.SaveChanges();
        }
Beispiel #23
0
 public void DeleteSpending(Spending spending)
 {
     using (SalesDB db = new SalesDB())
     {
         db.Spendings.Attach(spending);
         db.Spendings.Remove(spending);
         db.SaveChanges();
     }
 }
        public async Task <IActionResult> Delete(int id)
        {
            Spending spending = await spendingRepository.Get(id).ConfigureAwait(true);

            spendingRepository.Remove(spending);
            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <SpendingForGetDTO>(spending)));
        }
Beispiel #25
0
        public void Spendings_Repository_GetById_ShouldBeOk()
        {
            //Action
            Spending spendingResult = _repository.GetById(_spendingSeed.Id);

            //Assert
            spendingResult.Should().NotBeNull();
            spendingResult.Should().Be(_spendingSeed);
        }
Beispiel #26
0
        public void Spendings_Repository_GetById_ShouldThrowNotFoundException()
        {
            //Action
            int      notFoundId     = 10;
            Spending spendingResult = _repository.GetById(notFoundId);

            //Assert
            spendingResult.Should().BeNull();
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Spending spending = await db.Spendings.FindAsync(id);

            db.Spendings.Remove(spending);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #28
0
        public async Task <Domain.Entity.Spending> Insert(Domain.Entity.Spending spendingToAdd)
        {
            Spending dBSpending           = spendingToAdd.ToDb();
            EntityEntry <Spending> result = await _applicationDbContext.Spendings.AddAsync(dBSpending);

            await _applicationDbContext.SaveChangesAsync();

            return(result.Entity.ToEntity());
        }
 public async Task <IActionResult> AddSpending([FromBody] Spending input)
 {
     return(await SendCommandAsync(new AddSpending(
                                       PeriodId.From(input.PeriodId),
                                       Amount.From(input.Amount),
                                       Label.From(input.Label),
                                       Pair.From(input.Pair),
                                       SpendingCategory.From(input.Category))));
 }
Beispiel #30
0
 public Spending AddSpending(Spending spending)
 {
     using (SalesDB db = new SalesDB())
     {
         spending = db.Spendings.Add(spending);
         db.SaveChanges();
         return(spending);
     }
 }