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 <IActionResult> Create(MaterialInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model ?? new MaterialInputModel())); } await service.Create(model); return(this.Redirect("/Material/ViewAll")); }