// GET: Locations/Create
        public IActionResult Create(int?id)  // Passing in courseId
        {
            if (id == null)
            {
                return(NotFound());
            }

            LocationImageViewModel vm = new LocationImageViewModel()
            {
                CourseId = id.Value
            };

            return(View(vm));
        }
        public async Task <IActionResult> Create(LocationImageViewModel vm, int id)
        {
            if (ModelState.IsValid)
            {
                Location location = new Location()
                {
                    CourseId       = id,
                    Name           = vm.Name,
                    ImageGuid      = UploadImage(vm.LocationImage),
                    ImageExtension = Path.GetExtension(vm.LocationImage.FileName)
                };
                _locationContext.Add(location);
                await _locationContext.SaveChangesAsync();

                return(RedirectToAction("Details", "Courses", new { id = id }));
            }
            return(View(vm));
        }
 public async Task <IActionResult> Edit(LocationImageViewModel vm)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _locationContext.Update(vm);
             await _locationContext.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!LocationExists(vm.LocationId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Details", "Courses", new { id = vm.CourseId }));
     }
     return(View(vm));
 }
        // GET: Locations/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var location = await _locationContext.Location.FindAsync(id);

            if (location == null)
            {
                return(NotFound());
            }


            LocationImageViewModel vm = new LocationImageViewModel()
            {
                CourseId   = location.CourseId,
                LocationId = location.LocationId,
                Name       = location.Name
            };

            return(View(vm));
        }