// GET: LearningMaterials/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            LearningMaterialViewModel vm = new LearningMaterialViewModel();
            var learningMaterial         = await _context.LearningMaterial.FindAsync(id);

            if (learningMaterial == null)
            {
                return(NotFound());
            }
            vm.learningMaterial = learningMaterial;
            vm.instruments      = _context.Instrument.Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Name
            }).ToList();
            vm.instruments.Insert(0, new SelectListItem()
            {
                Value = "0",
                Text  = "Please choose an Instrument"
            });
            return(View(vm));
        }
        //edit function, not easily accessible for the user, it's for the programmer
        public async Task <IActionResult> Edit(int id, LearningMaterialViewModel vm)
        {
            if (id != vm.learningMaterial.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vm.learningMaterial);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LearningMaterialExists(vm.learningMaterial.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm.learningMaterial));
        }
        public async Task <IActionResult> Create(LearningMaterialViewModel vm)
        {
            if (ModelState.IsValid)
            {
                //adding the learning material from the view model to database
                _context.Add(vm.learningMaterial);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm.learningMaterial));
        }
        // GET: LearningMaterials/Create
        public IActionResult Create()
        {
            //instance of a view model
            LearningMaterialViewModel vm = new LearningMaterialViewModel();

            //Select List for instruments
            vm.instruments = _context.Instrument.Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Name
            }).ToList();
            vm.instruments.Insert(0, new SelectListItem()
            {
                Value = "0",
                Text  = "Please choose an Instrument"
            });

            return(View(vm));
        }