public async Task <IActionResult> Create([Bind("Id,Title,Description,Archived")] Course course)
        {
            if (ModelState.IsValid)
            {
                ILAUser user = await _context.Users.FindAsync(GetUserId());

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

                course.Owner = user;

                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,Visible,Start,Stop,CourseId")]
                                                 Lecture lecture)
        {
            var course =
                await _context.Courses.FirstOrDefaultAsync(x => x.Id == lecture.CourseId && x.Owner.Id == GetUserId());

            if (course == null)
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                _context.Add(lecture);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(lecture));
        }