public int AddExam(Exam model) { var allExams = examRepository.GetAll(); int lastId = 0; if (allExams.Count() > 0) { lastId = allExams[allExams.Count() - 1].Id; } model.Id = lastId + 1; examRepository.Insert(model); examRepository.Save(); return(model.Id); }