public async Task <ActionResult <RepeatableExpense> > PostRepeatableExpense(RepeatableExpenseInputModel repeatableExpenseInput)
        {
            var user = await _context.Users.FindAsync(GetUserId());

            var repeatableExpense = new RepeatableExpense
            {
                ExpiryDate         = repeatableExpenseInput.ExpiryDate,
                daysToTrigger      = repeatableExpenseInput.FirstOccurence.HasValue ? (repeatableExpenseInput.FirstOccurence.GetValueOrDefault() - DateTime.Now).Days : repeatableExpenseInput.TimeToRepeatInDays,
                timeToRepeatInDays = repeatableExpenseInput.TimeToRepeatInDays,
                ExpenseData        = new ExpenseData
                {
                    Amount      = repeatableExpenseInput.Amount,
                    Description = repeatableExpenseInput.Description
                },
                User = user
            };

            _context.RepeatableExpenses.Add(repeatableExpense);
            await _context.SaveChangesAsync();

            if (!repeatableExpenseInput.FirstOccurence.HasValue)
            {
                var currentExpense = new CurrentExpense
                {
                    Date        = DateTime.Now,
                    User        = user,
                    ExpenseData = repeatableExpense.ExpenseData
                };
                _context.CurrentExpenses.Add(currentExpense);
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction("GetRepeatableExpense", new { id = repeatableExpense.Id }, repeatableExpense));
        }
Ejemplo n.º 2
0
        public void Save()
        {
            ExpenseItems expenseItems = new ExpenseItems
            {
                Expense_Id     = rand.Next(1, 100000),
                ExpenseName    = (string)ExpenseSourcePicker,
                ExpenseComment = ExpenseComent
            };

            var realm = Realm.GetInstance();



            CurrentExpense currentExpense = new CurrentExpense
            {
                CurrentExpense_Id = rand.Next(1, 100000),
                ExpenseDate       = System.DateTime.Now.ToString(),
                Expense           = expenseItems,
                ExpenseSum        = Convert.ToDouble(Sum)
            };

            if (tempId == 0)
            {
                realm.Write(() =>
                {
                    realm.Add(currentExpense);
                });
                currentExpense.PropertyChanged += (sender, e) =>
                {
                    Debug.WriteLine($"New value set for {e.PropertyName}");
                };
                ExpenseFundsVeiw.calculateSum = 0;
            }

            else
            {
                var tempDate = realm.All <CurrentExpense>().First(d => d.CurrentExpense_Id == tempId);
                realm.Write(() =>
                {
                    tempDate.ExpenseDate            = System.DateTime.Now.ToString();
                    tempDate.Expense                = expenseItems;
                    tempDate.ExpenseSum             = Convert.ToDouble(Sum);
                    tempDate.Expense.ExpenseName    = (string)ExpenseSourcePicker;
                    tempDate.Expense.ExpenseComment = ExpenseComent;
                });
                tempDate.PropertyChanged += (sender, e) =>
                {
                    Debug.WriteLine($"New value set for {e.PropertyName}");
                };
                ExpenseFundsVeiw.calculateSum = 0;
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CurrentExpense> > PostCurrentExpense(CurrentExpenseInputModel currentExpenseInput)
        {
            var user = await _context.Users.FindAsync(GetUserId());

            var currentExpense = new CurrentExpense
            {
                Date        = currentExpenseInput.Date,
                User        = user,
                ExpenseData = new ExpenseData
                {
                    Amount      = currentExpenseInput.Amount,
                    Description = currentExpenseInput.Description
                }
            };

            _context.CurrentExpenses.Add(currentExpense);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCurrentExpense", new { id = currentExpense.Id }, currentExpense));
        }