[HttpPost] // Authorize public async Task <IActionResult> Post(string resource, Guid referenceId, ICollection <IFormFile> file) { foreach (var f in file) { using (var memoryStream = new MemoryStream()) { await f.CopyToAsync(memoryStream); var create = new Domain.File { Resource = resource, ReferenceId = referenceId, Name = f.FileName, FileType = f.ContentType, ContentType = f.ContentType, Size = f.Length, Content = new Domain.FileContent(memoryStream.ToArray()) }; context.Add(create); await context.SaveChangesAsync(); } } return(Accepted()); }
public async Task <IActionResult> Create([Bind("UserID,UserName,UserEmail,UserPassword,UserRole")] AccountModel accountModel) { if (ModelState.IsValid) { _context.Add(accountModel); await _context.SaveChangesAsync(); ClaimsIdentity identity = null; bool isAuthenticate = false; identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, accountModel.UserName), new Claim(ClaimTypes.Role, accountModel.UserRole) }, CookieAuthenticationDefaults.AuthenticationScheme); isAuthenticate = true; if (isAuthenticate) { var principal = new ClaimsPrincipal(identity); var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(RedirectToAction("Index", "Home")); } return(View()); } return(View(accountModel)); }
public async Task <IActionResult> Create([Bind("TaskID,TaskName,TaskDescription,TaskDeadline,TaskCourse,TaskTeacher")] TaskModel taskModel) { if (ModelState.IsValid) { _context.Add(taskModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taskModel)); }
public async Task <IActionResult> Create([Bind("CourseID,CourseName,CourseDescription,CourseSchedule,CourseTeacher")] CourseModel courseModel) { if (ModelState.IsValid) { _context.Add(courseModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(courseModel)); }
public async Task <IActionResult> CreateContent([Bind("ContentID,CourseID,ContentName,ContentFile")] ContentModel contentModel) { if (ModelState.IsValid) { //Save to File string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(contentModel.ContentFile.FileName); string extension = Path.GetExtension(contentModel.ContentFile.FileName); contentModel.ContentDescription = fileName = fileName + extension; //contentModel.ContentDescription = DateTime.Now.ToString("dddd, dd MMMM yyyy"); string path = Path.Combine(wwwRootPath + "/File", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await contentModel.ContentFile.CopyToAsync(fileStream); } //Insert record _context.Add(contentModel); await _context.SaveChangesAsync(); return(RedirectToAction("ContentList", new { courseID = contentModel.CourseID })); } return(View(contentModel)); }
public async Task <IActionResult> CreateSubmit([Bind("SubmitID,TaskID,SubmitName,ContentFile,SubmitTime,SubmitScore")] SubmitModel submitModel) { if (ModelState.IsValid) { //Save to File string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(submitModel.ContentFile.FileName); string extension = Path.GetExtension(submitModel.ContentFile.FileName); //contentModel.ContentDescription = fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension; submitModel.SubmitDescription = fileName = fileName + extension; submitModel.SubmitTime = DateTime.Now.ToString("dd MMMM yyyy"); string path = Path.Combine(wwwRootPath + "/File", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await submitModel.ContentFile.CopyToAsync(fileStream); } //Insert record _context.Add(submitModel); await _context.SaveChangesAsync(); return(RedirectToAction("SubmitList", new { TaskID = submitModel.TaskID })); } return(View(submitModel)); }