//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(Language language) { if (ModelState.IsValid) { _context.Add(language); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(language)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <string> AddWorkerAsync(Worker worker) { await dbContext.AddAsync(worker); await dbContext.SaveChangesAsync(); return(worker.Id); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(Worker worker) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { worker.Department = await _context.Departments.FindAsync(worker.Department.Id); worker.Language = await _context.Languages.FindAsync(worker.Language.Id); _context.Add(worker); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } AddTablesInViewBag(); return(View(worker)); }