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); }
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); }
public async Task AddDisciplineTo(Discipline dicipline, Material material) { material.Disciplines.Add(dicipline); await db.SaveChangesAsync(); }