public JsonResult AddFinancial(int currencyId, int workHours, double grossSalary, double cafeteria, double bonus, int employeeId) { try { EmployeeFinancial newFinancial = new EmployeeFinancial { ActiveFrom = DateTime.Now, Bonus = bonus, Cafeteria = cafeteria, CreatedDate = DateTime.Now, CurrencyId = currencyId, EmployeeId = employeeId, GrossSalary = grossSalary, Id = _context.EmployeeFinancials.Max(e => e.Id) + 1, ModifiedDate = DateTime.Now, WorkHours = workHours }; _context.EmployeeFinancials.Add(newFinancial); _context.SaveChanges(); ViewData["Toast"] = Toasts.Created; } catch { ViewData["Toast"] = Toasts.CreatedFail; } return(Json(null)); }
public async Task <IActionResult> Create(Employee employee) { if (ModelState.IsValid) { employee.Id = _context.Employees.Max(e => e.Id) + 1; _context.Add(employee); await _context.SaveChangesAsync(); EmployeeFinancial employeeFinancial = new EmployeeFinancial { ActiveFrom = DateTime.Now, Bonus = 0, Cafeteria = 0, CreatedDate = DateTime.Now, CurrencyId = 1, EmployeeId = employee.Id, GrossSalary = 0, Id = _context.EmployeeFinancials.Max(e => e.Id) + 1, ModifiedDate = DateTime.Now, WorkHours = 0 }; _context.Add(employeeFinancial); await _context.SaveChangesAsync(); TempData["Toast"] = Toasts.Created; return(RedirectToAction(nameof(Index))); } return(View(employee)); }