コード例 #1
0
ファイル: BankController.cs プロジェクト: DLJolien/BankApp
        public async Task <IActionResult> Create(BankCreateViewModel vm)
        {
            string  userId     = User.FindFirstValue(ClaimTypes.NameIdentifier);
            Expense newExpense = new Expense()
            {
                Amount           = vm.Amount,
                Description      = vm.Description,
                Date             = vm.Date,
                PhotoUrl         = vm.PhotoUrl,
                CategoryId       = vm.CategoryId,
                Persons_Expenses = vm.SelectedPersons.Select(person => new Person_Expense()
                {
                    PersonId = person
                }).ToList(),
                BankAppIdentityId = userId
            };

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

            if (String.IsNullOrEmpty(newExpense.PhotoUrl))
            {
                _photoService.AssignPicToExpense(newExpense);
            }
            _dbContext.Expenses.Add(newExpense);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #2
0
ファイル: BankController.cs プロジェクト: DLJolien/BankApp
        public async Task <IActionResult> Create()
        {
            BankCreateViewModel vm = new BankCreateViewModel();

            vm.Date = DateTime.Now;

            var categories = await _dbContext.Categories.ToListAsync();

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

            foreach (Category category in categories)
            {
                vm.Category.Add(new SelectListItem()
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }

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

            return(View(vm));
        }