public async Task <IActionResult> AssignmentSubmit(AssignmentSubmitModel submitModel) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Validation not passed"); return(View(submitModel)); } if (submitModel.AssignmentFile.ContentType != "application/zip" && submitModel.AssignmentFile.ContentType != "application/x-zip-compressed") { ModelState.AddModelError("", "Please upload zip file"); return(View(submitModel)); } var studentId = int.Parse(_userManager.GetUserId(User)); submitModel.StudentId = studentId; string assignmentFilePath = Path.Combine(_hostingEnvironment.WebRootPath, "Assignment_" + submitModel.AssignmentId); Directory.CreateDirectory(assignmentFilePath); string fileName = Path.Combine(assignmentFilePath, $"{studentId}.zip"); if (System.IO.File.Exists(fileName)) { ModelState.AddModelError("", "You have already submited your homework for this assignment"); return(View(submitModel)); } HelperFunctions.FileHelpers.SaveToPhysicalLocation(submitModel.AssignmentFile, fileName); submitModel.FilePath = fileName; submitModel.AssignmentFile = null; await _assignmentService.AddSubmitedAssignmen(submitModel); return(RedirectToAction("Index")); }