public async Task <IActionResult> Create([Bind("Id,NameTask,StartDate,EndDate,StateTask")] Tasks tasks) { if (ModelState.IsValid) { tasks.Id = Guid.NewGuid(); _context.Add(tasks); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tasks)); }
public async Task <IActionResult> Create(WorkerDTO workerDTO) { if (ModelState.IsValid) { var getID = await(from task in _context.Tasks where task.NameTask == workerDTO.TaskName select task.Id).SingleOrDefaultAsync(); var worker = new Worker() { Id = Guid.NewGuid(), FIO = workerDTO.FIO, Position = workerDTO.Position, State = workerDTO.State, TaskId = getID, TaskName = workerDTO.TaskName }; _context.Add(worker); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(workerDTO)); }