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")); }
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")); }