Esempio n. 1
0
        public async Task <IActionResult> Create()
        {
            var categories = await _expenseDbContext.Categories.ToListAsync();

            var tags = await _expenseDbContext.Tags.ToListAsync();

            var expense = new ExpenseCreateViewModel
            {
                Date       = DateTime.Now,
                Categories = categories.Select(item =>
                                               new SelectListItem
                {
                    Value = item.Id.ToString(),
                    Text  = item.Description,
                }),
                Tags = tags.Select(item =>
                                   new SelectListItem
                {
                    Value = item.Id.ToString(),
                    Text  = item.Name,
                })
            };

            return(View(expense));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(ExpenseCreateViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var expense = new Expense
            {
                Description = vm.Description,
                Date        = vm.Date,
                Amount      = vm.Amount,
                CategoryId  = vm.SelectedCategory,
                ExpenseTags = vm.SelectedTags.Select(id => new ExpenseTag {
                    TagId = id
                }).ToList(),
                ExpenseAppUserId = userId
            };

            if (vm.File != null)
            {
                expense.PhotoPath = _photoService.AddPhoto(vm.File);
            }

            await _expenseDbContext.AddAsync(expense);

            await _expenseDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public HttpResponseMessage AddExpense(ExpenseCreateViewModel model)
        {
            var resp = new HttpResponseMessage();

            if (model.Expense != null)
            {
                try
                {
                    this.usersService.SaveExpense(model.Email, model.Expense);
                }
                catch
                {
                    resp.Content = new StringContent(JsonConvert.SerializeObject(new { Status = "0" }));
                    resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    return(resp);
                }

                resp.Content = new StringContent(JsonConvert.SerializeObject(new { Status = "1" }));
                resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                return(resp);
            }

            resp.Content = new StringContent(JsonConvert.SerializeObject(new { Status = "0" }));
            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(resp);
        }
Esempio n. 4
0
        public async Task <IActionResult> Create()
        {
            ExpenseCreateViewModel vm = new ExpenseCreateViewModel();

            var paidStatuses = await _expenseDbContext.PaidStatuses.ToListAsync();

            foreach (PaidStatus paidStatus in paidStatuses)
            {
                vm.PaidStatuses.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Value = paidStatus.Id.ToString(),
                    Text  = paidStatus.Name
                });
            }

            var persons = await _expenseDbContext.Persons.ToListAsync();

            vm.Persons = persons.Select(person => new SelectListItem()
            {
                Value = person.Id.ToString(), Text = person.Name
            }).ToList
                             ();

            return(View(vm));
        }
        public IActionResult Create(ExpenseCreateViewModel expense)
        {
            if (!TryValidateModel(expense))
            {
                return(View(expense));
            }

            Expense newExpense = new Expense
            {
                Omschrijving = expense.Omschrijving,
                Categorie    = expense.Categorie,
                Bedrag       = expense.Bedrag,
                Datum        = expense.Datum
            };

            if (expense.Photo != null)
            {
                string uniqueFileName = UploadPhoto(expense.Photo);

                newExpense.PhotoUrl = "/expense-pics/" + uniqueFileName;
            }

            _expenseDatabase.Insert(newExpense);
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 6
0
        public IActionResult NewExpense()
        {
            var ExpenseCreateVM = new ExpenseCreateViewModel {
            };

            return(PartialView("_newExpensePartial", ExpenseCreateVM));
        }
Esempio n. 7
0
        public ExpenseCreatePage()
        {
            InitializeComponent();

            BindingContext = new ExpenseCreateViewModel(new ExpenseTrackerWebApiClientService());

            this.EntryDate.Date  = DateTime.Now.Date;
            this.EntryValue.Text = string.Empty;
        }
Esempio n. 8
0
        public IActionResult NewExpense([Bind("Subject, Value, IsCovered, ExpenseCategory, GroupId, ParticipantIds, ParticipantsCharge, DidParticipantsPay")] ExpenseCreateViewModel ecvm)
        {
            //TODO:check validation after adding it
            if (ModelState.IsValid)
            {
                //TODO: change to currentuserId
                var currentUserId = 1;

                bool isCovered = ecvm.IsCovered ? true : ecvm.DidParticipantsPay.All(pc => pc == true);

                var totalExpense = new TotalExpense
                {
                    Covered          = isCovered,
                    FinalizationDate = DateTime.Now,
                    OwnerId          = currentUserId,
                    ExpenseCategory  = ecvm.ExpenseCategory,
                    Subject          = ecvm.Subject,
                    Value            = ecvm.Value
                };

                _context.TotalExpenses.Add(totalExpense);
                _context.SaveChanges();

                var partialExpenses = new List <PartialExpense>();

                for (int i = 0; i < ecvm.ParticipantIds.Length; i++)
                {
                    partialExpenses.Add(new PartialExpense
                    {
                        Covered        = ecvm.DidParticipantsPay[i],
                        SettlementDate = ecvm.DidParticipantsPay[i] ? DateTime.Now : (DateTime?)null,
                        TeamId         = ecvm.GroupId,
                        TotalExpenseId = totalExpense.Id,
                        UserId         = ecvm.ParticipantIds[i],
                        Value          = ecvm.ParticipantsCharge[i]
                    });
                }

                _context.PartialExpenses.AddRange(partialExpenses);
                _context.SaveChanges();

                return(RedirectToAction("Index", "BudgetManager", new { id = currentUserId }));
            }

            return(PartialView("_newExpensePartial", ecvm));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create()
        {
            ExpenseCreateViewModel vm = new ExpenseCreateViewModel();

            vm.Date = DateTime.Now;
            var categories = await _dbContext.Categories.ToListAsync();

            foreach (Category category in categories)
            {
                vm.Category.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }
            return(View(vm));
        }
Esempio n. 10
0
        public IActionResult Create([FromForm] ExpenseCreateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View());
            }

            _expenseService.Create(new ExpenseDto
            {
                Omschrijving = model.Omschrijving,
                Bedrag       = model.Bedrag,
                Datum        = model.Datum,
                Categorie    = model.Categorie
            });

            return(RedirectToAction(nameof(List)));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create(ExpenseCreateViewModel expense)
        {
            if (!TryValidateModel(expense))
            {
                var paidStatuses = await _expenseDbContext.PaidStatuses.ToListAsync();

                foreach (PaidStatus paidStatus in paidStatuses)
                {
                    expense.PaidStatuses.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                    {
                        Value = paidStatus.Id.ToString(),
                        Text  = paidStatus.Name
                    });
                }
                return(View(expense));
            }

            Expense newExpense = new Expense()
            {
                Omschrijving   = expense.Omschrijving,
                Datum          = expense.Datum,
                Bedrag         = expense.Bedrag,
                Categorie      = expense.Categorie,
                PaidStatusId   = expense.SelectedPaidStatus,
                PersonExpenses = expense.SelectedPersons.Select(person => new PersonExpense()
                {
                    PersonId = person
                }).ToList(),
                UserId = User.FindFirstValue(ClaimTypes.NameIdentifier)
            };

            if (expense.Photo != null)
            {
                string uniqueFileName = UploadExpensePhoto(expense.Photo);
                newExpense.PhotoUrl = "/photos/" + uniqueFileName;
            }

            _expenseDbContext.Expenses.Add(newExpense);
            await _expenseDbContext.SaveChangesAsync();


            return(RedirectToAction("Index"));
        }
        public IActionResult Create([FromForm] ExpenseCreateViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            var newExpense = new ExpenseDto
            {
                Description = vm.Description,
                Date        = vm.Date,
                Value       = vm.Value,
                Categorie   = vm.Categorie
            };

            if (vm.Photo != null)
            {
                newExpense.PhotoUrl = _photoService.UploadPhoto(vm.Photo);
            }

            _expensesService.Create(newExpense);
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 13
0
        public IActionResult Create(ExpenseCreateViewModel NewExpense)
        {
            List <ExpenseProduct> products = new List <ExpenseProduct>();

            foreach (var productId in NewExpense.SelectedProductId)
            {
                products.Add(new ExpenseProduct()
                {
                    ProductId = productId
                });
            }
            _expenseDatabase.Expenses.Add(new Expense
            {
                Amount          = NewExpense.Amount,
                Date            = NewExpense.Date,
                Description     = NewExpense.Description,
                Category        = NewExpense.Category,
                PaymentStatusId = NewExpense.PaymentStatusId,
                ExpenseProducts = products,
                UserId          = User.FindFirstValue(ClaimTypes.NameIdentifier)
            });
            _expenseDatabase.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create()
        {
            ExpenseCreateViewModel NewExpense = new ExpenseCreateViewModel();

            IEnumerable <PaymentStatus> paymentStatusus = await _expenseDatabase.paymentStatuses.ToListAsync();

            foreach (var Status in paymentStatusus)
            {
                NewExpense.PaymentStatusus.Add(new SelectListItem()
                {
                    Text = Status.Status, Value = Status.Id.ToString()
                });
            }
            IEnumerable <Product> expenseProducts = await _expenseDatabase.Products.ToListAsync();

            foreach (var Product in expenseProducts)
            {
                NewExpense.Products.Add(new SelectListItem()
                {
                    Text = Product.Name, Value = Product.Id.ToString()
                });
            }
            return(View(NewExpense));
        }
Esempio n. 15
0
        public async Task <IActionResult> Create(ExpenseCreateViewModel cvm)
        {
            Expense newExpense = new Expense()
            {
                Amount        = cvm.Amount,
                CategoryId    = cvm.CategoryId,
                Description   = cvm.Description,
                Date          = cvm.Date,
                PhotoUrl      = cvm.PhotoUrl,
                ExpenseUserId = User.FindFirstValue(ClaimTypes.NameIdentifier)
            };

            newExpense.Category = await _dbContext.Categories.FirstOrDefaultAsync(x => x.Id == newExpense.CategoryId);

            if (String.IsNullOrEmpty(newExpense.PhotoUrl))
            {
                _photoService.AssignPicToExpense(newExpense);
            }

            _dbContext.Add(newExpense);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public IActionResult Create()
        {
            var viewModel = new ExpenseCreateViewModel();

            return(View(viewModel));
        }