Exemplo n.º 1
0
        public async Task <IActionResult> Create(VideoLessonInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model ?? new VideoLessonInputModel()));
            }


            await service.Create(model);

            return(this.Redirect("/VideoLesson/ViewAll"));
        }
Exemplo n.º 2
0
        public async Task <string> Create(VideoLessonInputModel model)
        {
            //TODO: Validate model
            VideoLesson video  = Mapper.Map <VideoLesson>(model);
            var         userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            video.AuthorId = userId;

            if (model.DisciplineName != null && model.Grade != null)
            {
                var disc = await disciplineService.CreateDiscipline(model.DisciplineName, model.Grade);

                video.Disciplines.Add(disc);
            }

            #region Old Manual Mapping
            //VideoLesson video = new VideoLesson()
            //{
            //    AuthorId = userId,
            //    Description = model.Description,
            //    Disciplines = model.Disciplines,
            //    ForTeachers = model.ForTeachers,
            //    Name = model.Name,
            //    Url = model.Url,
            //    Rating = 0,
            //    VideoLessonComments = new HashSet<VideoLessonComment>()

            //};
            #endregion

            db.VideoLessons.Add(video);
            await db.SaveChangesAsync();

            var result = $"You have successfully added the video {model.Name}!";
            return(result);
        }