/// <summary> /// --------------------------------------remain----------------------------------------------- /// </summary> public IEnumerable <TextMaterial> EditMaterial(TextMaterial EditMaterial) { var material = DB.TextMaterials.FromSqlRaw("EXEC dbo.usp_TextMaterials_Insert {0},{1},{2}" , EditMaterial.TextMaterialId , EditMaterial.TextMaterialName , EditMaterial.URL ); return(material); }
public TextMaterial AddMaterial(TextMaterial NewMaterial) { var material = DB.TextMaterials.FromSqlRaw("EXEC dbo.usp_TextMaterials_Insert {0},{1},{2}" , NewMaterial.TextMaterialName , NewMaterial.URL , NewMaterial.CourseId ).ToList().FirstOrDefault(); return(material); }
public async Task <TextMaterial> EditTextMaterial(Guid id, TextViewModel text) { TextMaterial textMaterial = await _text.GetTextMaterial(id); if (textMaterial != null) { textMaterial.Name = text.Name; textMaterial.Context = text.Context; await _text.UpdateTextMaterial(textMaterial); } return(textMaterial); }
public async Task <IActionResult> Edit(Guid id, TextViewModel text) { if (ModelState.IsValid) { TextMaterial new_text = await _textService.EditTextMaterial(id, text); if (new_text != null) { return(RedirectToAction("Details", "Modules", new { id = new_text.ModuleId })); } } return(View(text)); }
public async Task <IActionResult> Create(Guid id, TextViewModel text) { if (ModelState.IsValid) { TextMaterial textMaterial = await _textService.AddTextMaterial(id, text); if (textMaterial != null) { return(RedirectToAction("Details", "Modules", new { id = textMaterial.ModuleId })); } } return(View(text)); }
public async Task <TextMaterial> AddTextMaterial(Guid id, TextViewModel text) { Module module = await _moduleService.GetModule(id); TextMaterial text1 = new TextMaterial { Id = Guid.NewGuid(), Name = text.Name, Context = text.Context, Modified = DateTime.Now, ModuleId = module.Id, }; await _text.AddTextMaterial(text1); return(text1); }
// [Authorize] public async Task <IActionResult> AddMaterial(int CourseId) { var files = new List <IFormFile>(); for (int i = 0; i < Request.Form.Files?.Count(); i++) { files.Add(Request.Form.Files[i]); } var uploader = new Uploader(hostingEnvironment); var AllMaterial = new List <TextMaterial>(); var mat = new TextMaterial(); if (files.Count() == 0 || CourseId <= 0) { return(BadRequest()); } foreach (IFormFile source in files) { if (source.Length == 0) { continue; } //get uploaded file name as in the user pc string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.ToString().Trim('"'); filename = uploader.EnsureCorrectFilename(filename); var PathToBeSavedInDB = uploader.GetPathAndFilename(filename); using (FileStream output = System.IO.File.Create(PathToBeSavedInDB)) await source.CopyToAsync(output); mat.CourseId = CourseId; mat.TextMaterialName = filename; mat.URL = PathToBeSavedInDB; var cm = db.AddMaterial(mat); AllMaterial.Add(cm); } return(Ok(AllMaterial)); }
public async Task UpdateTextMaterial(TextMaterial text) { _appDbContext.TextMaterials.Update(text); await _appDbContext.SaveChangesAsync(); }
public async Task DeleteTextMaterial(TextMaterial text) { _appDbContext.TextMaterials.Remove(text); await _appDbContext.SaveChangesAsync(); }
public async Task AddTextMaterial(TextMaterial text) { await _appDbContext.TextMaterials.AddAsync(text); await _appDbContext.SaveChangesAsync(); }