public async Task <IActionResult> Edit(int id, Lecture lecture)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new LectureFormViewModel {
                    lecture = lecture
                };
                return(View(viewModel));
            }
            if (id != lecture.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id mismatch" }));
            }
            try
            {
                await _serviceLecture.UpdateAsync(lecture);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NotFoundException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
            catch (DbConcurrencyException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
        public async Task <IActionResult> Create()
        {
            var professors = await _professorService.FindAllAsync();

            var viewModel = new LectureFormViewModel {
                Professors = professors
            };

            return(View(viewModel));
        }
        [ValidateAntiForgeryToken] //To prevent cross-site request forgery
        public async Task <IActionResult> Create(Lecture lecture)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new LectureFormViewModel {
                    lecture = lecture
                };
                return(View(viewModel));
            }
            await _serviceLecture.InsertAsync(lecture);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id is null" }));
            }
            var obj = await _serviceLecture.FindByIdAsync(id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not found" }));
            }


            LectureFormViewModel view = new LectureFormViewModel {
                lecture = obj
            };

            return(View(view));
        }