public async Task <IActionResult> Create([Bind("Id,Year,Month,CreatedDate,CreatedBy,EmployeeInfoId,BonusTypeId")] BonusViewModel bonus) { if (ModelState.IsValid) { Bonus bb = new Bonus() { Year = bonus.Year, Month = bonus.Month, CreatedBy = bonus.CreatedBy, CreatedDate = bonus.CreatedDate, EmployeeInfoId = bonus.EmployeeInfoId, BonusTypeId = bonus.BonusTypeId }; await bonusRepository.Save(bb); //_context.Add(bonus); //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BonusTypeId"] = new SelectList(bonusTypeRepository.GetBonusTypeList(), "Id", "Id", bonus.BonusTypeId); ViewData["EmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", bonus.EmployeeInfoId); return(View(bonus)); }
public async Task <IActionResult> Create([Bind("Id,Year,Month,CreatedDate,CreatedBy,EmployeeInfoId,BonusTypeId")] BonusViewModel bonus) { if (ModelState.IsValid) { var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; Bonus bb = new Bonus() { Year = bonus.Year, Month = bonus.Month, CreatedBy = userId, CreatedDate = DateTime.Now, EmployeeInfoId = bonus.EmployeeInfoId, BonusTypeId = bonus.BonusTypeId }; await bonusRepository.Save(bb); //_context.Add(bonus); //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BonusTypeId"] = new SelectList(bonusTypeRepository.GetBonusTypeList(), "Id", "Id", bonus.BonusTypeId); ViewData["EmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", bonus.EmployeeInfoId); return(View(bonus)); }