Ejemplo n.º 1
0
        public async Task <JsonResult> Create([FromBody] Movement movement)
        {
            movement.DateAdded = DateTime.Now;
            _context.Add(movement);
            await _context.SaveChangesAsync();

            return(Json(new { success = true }));
        }
Ejemplo n.º 2
0
        public async Task <JsonResult> Create([FromBody] Category category)
        {
            _context.Add(category);
            await _context.SaveChangesAsync();

            return(Json(new { success = true }));
        }
        public async Task <JsonResult> Create([FromBody] RecurringMovement recurringMovement)
        {
            try
            {
                Category rCategory = recurringMovement.Category;
                recurringMovement.Category = null;
                _context.Add(recurringMovement);
                await _context.SaveChangesAsync();

                if (rCategory != null)
                {
                    Category   category = _context.Categories.First(c => c.CategoryID == rCategory.CategoryID);
                    IQueryable toUpdate = _context.RecurringMovements.Where(m => m.Description == recurringMovement.Description && m.Amount == recurringMovement.Amount);
                    foreach (RecurringMovement movement in toUpdate)
                    {
                        movement.Category = category;
                        _context.Update(movement);
                    }
                    await _context.SaveChangesAsync();
                }

                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, error = e.Message }));
            }
        }
        public async Task <IActionResult> Create([Bind("ExpenseId,UserId,MortgageRent,Phone,Gas,WaterSewerTrash,Electricity,CableInternet,HomeAlarmSystem,MaintenanceRepairs,VehiclePayment,Insurance,Fuel,UberLyft,LicenseRegistration,Maintenance,HomeRenters,Health,Dental,Vision,Pet,Life,Groceries,DiningOut,Coffee,ClothesShoes,SchoolTuitionSupplies,SportsOrganizationFees,Childcare,LunchMoney,ToysGames,HairCutsSalon,ManiPediWaxing,ClothesShoesAccessories,DryCleaning,GymSupplements,OrganizationDuesFees,Music,Video,MovieTheater,Concerts,SportingEvents,DateNights,Alchohol,TobaccoVaping,PersonalLoan,CreditCard,StudentLoan,Federal,State,Medicare,SocialSecurityFICA,EmergencySavings,CDsMoneyMarkets,IRA401k,StocksMutualFunds,Tithesffering,Charity,RetirementHome,Attorney,AlimonyChildSupport,LienJudgmentPayment,MonthlyIncome,TotalCost,IncomeVsTotal")] Expenses expenses)
        {
            if (ModelState.IsValid)
            {
                expenses.UserId    = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                expenses.TotalCost = expenses.MortgageRent + expenses.Phone + expenses.Gas + expenses.WaterSewerTrash +
                                     expenses.Electricity + expenses.CableInternet +
                                     expenses.HomeAlarmSystem + expenses.MaintenanceRepairs + expenses.VehiclePayment + expenses.Insurance +
                                     expenses.Fuel + expenses.UberLyft + expenses.LicenseRegistration + expenses.Maintenance +
                                     expenses.HomeRenters + expenses.Health + expenses.Dental + expenses.Vision + expenses.Pet +
                                     expenses.Life + expenses.Groceries + expenses.DiningOut +
                                     expenses.Coffee + expenses.ClothesShoes + expenses.SchoolTuitionSupplies +
                                     expenses.SportsOrganizationFees + expenses.Childcare +
                                     expenses.LunchMoney + expenses.ToysGames + expenses.HairCutsSalon + expenses.ManiPediWaxing +
                                     expenses.ClothesShoesAccessories +
                                     expenses.DryCleaning + expenses.GymSupplements + expenses.OrganizationDuesFees + expenses.Music +
                                     expenses.Video + expenses.MovieTheater +
                                     expenses.Concerts + expenses.SportingEvents + expenses.DateNights + expenses.Alchohol +
                                     expenses.TobaccoVaping + expenses.PersonalLoan + expenses.CreditCard +
                                     expenses.StudentLoan + expenses.Federal + expenses.State + expenses.Medicare +
                                     expenses.SocialSecurityFICA + expenses.EmergencySavings + expenses.CDsMoneyMarkets +
                                     expenses.IRA401k + expenses.StocksMutualFunds + expenses.Tithesffering + expenses.Charity +
                                     expenses.RetirementHome + expenses.Attorney +
                                     expenses.AlimonyChildSupport + expenses.LienJudgmentPayment;
                expenses.IncomeVsTotal = expenses.MonthlyIncome - expenses.TotalCost;
                _context.Add(expenses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", expenses.UserId);
            return(View(expenses));
        }
Ejemplo n.º 5
0
        public async Task Will_List_Categories_SecondPage()
        {
            // arrange
            using (var context = new BudgetContext(_options))
            {
                context.Add(new Category()
                {
                    Id = Guid.NewGuid(), Label = "1"
                });
                context.Add(new Category()
                {
                    Id = Guid.NewGuid(), Label = "2"
                });
                context.Add(new Category()
                {
                    Id = Guid.NewGuid(), Label = "3", IsArchived = true
                });
                context.Add(new Category()
                {
                    Id = Guid.NewGuid(), Label = "4"
                });
                await context.SaveChangesAsync();
            }

            var query = new CategoryListQuery()
            {
                PerPage    = 2,
                Page       = 1,
                OrderBy    = nameof(Category.Label),
                Descending = true
            };

            using (var context = new BudgetContext(_options))
            {
                // act
                var service = new CategoryService(context, _mapper);
                var result  = await service.Handle(query, CancellationToken.None);

                Assert.IsFalse(result.IsEmpty);
                Assert.AreEqual(3, result.TotalResults);
                Assert.AreEqual(1, result.Results.Count());
                Assert.AreEqual(2, result.TotalPages);

                Assert.AreEqual("1", result.Results.ElementAt(0).Label);
            }
        }
        public async Task <IActionResult> Create([Bind("PaymentMethodId,PaymentMethodName")] PaymentMethod paymentMethod)
        {
            if (ModelState.IsValid)
            {
                _context.Add(paymentMethod);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(paymentMethod));
        }
        public async Task <IActionResult> Create([Bind("CatId,CategoryName")] ExpenseCategory expenseCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(expenseCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(expenseCategory));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("SubcatId,SubcatName,CatId")] Subcat subcat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subcat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CatId"] = new SelectList(_context.ExpenseCategories, "CatId", "CategoryName", subcat.CatId);
            return(View(subcat));
        }
        public async Task <IActionResult> Create([Bind("PurchaseId,CatId,PurchaseName,Price,PaymentMethodId,Note,Necessity,PurchaseDate, UserId")] Purchase purchase)
        {
            if (ModelState.IsValid)
            {
                purchase.UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                _context.Add(purchase);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CatId"]           = new SelectList(_context.ExpenseCategories, "CatId", "CategoryName", purchase.CatId);
            ViewData["PaymentMethodId"] = new SelectList(_context.PaymentMethods, "PaymentMethodId", "PaymentMethodName", purchase.PaymentMethodId);
            return(View(purchase));
        }
Ejemplo n.º 10
0
        public async Task Add(Income income)
        {
            income.ClientId = _userAccessor.GetId();
            income.Source   = await _sourceResolver.Resolve(income.Source.Name);

            _context.Add(income);
            await _context.SaveChangesAsync();

            var clientSource = await _clientSourceResolver.Resolve(income.ClientId, income.Source.Id);

            if (clientSource != null)
            {
                _context.ClientSources.Add(clientSource);
                await _context.SaveChangesAsync();
            }
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("SubcatId,ActualCost,Difference,UserId,CatId,Id")] List <MonthlyCost> monthlyCost)
        {
            for (int i = 0; i < monthlyCost.Count(); i++)
            {
                if (ModelState.IsValid)
                {
                    monthlyCost[i].UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                    _context.Add(monthlyCost);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Create)));
                }
            }



            //ViewData["SubcatId"] = new SelectList(_context.Subcats, "SubcatId", "SubcatName", monthlyCostSubcatId);
            //ViewData["CatId"] = new SelectList(_context.ExpenseCategories, "CatId", "CategoryName", monthlyCost.CatId);
            return(RedirectToAction("Create"));
        }
Ejemplo n.º 12
0
 public void Add(T entity)
 {
     _context.Add(entity);
 }