public IActionResult assignStudentCompany(employmentViewModel model) { int studentId = int.Parse(model.selectedStudent); var studentcomp = _employRepo.GetAllEmploymentHistory().Where(sc => sc.CompID == model.compy_id && sc.ID == studentId).FirstOrDefault(); if (studentcomp == null) { EmploymentHistory employment = new EmploymentHistory() { CompID = model.compy_id, StudentId = studentId, StartDate = model.StartDate, //EndDate = model.EndDate }; _employRepo.AddEmploymentHistory(employment); return(RedirectToAction("index")); } else { ModelState.AddModelError("duplicate", "Error in key vale"); List <Student> studentlist = _student.GetAllStudent().ToList(); employmentViewModel employmentView = new employmentViewModel() { studentlist = studentlist }; return(View(employmentView)); } }