public ActionResult CreateDiscipline(DisciplineViewModel disciplineViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var disciplineDTO = new DisciplineDTO
                    {
                        Name = disciplineViewModel.Name
                    };

                    disciplineService.CreateDiscipline(disciplineDTO);

                    TempData["message"] = string.Format("Дисциплина была добавлена");

                    return(RedirectToAction("index"));
                }
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
            }

            return(View(disciplineViewModel));
        }
Пример #2
0
        public async Task <string> Create(MaterialInputModel model)
        {
            //TODO: Validate model
            var    userId  = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            string fileUrl = await this.cloudinaryService.UploadFileAsync(model.File, model.Name);

            Material material = new Material()
            {
                AuthorId         = userId,
                Description      = model.Description,
                ForTeachers      = model.ForTeachers,
                Name             = model.Name,
                FileLink         = fileUrl,
                MaterialComments = new HashSet <MaterialComment>()
            };

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

                material.Disciplines.Add(disc);
            }

            db.Materials.Add(material);
            await db.SaveChangesAsync();

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

            return(result);
        }
Пример #3
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);
        }